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

feat(go/adbc/driver/snowflake): Add support for table constraints when calling GetObjects #1455

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

vleslief-ms
Copy link
Contributor

When Snowflake Go driver calls GetObjects against tables and columns, it will now also return table constraints (name and type) if any are found related to the table.

The tables and columns SQL queries were modified to include a left outer join against INFORMATION_SCHEMA.TABLE_CONSTRAINTS to retrieve constraint information. The metadata object also had to be updated to include the constraint fields.

Pre-commit had to be updated as I could not commit until it was done, and the previous versions of the pre-commit dependencies kept returning errors when I tried to execute them.

@github-actions github-actions bot added this to the ADBC Libraries 0.10.0 milestone Jan 11, 2024
Copy link
Contributor

@ryan-syed ryan-syed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work on your first jab at the Go Driver. The table constraints implementation appears to be partial as compared to the spec. To ensure that the table constraints data is being stored and returned correctly it might be beneficial to include integration test for this functionality.

@@ -701,10 +701,16 @@ func prepareTablesSQL(matchingCatalogNames []string, catalog *string, dbSchema *
if query != "" {
query += " UNION ALL "
}
query += `SELECT * FROM "` + strings.ReplaceAll(catalog_name, "\"", "\"\"") + `".INFORMATION_SCHEMA.TABLES`
query += `SELECT T.*, K.constraint_name, K.constraint_type FROM "` + strings.ReplaceAll(catalog_name, "\"", "\"\"") + `".INFORMATION_SCHEMA.TABLES AS T
Copy link
Contributor

@ryan-syed ryan-syed Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -640,7 +639,8 @@ func (c *cnxn) getColumnsMetadata(ctx context.Context, matchingCatalogNames []st
err = rows.Scan(&data.TblType, &data.Dbname, &data.Schema, &data.TblName, &data.ColName,
&data.OrdinalPos, &data.IsNullable, &data.DataType, &data.NumericPrec,
&data.NumericPrecRadix, &data.NumericScale, &data.IsIdent, &data.IdentGen,
&data.IdentIncrement, &data.CharMaxLength, &data.CharOctetLength, &data.DatetimePrec, &data.Comment)
&data.IdentIncrement, &data.CharMaxLength, &data.CharOctetLength, &data.DatetimePrec, &data.Comment,
&data.ConstraintName, &data.ConstraintType)
Copy link
Contributor

@ryan-syed ryan-syed Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TableInfo struct doesn't currently capture table constraints.

I couldn't locate them being appended to tableConstraintsBuilder which seems to be marked as unimplemented.

AND T.table_schema = K.table_schema
AND T.table_name = K.table_name UNION ALL SELECT T.table_type,
C.*,
K.constraint_name, K.constraint_type
Copy link
Contributor

@ryan-syed ryan-syed Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a test similar to TestMetadataGetObjectsColumnsXdbc will be helpful to verify the table constraints are returned correctly. Adding tests in the CSharp layer would also work.

@vleslief-ms vleslief-ms force-pushed the snowflakeTableConstraints branch from 6fca3fa to 2afbbb7 Compare February 2, 2024 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants