zeroshade commented on code in PR #1593:
URL: https://github.com/apache/arrow-adbc/pull/1593#discussion_r1516610391


##########
go/adbc/driver/snowflake/connection.go:
##########
@@ -557,13 +587,204 @@ func (c *cnxn) populateMetadata(ctx context.Context, 
depth adbc.ObjectDepth, cat
        return metadataRecords, nil
 }
 
+func (c *cnxn) populateConstraintSchema(ctx context.Context, depth 
adbc.ObjectDepth, metadataRecords []internal.Metadata) 
(map[internal.CatalogSchemaTable][]internal.ConstraintSchema, error) {
+       constraintLookup := 
make(map[internal.CatalogSchemaTable][]internal.ConstraintSchema)
+       tableConstraintsData, err := c.getConstraintsData(ctx, depth, 
metadataRecords)
+       if err != nil {
+               return nil, err
+       }
+
+       fullyQualifiedConstraintSchemaLookup := 
make(map[string]internal.ConstraintSchema)
+       for _, data := range tableConstraintsData {
+               var fullyQualifiedConstraintName string
+               if data.fk_constraintName.Valid {
+                       fullyQualifiedConstraintName = 
getFullyQualifiedConstraintName(data.fkDbName.String, data.fkSchema.String, 
data.fkTblName.String, data.fk_constraintName.String)
+                       if _, exists := 
fullyQualifiedConstraintSchemaLookup[fullyQualifiedConstraintName]; !exists {
+                               
fullyQualifiedConstraintSchemaLookup[fullyQualifiedConstraintName] = 
internal.ConstraintSchema{
+                                       ConstraintName:        
data.fk_constraintName.String,
+                                       ConstraintType:        
data.constraintType,
+                                       ConstraintColumnNames: 
[]string{data.fkColName.String},
+                                       ConstraintColumnUsages: 
[]internal.UsageSchema{
+                                               {
+                                                       ForeignKeyCatalog:  
data.dbName,
+                                                       ForeignKeyDbSchema: 
data.schema,
+                                                       ForeignKeyTable:    
data.tblName,
+                                                       ForeignKeyColName:  
data.colName,
+                                               },
+                                       },
+                               }
+                       } else {
+                               constraintInfo := 
fullyQualifiedConstraintSchemaLookup[fullyQualifiedConstraintName]
+                               constraintInfo.ConstraintColumnNames = 
append(constraintInfo.ConstraintColumnNames, data.fkColName.String)
+
+                               constraintInfo.ConstraintColumnUsages = 
append(constraintInfo.ConstraintColumnUsages, internal.UsageSchema{

Review Comment:
   since both cases use this `UsageSchema` you should be able to populate it 
before line 602 and then use the populated schema in both places rather than 
duplicating it



-- 
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]

Reply via email to