jduo commented on code in PR #1352:
URL: https://github.com/apache/arrow-adbc/pull/1352#discussion_r1440703563
##########
go/adbc/driver/snowflake/connection.go:
##########
@@ -238,84 +239,59 @@ func (c *cnxn) GetInfo(ctx context.Context, infoCodes
[]adbc.InfoCode) (array.Re
// All non-empty, non-nil strings should be a search pattern (as described
// earlier).
func (c *cnxn) GetObjects(ctx context.Context, depth adbc.ObjectDepth, catalog
*string, dbSchema *string, tableName *string, columnName *string, tableType
[]string) (array.RecordReader, error) {
- g := internal.GetObjects{Ctx: ctx, Depth: depth, Catalog: catalog,
DbSchema: dbSchema, TableName: tableName, ColumnName: columnName, TableType:
tableType}
- if err := g.Init(c.db.Alloc, c.getObjectsDbSchemas,
c.getObjectsTables); err != nil {
+ metadataRecords, err := c.populateMetadata(ctx, depth, catalog,
dbSchema, tableName, columnName, tableType)
+ if err != nil {
return nil, err
}
- defer g.Release()
- rows, err := c.sqldb.QueryContext(ctx, "SHOW TERSE DATABASES", nil)
- if err != nil {
+ g := internal.GetObjects{Ctx: ctx, Depth: depth, Catalog: catalog,
DbSchema: dbSchema, TableName: tableName, ColumnName: columnName, TableType:
tableType}
+ g.MetadataRecords = metadataRecords
+ if err := g.Init(c.db.Alloc, c.getObjectsDbSchemas,
c.getObjectsTables); err != nil {
return nil, err
}
- defer rows.Close()
-
- var (
- created time.Time
- name string
- kind, dbname, schema sql.NullString
- )
- for rows.Next() {
- if err := rows.Scan(&created, &name, &kind, &dbname, &schema);
err != nil {
- return nil, errToAdbcErr(adbc.StatusInvalidData, err)
- }
+ defer g.Release()
- // SNOWFLAKE catalog contains functions and no tables
- if name == "SNOWFLAKE" {
+ uniqueCatalogs := make(map[string]bool)
+ for _, data := range metadataRecords {
+ if !data.Dbname.Valid {
continue
}
- // schema for SHOW TERSE DATABASES is:
- // created_on:timestamp, name:text, kind:null,
database_name:null, schema_name:null
- // the last three columns are always null because they are not
applicable for databases
- // so we want values[1].(string) for the name
- g.AppendCatalog(name)
+ if _, exists := uniqueCatalogs[data.Dbname.String]; !exists {
+ uniqueCatalogs[data.Dbname.String] = true
+ g.AppendCatalog(data.Dbname.String)
+ }
}
return g.Finish()
}
-func (c *cnxn) getObjectsDbSchemas(ctx context.Context, depth
adbc.ObjectDepth, catalog *string, dbSchema *string) (result
map[string][]string, err error) {
+func (c *cnxn) getObjectsDbSchemas(ctx context.Context, depth
adbc.ObjectDepth, catalog *string, dbSchema *string, metadataRecords
[]internal.Metadata) (result map[string][]string, err error) {
if depth == adbc.ObjectDepthCatalogs {
return
}
- conditions := make([]string, 0)
- if catalog != nil && *catalog != "" {
- conditions = append(conditions, ` CATALOG_NAME ILIKE
'`+*catalog+`'`)
- }
- if dbSchema != nil && *dbSchema != "" {
- conditions = append(conditions, ` SCHEMA_NAME ILIKE
'`+*dbSchema+`'`)
- }
-
- cond := strings.Join(conditions, " AND ")
-
result = make(map[string][]string)
+ uniqueCatalogSchema := make(map[string]map[string]bool)
Review Comment:
It is hard to tell what these maps are being used for. Some comments would
be helpful.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]