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

SNOW-1618183: Dataset load with VARIANT in resultset lead to ConstraintException #1006

Open
MasterKuat opened this issue Aug 8, 2024 · 2 comments
Assignees
Labels
bug status-triage_done Initial triage done, will be further handled by the driver team

Comments

@MasterKuat
Copy link

  1. What version of .NET driver are you using?
    4.1.0

  2. What operating system and processor architecture are you using?
    Windows 10, x64

  3. What version of .NET framework are you using?
    .net framework 4.8

  4. What did you do?
    Mainly :

          var reader = cmd.ExecuteReader();
           var dt = new DataTable();
           dt.Load(reader);

cmd is a SnowflakeDbCommand with a simple query : SELECT MyVariantcolumn FROM T

dt.Load(reader) raise an exception : Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints

  1. What did you expect to see?

No exception

  1. Can you set logging to DEBUG and collect the logs?

This came from ColumnSize

For variant rowType.length is 0, should be -1 for unknown.
Replace L124 by :
row[SchemaTableColumn.ColumnSize] = rowType.length == 0 ? -1: (int)rowType.length;

@MasterKuat MasterKuat added the bug label Aug 8, 2024
@github-actions github-actions bot changed the title Dataset load with VARIANT in resultset lead to ConstraintException SNOW-1618183: Dataset load with VARIANT in resultset lead to ConstraintException Aug 8, 2024
@sfc-gh-dszmolka sfc-gh-dszmolka self-assigned this Aug 13, 2024
@sfc-gh-dszmolka sfc-gh-dszmolka added the status-triage Issue is under initial triage label Aug 13, 2024
@sfc-gh-dszmolka
Copy link
Contributor

hi - thanks for reporting this issue and all the details (and the suggested solution too!)
managed to reproduce it as you described; we'll take a look and fix it.

i also observed that using reader.Read(), something like:

...
                    cmd.CommandText = "SELECT variantcol from test_db.dotnet.gh1006;";
                    IDataReader reader = cmd.ExecuteReader();             
                        while (reader.Read())
                        {
                            Console.WriteLine(reader.GetString(0));
                        }
...

did not crash the application and could return the resultset; so perhaps could be used as a workaround until the issue is fixed, of course only if that makes sense in your case.

Anyways; thank you again and I'll keep this issue posted with the progress as there's any.

@sfc-gh-dszmolka sfc-gh-dszmolka added status-triage_done Initial triage done, will be further handled by the driver team and removed status-triage Issue is under initial triage labels Aug 13, 2024
@mrmoses
Copy link

mrmoses commented Oct 7, 2024

Same issue seems to be happening with ARRAY data types in the result.

One workaround is to specify the columns on the DataTable (generated from the results) before loading the data into it

IDataReader reader = cmd.ExecuteReader();

var table = new DataTable();

for (int i = 0; i < reader.FieldCount; i++)
{
    table.Columns.Add(reader.GetName(i), reader.GetFieldType(i));
}

table.Load(reader);

This loaded the ARRAY columns as (serialized) strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug status-triage_done Initial triage done, will be further handled by the driver team
Projects
None yet
Development

No branches or pull requests

4 participants