zeroshade commented on code in PR #1991:
URL: https://github.com/apache/iceberg-go/pull/1991#discussion_r3960400202
##########
table/arrow_utils_internal_test.go:
##########
@@ -428,34 +426,157 @@ var tableSchemaNested =
iceberg.NewSchemaWithIdentifiers(1,
)
func TestStatsTypes(t *testing.T) {
- statsCols, err := iceberg.PreOrderVisit(tableSchemaNested,
- &arrowStatsCollector{schema: tableSchemaNested, defaultMode:
"full"})
-
+ plan, err := computeStatsPlan(tableSchemaNested, iceberg.Properties{
+ DefaultWriteMetricsModeKey: string(internal.MetricModeFull),
+ })
require.NoError(t, err)
- // field ids should be sorted
- assert.True(t, slices.IsSortedFunc(statsCols, func(a, b
internal.StatisticsCollector) int {
- return cmp.Compare(a.FieldID, b.FieldID)
- }))
+ full := internal.MetricsMode{Typ: internal.MetricModeFull}
+ counts := internal.MetricsMode{Typ: internal.MetricModeCounts}
+ assert.Equal(t, map[int]internal.StatisticsCollector{
+ 1: {FieldID: 1, IcebergTyp: iceberg.PrimitiveTypes.String,
ColName: "foo", Mode: full},
+ 2: {FieldID: 2, IcebergTyp: iceberg.PrimitiveTypes.Int32,
ColName: "bar", Mode: full},
+ 3: {FieldID: 3, IcebergTyp: iceberg.PrimitiveTypes.Bool,
ColName: "baz", Mode: full},
+ 5: {FieldID: 5, IcebergTyp: iceberg.PrimitiveTypes.String,
ColName: "qux.element", Mode: counts},
+ 7: {FieldID: 7, IcebergTyp: iceberg.PrimitiveTypes.String,
ColName: "quux.key", Mode: counts},
+ 9: {FieldID: 9, IcebergTyp: iceberg.PrimitiveTypes.String,
ColName: "quux.value.key", Mode: counts},
+ 10: {FieldID: 10, IcebergTyp: iceberg.PrimitiveTypes.Int32,
ColName: "quux.value.value", Mode: counts},
+ 13: {FieldID: 13, IcebergTyp: iceberg.PrimitiveTypes.Float32,
ColName: "location.element.latitude", Mode: counts},
+ 14: {FieldID: 14, IcebergTyp: iceberg.PrimitiveTypes.Float32,
ColName: "location.element.longitude", Mode: counts},
+ 16: {FieldID: 16, IcebergTyp: iceberg.PrimitiveTypes.String,
ColName: "person.name", Mode: counts},
+ 17: {FieldID: 17, IcebergTyp: iceberg.PrimitiveTypes.Int32,
ColName: "person.age", Mode: counts},
+ }, plan)
+}
+
+func TestComputeStatsPlanMetricsModes(t *testing.T) {
+ schema := iceberg.NewSchema(0,
+ iceberg.NestedField{ID: 1, Name: "text", Type:
iceberg.PrimitiveTypes.String},
+ iceberg.NestedField{ID: 2, Name: "binary", Type:
iceberg.PrimitiveTypes.Binary},
+ iceberg.NestedField{ID: 3, Name: "number", Type:
iceberg.PrimitiveTypes.Int32},
+ iceberg.NestedField{ID: 4, Name: "variant", Type:
iceberg.VariantType{}},
+ iceberg.NestedField{ID: 5, Name: "dotted.name", Type:
iceberg.PrimitiveTypes.String},
+ iceberg.NestedField{ID: 6, Name: "nested", Type:
&iceberg.StructType{FieldList: []iceberg.NestedField{
+ {ID: 7, Name: "text", Type:
iceberg.PrimitiveTypes.String},
+ {ID: 8, Name: "variant", Type: iceberg.VariantType{}},
+ }}},
+ )
+ full := internal.MetricsMode{Typ: internal.MetricModeFull}
+ counts := internal.MetricsMode{Typ: internal.MetricModeCounts}
+ none := internal.MetricsMode{Typ: internal.MetricModeNone}
+ truncate := internal.MetricsMode{Typ: internal.MetricModeTruncate, Len:
16}
+ truncateTwo := internal.MetricsMode{Typ: internal.MetricModeTruncate,
Len: 2}
+
+ for _, tt := range []struct {
+ name string
+ props iceberg.Properties
+ expected map[int]internal.MetricsMode
+ }{
+ {
+ name: "default",
+ expected: map[int]internal.MetricsMode{1: truncate, 2:
truncate, 3: full, 4: truncate, 5: counts, 7: counts, 8: truncate},
+ },
+ {
+ name: "full",
+ props:
iceberg.Properties{DefaultWriteMetricsModeKey: "full"},
+ expected: map[int]internal.MetricsMode{1: full, 2:
full, 3: full, 4: full, 5: counts, 7: counts, 8: full},
+ },
+ {
+ name: "counts",
+ props:
iceberg.Properties{DefaultWriteMetricsModeKey: "counts"},
+ expected: map[int]internal.MetricsMode{1: counts, 2:
counts, 3: counts, 4: counts, 5: counts, 7: counts, 8: counts},
+ },
+ {
+ name: "none",
+ props:
iceberg.Properties{DefaultWriteMetricsModeKey: "none"},
+ expected: map[int]internal.MetricsMode{1: none, 2:
none, 3: none, 4: none, 5: none, 7: none, 8: none},
+ },
+ {
+ name: "custom truncation",
+ props:
iceberg.Properties{DefaultWriteMetricsModeKey: " TRUNCATE(2) "},
+ expected: map[int]internal.MetricsMode{1: truncateTwo,
2: truncateTwo, 3: full, 4: truncateTwo, 5: counts, 7: counts, 8: truncateTwo},
+ },
+ {
+ name: "column overrides",
+ props: iceberg.Properties{
+ DefaultWriteMetricsModeKey:
"none",
+ MetricsModeColumnConfPrefix + ".text":
"truncate(2)",
+ MetricsModeColumnConfPrefix + ".binary":
"full",
+ MetricsModeColumnConfPrefix + ".number":
"truncate(2)",
+ MetricsModeColumnConfPrefix + ".variant":
"counts",
+ MetricsModeColumnConfPrefix + ".dotted.name":
"full",
+ MetricsModeColumnConfPrefix + ".nested.text":
"full",
+ MetricsModeColumnConfPrefix +
".nested.variant": "truncate(2)",
+ MetricsModeColumnConfPrefix + ".not_present":
"truncate(0)",
+ "unrelated.property":
"truncate(0)",
+ },
+ expected: map[int]internal.MetricsMode{1: truncateTwo,
2: full, 3: full, 4: counts, 5: counts, 7: counts, 8: truncateTwo},
+ },
+ {
+ name: "nested none overrides",
+ props: iceberg.Properties{
+ DefaultWriteMetricsModeKey:
"full",
+ MetricsModeColumnConfPrefix + ".nested.text":
"none",
+ MetricsModeColumnConfPrefix +
".nested.variant": "none",
+ },
+ expected: map[int]internal.MetricsMode{1: full, 2:
full, 3: full, 4: full, 5: counts, 7: none, 8: none},
+ },
+ } {
+ t.Run(tt.name, func(t *testing.T) {
+ plan, err := computeStatsPlan(schema, tt.props)
+ require.NoError(t, err)
+ require.Len(t, plan, len(tt.expected))
+ for fieldID, expected := range tt.expected {
+ require.Contains(t, plan, fieldID)
+ assert.Equal(t, expected, plan[fieldID].Mode,
"field %d", fieldID)
+ }
+ assert.Nil(t, plan[4].IcebergTyp)
+ assert.Nil(t, plan[8].IcebergTyp)
+ assert.Equal(t, "variant", plan[4].ColName)
+ assert.Equal(t, "nested.variant", plan[8].ColName)
+ })
+ }
+}
- actual := make([]iceberg.Type, len(statsCols))
- for i, col := range statsCols {
- actual[i] = col.IcebergTyp
+func TestComputeStatsPlanInvalidModes(t *testing.T) {
+ schema := iceberg.NewSchema(0,
Review Comment:
**nit** — Loop-invariant variant assertions repeated in all seven subtests
assert.Nil(plan[4].IcebergTyp), assert.Nil(plan[8].IcebergTyp),
assert.Equal("variant", plan[4].ColName) and assert.Equal("nested.variant",
plan[8].ColName) do not depend on tt and are re-asserted identically in each of
the 7 table cases. They belong once outside the table loop.
##########
table/arrow_utils_bench_test.go:
##########
@@ -0,0 +1,77 @@
+// 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 table
+
+import (
+ "fmt"
+ "testing"
+
+ "github.com/apache/iceberg-go"
+)
+
+func BenchmarkComputeStatsPlan(b *testing.B) {
+ for _, fieldCount := range []int{100, 1000, 10000} {
+ for _, benchmarkCase := range []struct {
Review Comment:
**nit** — Benchmark covers only flat schemas, missing the case where the
pre-sizing traversal pays off
benchmarkMetricsSchema builds a purely flat schema, so
statsPlanFieldCount(field) returns 1 per field and resultCount == len(fields)
exactly -- the extra recursive traversal is pure overhead in every shipped
benchmark case. It is nonetheless a real optimization for nested schemas, which
nothing benchmarks. Adding a nested case would document where the win actually
lives.
##########
table/arrow_utils_internal_test.go:
##########
@@ -428,34 +426,157 @@ var tableSchemaNested =
iceberg.NewSchemaWithIdentifiers(1,
)
func TestStatsTypes(t *testing.T) {
- statsCols, err := iceberg.PreOrderVisit(tableSchemaNested,
Review Comment:
**nit** — TestStatsTypes name is stale after the rewrite
The test no longer checks only Iceberg types -- it now asserts the entire
plan including FieldID, ColName and Mode for all 11 fields. A name like
TestComputeStatsPlanNestedSchema would describe what it actually pins.
--
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]