kevinjqliu commented on code in PR #245:
URL: https://github.com/apache/iceberg-go/pull/245#discussion_r1908136750
##########
catalog/catalog.go:
##########
@@ -195,3 +200,36 @@ func TableNameFromIdent(ident table.Identifier) string {
func NamespaceFromIdent(ident table.Identifier) table.Identifier {
return ident[:len(ident)-1]
}
+
+type createTableOpt func(*createTableCfg)
+
+type createTableCfg struct {
+ location string
+ partitionSpec *iceberg.PartitionSpec
+ sortOrder table.SortOrder
+ properties iceberg.Properties
+}
+
+func WithLocation(location string) createTableOpt {
+ return func(cfg *createTableCfg) {
+ cfg.location = strings.TrimRight(location, "/")
+ }
+}
+
+func WithPartitionSpec(spec *iceberg.PartitionSpec) createTableOpt {
+ return func(cfg *createTableCfg) {
+ cfg.partitionSpec = spec
+ }
+}
+
+func WithSortOrder(order table.SortOrder) createTableOpt {
Review Comment:
I noticed in `catalog/rest.go`'s removed code, the SortOrder is passed as a
pointer
```
func WithWriteOrder(order *table.SortOrder) createTableOption {
return func(req *createTableRequest) {
req.WriteOrder = order
}
}
```
##########
catalog/catalog.go:
##########
@@ -152,6 +153,10 @@ type Catalog interface {
// CatalogType returns the type of the catalog.
CatalogType() CatalogType
+ // CreateTable creates a new iceberg table in the catalog using the
provided identiifer
Review Comment:
```suggestion
// CreateTable creates a new iceberg table in the catalog using the
provided identifier
```
##########
catalog/rest.go:
##########
@@ -663,18 +631,40 @@ func splitIdentForPath(ident table.Identifier) (string,
string, error) {
return strings.Join(NamespaceFromIdent(ident), namespaceSeparator),
TableNameFromIdent(ident), nil
}
-func (r *RestCatalog) CreateTable(ctx context.Context, identifier
table.Identifier, schema *iceberg.Schema, opts ...createTableOption)
(*table.Table, error) {
+func (r *RestCatalog) CreateTable(ctx context.Context, identifier
table.Identifier, schema *iceberg.Schema, opts ...createTableOpt)
(*table.Table, error) {
ns, tbl, err := splitIdentForPath(identifier)
if err != nil {
return nil, err
}
- payload := createTableRequest{
- Name: tbl,
- Schema: schema,
- }
+ var cfg createTableCfg
for _, o := range opts {
- o(&payload)
+ o(&cfg)
+ }
+
+ freshSchema, err := iceberg.AssignFreshSchemaIDs(schema, nil)
+ if err != nil {
+ return nil, err
+ }
+
+ freshPartitionSpec, err :=
iceberg.AssignFreshPartitionSpecIDs(cfg.partitionSpec, schema, freshSchema)
+ if err != nil {
+ return nil, err
+ }
+
+ freshSortOrder, err := table.AssignFreshSortOrderIDs(cfg.sortOrder,
schema, freshSchema)
+ if err != nil {
+ return nil, err
+ }
+
+ payload := createTableRequest{
+ Name: tbl,
+ Schema: freshSchema,
+ Location: cfg.location,
+ PartitionSpec: &freshPartitionSpec,
+ WriteOrder: &freshSortOrder,
+ StageCreate: false,
Review Comment:
nit: should we add this as an option?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]