You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by lp...@apache.org on 2022/07/18 19:37:58 UTC

[hive] branch master updated: HIVE-26403: Iceberg CTAS fails if source table schema contains decimal column (#3450) (Laszlo Pinter, reviewed by Adam Szita)

This is an automated email from the ASF dual-hosted git repository.

lpinter pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new d3309c0ea9d HIVE-26403: Iceberg CTAS fails if source table schema contains decimal column (#3450) (Laszlo Pinter, reviewed by Adam Szita)
d3309c0ea9d is described below

commit d3309c0ea9da907af4d27427805084b7331a6c24
Author: László Pintér <47...@users.noreply.github.com>
AuthorDate: Mon Jul 18 21:37:52 2022 +0200

    HIVE-26403: Iceberg CTAS fails if source table schema contains decimal column (#3450) (Laszlo Pinter, reviewed by Adam Szita)
---
 .../IcebergDecimalObjectInspector.java             |   2 +-
 .../iceberg/mr/hive/TestHiveIcebergCTAS.java       | 100 +++++++++++++++++++++
 2 files changed, 101 insertions(+), 1 deletion(-)

diff --git a/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/serde/objectinspector/IcebergDecimalObjectInspector.java b/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/serde/objectinspector/IcebergDecimalObjectInspector.java
index b30a3fadbc6..6c431e2d181 100644
--- a/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/serde/objectinspector/IcebergDecimalObjectInspector.java
+++ b/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/serde/objectinspector/IcebergDecimalObjectInspector.java
@@ -38,7 +38,7 @@ public final class IcebergDecimalObjectInspector extends AbstractPrimitiveJavaOb
           .build();
 
   public static IcebergDecimalObjectInspector get(int precision, int scale) {
-    Preconditions.checkArgument(scale < precision);
+    Preconditions.checkArgument(scale <= precision);
     Preconditions.checkArgument(precision <= HiveDecimal.MAX_PRECISION);
     Preconditions.checkArgument(scale <= HiveDecimal.MAX_SCALE);
 
diff --git a/iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergCTAS.java b/iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergCTAS.java
index fda9652e0fa..4e0f19a23c2 100644
--- a/iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergCTAS.java
+++ b/iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergCTAS.java
@@ -279,4 +279,104 @@ public class TestHiveIcebergCTAS extends HiveIcebergStorageHandlerWithEngineBase
       shell.executeStatement("DROP TABLE target");
     }
   }
+
+  @Test
+  public void testCTASForAllColumnTypes() {
+    Assume.assumeTrue(HiveIcebergSerDe.CTAS_EXCEPTION_MSG, testTableType == TestTables.TestTableType.HIVE_CATALOG);
+    shell.setHiveSessionValue(InputFormatConfig.SCHEMA_AUTO_CONVERSION, "true");
+    String sourceCreate = "CREATE EXTERNAL TABLE source (" +
+        "timestamp_col_1 TIMESTAMP, " +
+        "decimal3003_col_2 DECIMAL(30, 3), " +
+        "tinyint_col_3 TINYINT, " +
+        "decimal0101_col_4 DECIMAL(1, 1), " +
+        "boolean_col_5 BOOLEAN, " +
+        "float_col_6 FLOAT, " +
+        "bigint_col_7 BIGINT, " +
+        "varchar0098_col_8 VARCHAR(98), " +
+        "timestamp_col_9 TIMESTAMP, " +
+        "bigint_col_10 BIGINT, " +
+        "decimal0903_col_11 DECIMAL(9, 3), " +
+        "timestamp_col_12 TIMESTAMP, " +
+        "timestamp_col_13 TIMESTAMP, " +
+        "float_col_14 FLOAT, " +
+        "char0254_col_15 CHAR(254), " +
+        "double_col_16 DOUBLE, " +
+        "timestamp_col_17 TIMESTAMP, " +
+        "boolean_col_18 BOOLEAN, " +
+        "decimal2608_col_19 DECIMAL(26, 8), " +
+        "varchar0216_col_20 VARCHAR(216), " +
+        "string_col_21 STRING, " +
+        "bigint_col_22 BIGINT, " +
+        "boolean_col_23 BOOLEAN, " +
+        "timestamp_col_24 TIMESTAMP, " +
+        "boolean_col_25 BOOLEAN, " +
+        "decimal2016_col_26 DECIMAL(20, 16), " +
+        "string_col_27 STRING, " +
+        "decimal0202_col_28 DECIMAL(2, 2), " +
+        "float_col_29 FLOAT, " +
+        "decimal2020_col_30 DECIMAL(20, 20), " +
+        "boolean_col_31 BOOLEAN, " +
+        "double_col_32 DOUBLE, " +
+        "varchar0148_col_33 VARCHAR(148), " +
+        "decimal2121_col_34 DECIMAL(21, 21), " +
+        "tinyint_col_35 TINYINT, " +
+        "boolean_col_36 BOOLEAN, " +
+        "boolean_col_37 BOOLEAN, " +
+        "string_col_38 STRING, " +
+        "decimal3420_col_39 DECIMAL(34, 20), " +
+        "timestamp_col_40 TIMESTAMP, " +
+        "decimal1408_col_41 DECIMAL(14, 8), " +
+        "string_col_42 STRING, " +
+        "decimal0902_col_43 DECIMAL(9, 2), " +
+        "varchar0204_col_44 VARCHAR(204), " +
+        "boolean_col_45 BOOLEAN, " +
+        "timestamp_col_46 TIMESTAMP, " +
+        "boolean_col_47 BOOLEAN, " +
+        "bigint_col_48 BIGINT, " +
+        "boolean_col_49 BOOLEAN, " +
+        "smallint_col_50 SMALLINT, " +
+        "decimal0704_col_51 DECIMAL(7, 4), " +
+        "timestamp_col_52 TIMESTAMP, " +
+        "boolean_col_53 BOOLEAN, " +
+        "timestamp_col_54 TIMESTAMP, " +
+        "int_col_55 INT, " +
+        "decimal0505_col_56 DECIMAL(5, 5), " +
+        "char0155_col_57 CHAR(155), " +
+        "boolean_col_58 BOOLEAN, " +
+        "bigint_col_59 BIGINT, " +
+        "boolean_col_60 BOOLEAN, " +
+        "boolean_col_61 BOOLEAN, " +
+        "char0249_col_62 CHAR(249), " +
+        "boolean_col_63 BOOLEAN, " +
+        "timestamp_col_64 TIMESTAMP, " +
+        "decimal1309_col_65 DECIMAL(13, 9), " +
+        "int_col_66 INT, " +
+        "float_col_67 FLOAT, " +
+        "timestamp_col_68 TIMESTAMP, " +
+        "timestamp_col_69 TIMESTAMP, " +
+        "boolean_col_70 BOOLEAN, " +
+        "timestamp_col_71 TIMESTAMP, " +
+        "double_col_72 DOUBLE, " +
+        "boolean_col_73 BOOLEAN, " +
+        "char0222_col_74 CHAR(222), " +
+        "float_col_75 FLOAT, " +
+        "string_col_76 STRING, " +
+        "decimal2612_col_77 DECIMAL(26, 12), " +
+        "timestamp_col_78 TIMESTAMP, " +
+        "char0128_col_79 CHAR(128), " +
+        "timestamp_col_80 TIMESTAMP, " +
+        "double_col_81 DOUBLE, " +
+        "timestamp_col_82 TIMESTAMP, " +
+        "float_col_83 FLOAT, " +
+        "decimal2622_col_84 DECIMAL(26, 22), " +
+        "double_col_85 DOUBLE, " +
+        "float_col_86 FLOAT, " +
+        "decimal0907_col_87 DECIMAL(9, 7)) " +
+        "ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'";
+
+    shell.executeStatement(sourceCreate);
+
+    String ctas = "CREATE TABLE target STORED BY ICEBERG STORED AS orc AS SELECT * FROM source";
+    shell.executeStatement(ctas);
+  }
 }