You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2021/09/03 05:39:23 UTC

[GitHub] [iceberg] szehon-ho commented on a change in pull request #2240: Core: Auto promote sorted column metrics to truncate(16)

szehon-ho commented on a change in pull request #2240:
URL: https://github.com/apache/iceberg/pull/2240#discussion_r701597694



##########
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.DataFile;
+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}

Review comment:
       Avro returns null metrics, so it seems usually skipped from Metrics tests. 
    https://github.com/apache/iceberg/blob/master/core/src/main/java/org/apache/iceberg/avro/AvroMetrics.java
   

##########
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.DataFile;
+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<T> 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();

Review comment:
       Done

##########
File path: core/src/main/java/org/apache/iceberg/MetricsConfig.java
##########
@@ -77,6 +79,14 @@ public static MetricsConfig getDefault() {
   }
 
   public static MetricsConfig fromProperties(Map<String, String> props) {
+    return from(props, null);
+  }
+
+  public static MetricsConfig forTable(Table table) {

Review comment:
       Good catch, 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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org