From 6028e90ea0390cf1a7a3d7b09f9dd1f9a73e720c Mon Sep 17 00:00:00 2001 From: findinpath Date: Tue, 25 Jan 2022 07:47:03 +0100 Subject: [PATCH] Showcase that Hive expects FIXED_LEN_BYTE_ARRAY for decimal values --- .../product/hive/TestHiveCompatibility.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveCompatibility.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveCompatibility.java index 5c5607052151..79874bf2a3b2 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveCompatibility.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveCompatibility.java @@ -192,6 +192,26 @@ public void testTimestampFieldWrittenByOptimizedParquetWriterCannotBeReadByHive( onTrino().executeQuery(format("DROP TABLE %s", tableName)); } + @Test(groups = STORAGE_FORMATS_DETAILED) + public void testSmallDecimalFieldWrittenByOptimizedParquetWriterCannotBeReadByHive() + throws Exception + { + // only admin user is allowed to change session properties + setAdminRole(onTrino().getConnection()); + setSessionProperty(onTrino().getConnection(), "hive.experimental_parquet_optimized_writer_enabled", "true"); + + String tableName = "parquet_table_small_decimal_created_in_trino"; + onTrino().executeQuery("DROP TABLE IF EXISTS " + tableName); + onTrino().executeQuery("CREATE TABLE " + tableName + " (a_decimal DECIMAL(5,0)) WITH (format='PARQUET')"); + onTrino().executeQuery("INSERT INTO " + tableName + " VALUES (123)"); + + // Hive expects `FIXED_LEN_BYTE_ARRAY` for decimal values irrespective of the Parquet specification which allows `INT32`, `INT64` for short precision decimal types + assertQueryFailure(() -> onHive().executeQuery("SELECT a_decimal FROM " + tableName)) + .hasMessageMatching(".* org.apache.parquet.io.ParquetDecodingException: Can not read value at 1 in block 0 in file .*"); + + onTrino().executeQuery(format("DROP TABLE %s", tableName)); + } + @DataProvider public static TestHiveStorageFormats.StorageFormat[] storageFormatsWithConfiguration() {