natusioe commented on code in PR #173: URL: https://github.com/apache/iceberg-go/pull/173#discussion_r1811534102
########## catalog/glue.go: ########## @@ -180,8 +267,155 @@ func (c *GlueCatalog) ListNamespaces(ctx context.Context, parent table.Identifie return icebergNamespaces, nil } +// CreateNamespace creates a new Iceberg namespace in the Glue catalog. +func (c *GlueCatalog) CreateNamespace(ctx context.Context, namespace table.Identifier, props iceberg.Properties) error { + database, err := identifierToGlueDatabase(namespace) + if err != nil { + return err + } + + databaseParameters := map[string]string{ + databaseTypePropsKey: glueTypeIceberg, + } + + description := props[descriptionPropsKey] + locationURI := props[locationPropsKey] + + if description != "" { + databaseParameters[descriptionPropsKey] = description + } + if locationURI != "" { + databaseParameters[locationPropsKey] = locationURI + } + + databaseInput := &types.DatabaseInput{ + Name: aws.String(database), + Parameters: databaseParameters, + } + + params := &glue.CreateDatabaseInput{DatabaseInput: databaseInput} + _, err = c.glueSvc.CreateDatabase(ctx, params) Review Comment: Added. ########## catalog/glue.go: ########## @@ -122,33 +149,93 @@ func (c *GlueCatalog) LoadTable(ctx context.Context, identifier table.Identifier return icebergTable, nil } -func (c *GlueCatalog) CatalogType() CatalogType { - return Glue -} - +// DropTable deletes an Iceberg table from the Glue catalog. func (c *GlueCatalog) DropTable(ctx context.Context, identifier table.Identifier) error { - return fmt.Errorf("%w: [Glue Catalog] drop table", iceberg.ErrNotImplemented) + database, tableName, err := identifierToGlueTable(identifier) + if err != nil { + return err + } + + // Check if the table exists and is an Iceberg table. + _, err = c.getTable(ctx, database, tableName) + if err != nil { + return err + } + + params := &glue.DeleteTableInput{ + DatabaseName: aws.String(database), + Name: aws.String(tableName), + } + _, err = c.glueSvc.DeleteTable(ctx, params) + if err != nil { + return fmt.Errorf("failed to drop table %s.%s: %w", database, tableName, err) + } + + return nil } +// RenameTable renames an Iceberg table in the Glue catalog. func (c *GlueCatalog) RenameTable(ctx context.Context, from, to table.Identifier) (*table.Table, error) { - return nil, fmt.Errorf("%w: [Glue Catalog] rename table", iceberg.ErrNotImplemented) -} + fromDatabase, fromTable, err := identifierToGlueTable(from) + if err != nil { + return nil, err + } -func (c *GlueCatalog) CreateNamespace(ctx context.Context, namespace table.Identifier, props iceberg.Properties) error { - return fmt.Errorf("%w: [Glue Catalog] create namespace", iceberg.ErrNotImplemented) -} + toDatabase, toTable, err := identifierToGlueTable(to) + if err != nil { + return nil, err + } -func (c *GlueCatalog) DropNamespace(ctx context.Context, namespace table.Identifier) error { - return fmt.Errorf("%w: [Glue Catalog] drop namespace", iceberg.ErrNotImplemented) -} + if fromDatabase != toDatabase { + return nil, fmt.Errorf("cannot rename table across namespaces: %s -> %s", fromDatabase, toDatabase) + } -func (c *GlueCatalog) LoadNamespaceProperties(ctx context.Context, namespace table.Identifier) (iceberg.Properties, error) { - return nil, fmt.Errorf("%w: [Glue Catalog] load namespace properties", iceberg.ErrNotImplemented) -} + // Fetch the existing Glue table to copy the metadata into the new table. + fromGlueTable, err := c.getTable(ctx, fromDatabase, fromTable) + if err != nil { + return nil, fmt.Errorf("failed to fetch the table %s.%s: %w", fromDatabase, fromTable, err) + } -func (c *GlueCatalog) UpdateNamespaceProperties(ctx context.Context, namespace table.Identifier, - removals []string, updates iceberg.Properties) (PropertiesUpdateSummary, error) { - return PropertiesUpdateSummary{}, fmt.Errorf("%w: [Glue Catalog] update namespace properties", iceberg.ErrNotImplemented) + // Create the new table. + _, err = c.glueSvc.CreateTable(ctx, &glue.CreateTableInput{ Review Comment: Yes, good catch, added. ########## catalog/glue.go: ########## @@ -30,22 +30,40 @@ import ( "github.com/aws/aws-sdk-go-v2/service/glue/types" ) -const glueTypeIceberg = "ICEBERG" +const ( + glueTypeIceberg = "ICEBERG" + databaseTypePropsKey = "database_type" + tableTypePropsKey = "table_type" + descriptionPropsKey = "Description" + + // Database location. + locationPropsKey = "Location" + + // Table metadata location pointer. + metadataLocationPropsKey = "metadata_location" Review Comment: Added the documentation to the pyiceberg. @nastra I will add `previous_metadata_location` in the next PR with the remaining ops (e.g. register_table) as it is used in them. ########## catalog/glue.go: ########## @@ -122,33 +149,93 @@ func (c *GlueCatalog) LoadTable(ctx context.Context, identifier table.Identifier return icebergTable, nil } -func (c *GlueCatalog) CatalogType() CatalogType { - return Glue -} - +// DropTable deletes an Iceberg table from the Glue catalog. func (c *GlueCatalog) DropTable(ctx context.Context, identifier table.Identifier) error { - return fmt.Errorf("%w: [Glue Catalog] drop table", iceberg.ErrNotImplemented) + database, tableName, err := identifierToGlueTable(identifier) + if err != nil { + return err + } + + // Check if the table exists and is an Iceberg table. + _, err = c.getTable(ctx, database, tableName) + if err != nil { + return err + } + + params := &glue.DeleteTableInput{ Review Comment: Added. Followed the Java pattern where we add catalog id in every request input. Event listener based approach from Python Iceberg might be ugly in Golang. -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org