You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by GitBox <gi...@apache.org> on 2019/07/17 18:47:02 UTC

[GitHub] [drill] vvysotskyi commented on a change in pull request #1826: DRILL-7272: Drill Metastore Read / Write API and Drill Iceberg Metastore implementation

vvysotskyi commented on a change in pull request #1826: DRILL-7272: Drill Metastore Read / Write API and Drill Iceberg Metastore implementation
URL: https://github.com/apache/drill/pull/1826#discussion_r304524503
 
 

 ##########
 File path: metastore/iceberg-metastore/src/main/java/org/apache/drill/metastore/iceberg/metadata/IcebergTableSchema.java
 ##########
 @@ -0,0 +1,160 @@
+/*
+ * 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.drill.metastore.iceberg.metadata;
+
+import org.apache.drill.metastore.MetastoreFieldDefinition;
+import org.apache.drill.metastore.iceberg.exceptions.IcebergMetastoreException;
+import org.apache.drill.shaded.guava.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.types.Types;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * Provides Iceberg table schema and its partition specification.
+ */
+public class IcebergTableSchema {
+
+  public static final String STORAGE_PLUGIN = "storagePlugin";
+  public static final String WORKSPACE = "workspace";
+  public static final String TABLE_NAME = "tableName";
+  public static final String METADATA_KEY = "metadataKey";
+
+  public static final int STARTING_SCHEMA_INDEX = 1;
+  public static final int STARTING_COMPLEX_TYPES_INDEX = 10_000;
+
+  private static final Map<String, org.apache.iceberg.types.Type> JAVA_TO_ICEBERG_TYPE_MAP =
+    ImmutableMap.<String, org.apache.iceberg.types.Type>builder()
+    .put("string", Types.StringType.get())
+    .put("int", Types.IntegerType.get())
+    .put("integer", Types.IntegerType.get())
+    .put("long", Types.LongType.get())
+    .put("float", Types.FloatType.get())
+    .put("double", Types.DoubleType.get())
+    .put("boolean", Types.BooleanType.get())
+    .build();
+
+  private static final Map<String, Integer> PARTITION_KEYS = ImmutableMap.of(
+    STORAGE_PLUGIN, 1,
+    WORKSPACE, 2,
+    TABLE_NAME, 3,
+    METADATA_KEY, 4);
+
+  private final Schema metastoreSchema;
+  private final PartitionSpec partitionSpec;
+
+  public IcebergTableSchema(Schema metastoreSchema, PartitionSpec partitionSpec) {
+    this.metastoreSchema = metastoreSchema;
+    this.partitionSpec = partitionSpec;
+  }
+
+  /**
+   * Based on given class fields annotated with {@link MetastoreFieldDefinition}
+   * generates Iceberg table schema and its partition specification.
+   *
+   * @param clazz base class for Iceberg schema
+   * @return instance of Iceberg schema
+   */
+  public static IcebergTableSchema of(Class<?> clazz) {
+    List<Types.NestedField> metastoreSchemaFields = new ArrayList<>();
+    Map<Integer, Types.NestedField> partitionSpecSchemaFields = new TreeMap<>();
 
 Review comment:
   Looks like only values from `partitionSpecSchemaFields` are used. Is it possible to replace it with the list, or it is used intentionally to obtain values in a specific order based on their value in PARTITION_KEYS map or to preserve fields uniqueness using their indexes?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services