kevinjqliu commented on code in PR #475: URL: https://github.com/apache/iceberg-go/pull/475#discussion_r2220048076
########## cmd/iceberg/utils.go: ########## @@ -0,0 +1,128 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package main + +import ( + "fmt" + "strings" + + "github.com/apache/iceberg-go" + "github.com/apache/iceberg-go/table" +) + +func parseProperties(propStr string) (iceberg.Properties, error) { + if propStr == "" { + return iceberg.Properties{}, nil + } + props := make(iceberg.Properties) + pairs := strings.Split(propStr, ",") + + for _, pair := range pairs { + parts := strings.SplitN(strings.TrimSpace(pair), "=", 2) + if len(parts) != 2 { + return nil, fmt.Errorf("invalid property pair: %s (expected key=value)", pair) + } + key := strings.TrimSpace(parts[0]) + value := strings.TrimSpace(parts[1]) + if key == "" { + return nil, fmt.Errorf("property key cannot be empty in: %s", pair) + } + props[key] = value + } + + return props, nil +} + +func parsePartitionSpec(specStr string) (*iceberg.PartitionSpec, error) { + if specStr == "" { + return iceberg.UnpartitionedSpec, nil + } + + fields := strings.Split(specStr, ",") + var partitionFields []iceberg.PartitionField + + for i, field := range fields { + field = strings.TrimSpace(field) + if field == "" { + continue + } + + partitionFields = append(partitionFields, iceberg.PartitionField{ + SourceID: i + 1, + FieldID: i + 100, Review Comment: i think partition starts at 1000 https://github.com/apache/iceberg-go/blob/27dc0f3f6781d57cc92a40e2ad9cfd698a86a91b/partitions.go#L31 lets reuse existing vars if possible for both source id and field id ########## cmd/iceberg/utils.go: ########## @@ -0,0 +1,128 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package main + +import ( + "fmt" + "strings" + + "github.com/apache/iceberg-go" + "github.com/apache/iceberg-go/table" +) + +func parseProperties(propStr string) (iceberg.Properties, error) { + if propStr == "" { + return iceberg.Properties{}, nil + } + props := make(iceberg.Properties) + pairs := strings.Split(propStr, ",") + + for _, pair := range pairs { + parts := strings.SplitN(strings.TrimSpace(pair), "=", 2) + if len(parts) != 2 { + return nil, fmt.Errorf("invalid property pair: %s (expected key=value)", pair) + } + key := strings.TrimSpace(parts[0]) + value := strings.TrimSpace(parts[1]) + if key == "" { + return nil, fmt.Errorf("property key cannot be empty in: %s", pair) + } + props[key] = value + } + + return props, nil +} + +func parsePartitionSpec(specStr string) (*iceberg.PartitionSpec, error) { + if specStr == "" { + return iceberg.UnpartitionedSpec, nil + } + + fields := strings.Split(specStr, ",") + var partitionFields []iceberg.PartitionField + + for i, field := range fields { + field = strings.TrimSpace(field) + if field == "" { + continue + } + + partitionFields = append(partitionFields, iceberg.PartitionField{ + SourceID: i + 1, + FieldID: i + 100, + Name: field, + Transform: iceberg.IdentityTransform{}, Review Comment: maybe document that only identity transform is currently supported ########## cmd/iceberg/utils.go: ########## @@ -0,0 +1,128 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package main + +import ( + "fmt" + "strings" + + "github.com/apache/iceberg-go" + "github.com/apache/iceberg-go/table" +) + +func parseProperties(propStr string) (iceberg.Properties, error) { + if propStr == "" { + return iceberg.Properties{}, nil + } + props := make(iceberg.Properties) + pairs := strings.Split(propStr, ",") + + for _, pair := range pairs { + parts := strings.SplitN(strings.TrimSpace(pair), "=", 2) + if len(parts) != 2 { + return nil, fmt.Errorf("invalid property pair: %s (expected key=value)", pair) + } + key := strings.TrimSpace(parts[0]) + value := strings.TrimSpace(parts[1]) + if key == "" { + return nil, fmt.Errorf("property key cannot be empty in: %s", pair) + } + props[key] = value + } + + return props, nil +} + +func parsePartitionSpec(specStr string) (*iceberg.PartitionSpec, error) { + if specStr == "" { + return iceberg.UnpartitionedSpec, nil + } + + fields := strings.Split(specStr, ",") + var partitionFields []iceberg.PartitionField + + for i, field := range fields { + field = strings.TrimSpace(field) + if field == "" { + continue + } + + partitionFields = append(partitionFields, iceberg.PartitionField{ + SourceID: i + 1, + FieldID: i + 100, + Name: field, + Transform: iceberg.IdentityTransform{}, + }) + } + if len(partitionFields) == 0 { + return iceberg.UnpartitionedSpec, nil + } + spec := iceberg.NewPartitionSpec(partitionFields...) + + return &spec, nil +} + +func parseSortOrder(sortStr string) (table.SortOrder, error) { + if sortStr == "" { + return table.UnsortedSortOrder, nil + } + + fields := strings.Split(sortStr, ",") + var sortFields []table.SortField + + for i, field := range fields { + field = strings.TrimSpace(field) + if field == "" { + continue + } + parts := strings.SplitN(field, ":", 2) + direction := "asc" // default value + + if len(parts) > 1 { + direction = strings.TrimSpace(parts[1]) + } + + var nullOrder table.NullOrder + var sortDirection table.SortDirection + + switch strings.ToLower(direction) { + case "asc": + sortDirection = table.SortASC + nullOrder = table.NullsFirst + case "desc": + sortDirection = table.SortDESC + nullOrder = table.NullsLast + default: Review Comment: is it true that nullOrder is determined by direction? or should we also make null order configurable -- 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