szehon-ho commented on a change in pull request #2240:
URL: https://github.com/apache/iceberg/pull/2240#discussion_r691713275
##########
File path: core/src/test/java/org/apache/iceberg/TestMetrics.java
##########
@@ -597,6 +609,101 @@ public void testTruncateBinaryMetricsMode() throws
IOException {
assertBounds(1, Types.BinaryType.get(), expectedMinBounds,
expectedMaxBounds, metrics);
}
+ @Test
+ public void testSortedColumnMetrics() throws IOException {
+ File tableDir = temp.newFolder();
+ tableDir.delete(); // created by table create
+
+ SortOrder sortOrder = SortOrder.builderFor(SIMPLE_SCHEMA)
+ .asc("booleanCol")
+ .asc("intCol")
+ .asc("longCol")
+ .asc("decimalCol")
+ .asc("stringCol")
+ .asc("dateCol").build();
+
+ Table table =
+ TestTables.create(tableDir, "test", SIMPLE_SCHEMA,
PartitionSpec.unpartitioned(), sortOrder, FORMAT_V2);
Review comment:
Added a spec which is PartitionSpec.unpartitioned(), if that is what you
meant
##########
File path: core/src/test/java/org/apache/iceberg/TestMetricsModes.java
##########
@@ -19,22 +19,39 @@
package org.apache.iceberg;
+import java.io.File;
import java.util.Map;
import org.apache.iceberg.MetricsModes.Counts;
import org.apache.iceberg.MetricsModes.Full;
import org.apache.iceberg.MetricsModes.None;
import org.apache.iceberg.MetricsModes.Truncate;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.types.Types;
+import org.junit.After;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
+
+import static org.apache.iceberg.types.Types.NestedField.required;
public class TestMetricsModes {
@Rule
public ExpectedException exceptionRule = ExpectedException.none();
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
+ private static final int FORMAT_V2 = 2;
+
+ @After
+ public void after() {
+ TestTables.clearTables();
+ }
+
+
Review comment:
Fixed
##########
File path: data/src/test/java/org/apache/iceberg/io/TestWriterMetrics.java
##########
@@ -0,0 +1,150 @@
+/*
+ * 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 org.apache.iceberg.io;
+
+import java.io.File;
+import java.nio.ByteBuffer;
+import java.util.Map;
+import org.apache.iceberg.FileFormat;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.SortOrder;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.TestTables;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.types.Conversions;
+import org.apache.iceberg.types.Types;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+
+import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.apache.iceberg.types.Types.NestedField.required;
+
+@RunWith(Parameterized.class)
+public abstract class TestWriterMetrics<T> {
+
+ private static final int FORMAT_V2 = 2;
+
+ protected static final Types.NestedField ID_FIELD = required(1, "id",
Types.IntegerType.get());
+ protected static final Types.NestedField DATA_FIELD = optional(2, "data",
Types.StringType.get());
+
+ protected static final Types.StructType NESTED_FIELDS = Types.StructType.of(
+ required(4, "booleanField", Types.BooleanType.get()),
+ optional(5, "longValue", Types.LongType.get()));
+
+ protected static final Types.NestedField STRUCT_FIELD = optional(3,
"structField", NESTED_FIELDS);
+
+ // create a schema with all supported fields
+ protected static final Schema SCHEMA = new Schema(
+ ID_FIELD,
+ DATA_FIELD,
+ STRUCT_FIELD
+ );
+
+ protected static final SortOrder sortOrder =
+
SortOrder.builderFor(SCHEMA).asc("id").asc("structField.longValue").build();
+
+ protected static final Map<String, String> properties =
+ ImmutableMap.of(TableProperties.DEFAULT_WRITE_METRICS_MODE, "none");
+
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
+ protected FileFormat fileFormat;
+ protected TestTables.TestTable table = null;
+ protected File metadataDir = null;
+ private File tableDir = null;
+ private OutputFileFactory fileFactory = null;
+
+ @Parameterized.Parameters(name = "FileFormat = {0}")
+ public static Object[][] parameters() {
+ return new Object[][] {
+ {FileFormat.ORC},
+ {FileFormat.PARQUET}
+ };
+ }
+
+ public TestWriterMetrics(FileFormat fileFormat) {
+ this.fileFormat = fileFormat;
+ }
+
+ protected abstract WriterFactory newWriterFactory(Schema dataSchema);
+
+
Review comment:
Done
##########
File path: data/src/test/java/org/apache/iceberg/io/TestWriterMetrics.java
##########
@@ -0,0 +1,150 @@
+/*
+ * 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 org.apache.iceberg.io;
+
+import java.io.File;
+import java.nio.ByteBuffer;
+import java.util.Map;
+import org.apache.iceberg.FileFormat;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.SortOrder;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.TestTables;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.types.Conversions;
+import org.apache.iceberg.types.Types;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+
Review comment:
Done
##########
File path: data/src/test/java/org/apache/iceberg/io/TestWriterMetrics.java
##########
@@ -0,0 +1,150 @@
+/*
+ * 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 org.apache.iceberg.io;
+
+import java.io.File;
+import java.nio.ByteBuffer;
+import java.util.Map;
+import org.apache.iceberg.FileFormat;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.SortOrder;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.TestTables;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.types.Conversions;
+import org.apache.iceberg.types.Types;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+
+import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.apache.iceberg.types.Types.NestedField.required;
+
+@RunWith(Parameterized.class)
+public abstract class TestWriterMetrics<T> {
+
+ private static final int FORMAT_V2 = 2;
+
+ protected static final Types.NestedField ID_FIELD = required(1, "id",
Types.IntegerType.get());
+ protected static final Types.NestedField DATA_FIELD = optional(2, "data",
Types.StringType.get());
+
+ protected static final Types.StructType NESTED_FIELDS = Types.StructType.of(
+ required(4, "booleanField", Types.BooleanType.get()),
+ optional(5, "longValue", Types.LongType.get()));
+
+ protected static final Types.NestedField STRUCT_FIELD = optional(3,
"structField", NESTED_FIELDS);
+
+ // create a schema with all supported fields
+ protected static final Schema SCHEMA = new Schema(
+ ID_FIELD,
+ DATA_FIELD,
+ STRUCT_FIELD
+ );
+
+ protected static final SortOrder sortOrder =
+
SortOrder.builderFor(SCHEMA).asc("id").asc("structField.longValue").build();
+
+ protected static final Map<String, String> properties =
+ ImmutableMap.of(TableProperties.DEFAULT_WRITE_METRICS_MODE, "none");
+
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
+ protected FileFormat fileFormat;
+ protected TestTables.TestTable table = null;
+ protected File metadataDir = null;
+ private File tableDir = null;
+ private OutputFileFactory fileFactory = null;
+
+ @Parameterized.Parameters(name = "FileFormat = {0}")
+ public static Object[][] parameters() {
+ return new Object[][] {
+ {FileFormat.ORC},
+ {FileFormat.PARQUET}
+ };
+ }
+
+ public TestWriterMetrics(FileFormat fileFormat) {
+ this.fileFormat = fileFormat;
+ }
+
+ protected abstract WriterFactory newWriterFactory(Schema dataSchema);
+
+
+ protected abstract T toRow(Integer id, String data, boolean boolValue, Long
longValue);
+
+ @Before
+ public void setupTable() throws Exception {
+ this.tableDir = temp.newFolder();
+ tableDir.delete(); // created by table create
+
+ this.metadataDir = new File(tableDir, "metadata");
+
+ this.table = TestTables.create(
+ tableDir,
+ "test",
+ SCHEMA,
+ PartitionSpec.unpartitioned(),
+ sortOrder,
+ FORMAT_V2);
+ table.updateProperties().set(TableProperties.DEFAULT_WRITE_METRICS_MODE,
"none").commit();
+
+ this.fileFactory = OutputFileFactory.builderFor(table, 1,
1).format(fileFormat).build();
+ }
+
+ @After
+ public void after() {
+ TestTables.clearTables();
+ }
+
+ @Test
+ public void verifySortedColMetric() throws Exception {
+ T row = toRow(3, "3", true, 3L);
+ FileAppender<T> appender = newWriterFactory(SCHEMA).newDataWriter(
Review comment:
Done
--
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]