[ 
https://issues.apache.org/jira/browse/DRILL-7313?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16878863#comment-16878863
 ] 

ASF GitHub Bot commented on DRILL-7313:
---------------------------------------

arina-ielchiieva commented on pull request #1819: DRILL-7313: Use Hive schema 
for MaprDB native reader when field was empty
URL: https://github.com/apache/drill/pull/1819#discussion_r300486007
 
 

 ##########
 File path: 
contrib/storage-hive/core/src/test/java/org/apache/drill/exec/store/hive/schema/TestSchemaConversion.java
 ##########
 @@ -0,0 +1,184 @@
+/*
+ * 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.exec.store.hive.schema;
+
+import org.apache.calcite.sql.type.SqlTypeFactoryImpl;
+import org.apache.drill.categories.SlowTest;
+import org.apache.drill.common.types.TypeProtos;
+import org.apache.drill.common.types.Types;
+import org.apache.drill.exec.planner.types.DrillRelDataTypeSystem;
+import org.apache.drill.exec.planner.types.HiveToRelDataTypeConverter;
+import org.apache.drill.exec.record.metadata.ColumnMetadata;
+import org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata;
+import org.apache.drill.exec.record.metadata.SchemaBuilder;
+import org.apache.drill.exec.store.hive.HiveUtilities;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertEquals;
+
+@Category({SlowTest.class})
+public class TestSchemaConversion {
+  private static final HiveToRelDataTypeConverter dataTypeConverter
+      = new HiveToRelDataTypeConverter(new SqlTypeFactoryImpl(new 
DrillRelDataTypeSystem()));
+
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  @Test
+  public void testPrimitiveSchema() {
+    verifyConversion("int", Types.optional(TypeProtos.MinorType.INT));
+    verifyConversion("varchar(123)", 
TypeProtos.MajorType.newBuilder().setMinorType(TypeProtos.MinorType.VARCHAR).setPrecision(123).build());
+    verifyConversion("timestamp", 
Types.optional(TypeProtos.MinorType.TIMESTAMP));
+  }
+
+  @Test
+  public void testStructSchema() {
+    ColumnMetadata expectedSchema = new SchemaBuilder()
+        .addMap("a")
+            .addNullable("t1", TypeProtos.MinorType.BIT)
+            .addNullable("t2", TypeProtos.MinorType.INT)
+            .resumeSchema()
+        .buildSchema()
+        .metadata(0);
+    verifyConversion("struct<t1:boolean,t2:int>", expectedSchema);
+
+    expectedSchema = new SchemaBuilder()
+        .addMap("a")
+            .addNullable("t1", TypeProtos.MinorType.BIT)
+            .addMap("t2")
+                .addNullable("t3", TypeProtos.MinorType.VARDECIMAL, 38, 8)
+                .resumeMap()
+            .resumeSchema()
+        .buildSchema()
+        .metadata(0);
+    verifyConversion("struct<t1:boolean,t2:struct<t3:decimal(38,8)>>", 
expectedSchema);
+  }
+
+  @Test
+  public void testRepeatedSchema() {
+    verifyConversion("array<boolean>", 
Types.repeated(TypeProtos.MinorType.BIT));
+
+    ColumnMetadata expectedSchema = new SchemaBuilder()
+        .addRepeatedList("a")
+            .addArray(TypeProtos.MinorType.BIT)
+            .resumeSchema()
+        .buildSchema()
+        .metadata(0);
+    verifyConversion("array<array<boolean>>", expectedSchema);
+
+    expectedSchema = new SchemaBuilder()
+        .addRepeatedList("a")
+            .addDimension()
+                .addArray(TypeProtos.MinorType.BIT)
+                .resumeList()
+            .resumeSchema()
+        .buildSchema()
+        .metadata(0);
+    verifyConversion("array<array<array<boolean>>>", expectedSchema);
+  }
+
+  @Test
+  public void testRepeatedStructSchema() {
+    ColumnMetadata expectedSchema = new SchemaBuilder()
+        .addMapArray("a")
+            .addNullable("t1", TypeProtos.MinorType.VARCHAR, 999)
+            .addNullable("t2", TypeProtos.MinorType.INT)
+            .resumeSchema()
+        .buildSchema()
+        .metadata(0);
+    verifyConversion("array<struct<t1:varchar(999),t2:int>>", expectedSchema);
+
+    expectedSchema = new SchemaBuilder()
+        .addRepeatedList("a")
+            .addMapArray()
+                .addNullable("t1", TypeProtos.MinorType.VARCHAR, 999)
+                .addNullable("t2", TypeProtos.MinorType.INT)
+                .resumeList()
+            .resumeSchema()
+        .buildSchema()
+        .metadata(0);
+    verifyConversion("array<array<struct<t1:varchar(999),t2:int>>>", 
expectedSchema);
+
+    expectedSchema = new SchemaBuilder()
+        .addRepeatedList("a")
+            .addDimension()
+                .addMapArray()
+                    .addRepeatedList("t1")
+                        .addArray(TypeProtos.MinorType.VARCHAR, 999)
+                        .resumeMap()
+                    .addArray("t2", TypeProtos.MinorType.VARDECIMAL, 28, 14)
+                    .resumeList()
+                .resumeList()
+            .resumeSchema()
+        .buildSchema()
+        .metadata(0);
+    
verifyConversion("array<array<array<struct<t1:array<array<varchar(999)>>,t2:array<decimal(28,14)>>>>>",
 expectedSchema);
+  }
+
+  @Test
+  public void testUnionSchema() {
+    thrown.expect(UnsupportedOperationException.class);
+    thrown.expectMessage(containsString("Unsupported data type"));
 
 Review comment:
   Nit: checking exception message is brittle. I would say checking that we 
receive `UnsupportedOperationException` is enough.
 
----------------------------------------------------------------
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:
us...@infra.apache.org


> Use Hive schema for MaprDB native reader when field was empty
> -------------------------------------------------------------
>
>                 Key: DRILL-7313
>                 URL: https://issues.apache.org/jira/browse/DRILL-7313
>             Project: Apache Drill
>          Issue Type: Task
>    Affects Versions: 1.16.0
>            Reporter: Volodymyr Vysotskyi
>            Assignee: Volodymyr Vysotskyi
>            Priority: Major
>             Fix For: 1.17.0
>
>
> Currently, when an external Hive MaprDB table is queried using hive plugin 
> with enabled {{store.hive.maprdb_json.optimize_scan_with_native_reader}}, 
> some queries may fail due to soft schema change, though Hive knows actual 
> data types.
> For example, when we have a table with several fields, and one of them has 
> only several non-null values, queries with grouping by such field will fail 
> due to schema change.
> The goal of this Jira is to allow using types from Hive when a non-existing 
> field is created, so it will allow avoiding such issues.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to