Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter binding issue with complex objects #5

Closed
vostruk opened this issue Feb 18, 2021 · 3 comments
Closed

Parameter binding issue with complex objects #5

vostruk opened this issue Feb 18, 2021 · 3 comments
Labels
question Further information is requested

Comments

@vostruk
Copy link

vostruk commented Feb 18, 2021

When using complex objects (like List) in sqlParams the error is thrown.

Query execution failed. Message: SQL execution internal error:
Processing aborted due to error 300002:2150974492; incident 8924023.

For example performing an insert with something like:

await snowflakeClient.ExecuteAsync("INSERT INTO EMPLOYEES (EmploymentsList) VALUES (:EmploymentsList);", new { EmploymentsList = new List<string> {"Programmer"} });

Causes an error in SnowflakeClient.cs like 137 (BuildQueryRequest method)

Similar goes when we pass Class with complex fields without even using them in query.

I understand where this may come from, since filtering on such objects may not be needed. But inserts of complex objects is quite common thing, at least in my case.

Would be great if we can solve this problem.

@fixer-m
Copy link
Owner

fixer-m commented Feb 18, 2021

@vostruk, Hi!

As I understand, you want to pass list of values to insert it into one array/object/variant column, right?

I haven't found a way to do this via official Snowflake.Data connector. I tried to modify it's source code in a different ways, but with no luck. I think Snowflake API doesn't support this. Each passed parameter should have some value and specified type. Value can be any object, but what to specify as value type in case of array/list?

If you try to specify array, object or variant as parameter type it will return:

SQL compilation error: Unsupported data type 'ARRAY'.

If you try to specify element type instead, i.e. text in case of list of strings, it will return:

Processing aborted due to error 300002:1802044846; incident 3723616.

The only workaround I have found is to pass list as json string and use PARSE_JSON function:

var query = "INSERT INTO EMPLOYEES (EmployeesListColumn) SELECT PARSE_JSON(:EmployeesList);";
var result = await _snowflakeClient.ExecuteAsync(query, new { EmployeesList = "[\"Alexander\", \"Max\"]" });

Let me know if you know other options or have more questions.

@vostruk
Copy link
Author

vostruk commented Feb 18, 2021

Good point. Parse_json workaround is a bit clumsy but it works.
I'm implementing bulk insert extension on my side that will use blob storage as intermediate to insert big amounts of data using COPY into statement. With that solution any type of data could be handled and inserted.

However using blobs currently require external storage connection (Azure, AWS or GCS) since file PUT doesn't work with .NET yet :(
With PUT working this will be much easier.

Let's then close this issue for now.

@fixer-m
Copy link
Owner

fixer-m commented Feb 18, 2021

@vostruk, got it.

GET/PUT files feature is already on my roadmap :)

@fixer-m fixer-m closed this as completed Feb 18, 2021
@fixer-m fixer-m added the question Further information is requested label Jan 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants