From 05d3289dda98df7f4158622ff862b4353e620c1a Mon Sep 17 00:00:00 2001 From: Kevin Ge Date: Thu, 28 Mar 2024 23:58:58 -0400 Subject: [PATCH 01/13] add precision for int and bigint for hive type system --- .../main/java/com/linkedin/coral/common/HiveTypeSystem.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java b/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java index 32ecd526d..0b5131dde 100644 --- a/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java +++ b/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java @@ -59,6 +59,10 @@ public int getDefaultPrecision(SqlTypeName typeName) { switch (typeName) { // Hive will always require user to specify exact sizes for char, varchar; // Binary doesn't need any sizes; Decimal has the default of 10. + case INTEGER: + return 10; + case BIGINT: + return 19; case BINARY: case VARBINARY: case TIME: From 5e05b329ed0898232ddc356d63aa3f59c13c667b Mon Sep 17 00:00:00 2001 From: Kevin Ge Date: Tue, 9 Apr 2024 17:55:16 -0400 Subject: [PATCH 02/13] use static final variables for precisions --- .../com/linkedin/coral/common/HiveTypeSystem.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java b/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java index 0b5131dde..7a8075e65 100644 --- a/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java +++ b/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java @@ -12,8 +12,9 @@ import org.apache.calcite.sql.type.SqlTypeUtil; -// Copied from Hive source code +// Copied from Hive source code before HIVE-22978 patch public class HiveTypeSystem extends RelDataTypeSystemImpl { + // TODO: Rename to CoralTypeSystem // TODO: This should come from type system; Currently there is no definition // in type system for this. private static final int MAX_DECIMAL_PRECISION = 38; @@ -29,6 +30,8 @@ public class HiveTypeSystem extends RelDataTypeSystemImpl { private static final int DEFAULT_CHAR_PRECISION = 255; private static final int MAX_BINARY_PRECISION = Integer.MAX_VALUE; private static final int MAX_TIMESTAMP_PRECISION = 9; + private static final int DEFAULT_INTEGER_PRECISION = 10; + private static final int DEFAULT_BIGINT_PRECISION = 19; @Override public int getMaxScale(SqlTypeName typeName) { @@ -59,10 +62,6 @@ public int getDefaultPrecision(SqlTypeName typeName) { switch (typeName) { // Hive will always require user to specify exact sizes for char, varchar; // Binary doesn't need any sizes; Decimal has the default of 10. - case INTEGER: - return 10; - case BIGINT: - return 19; case BINARY: case VARBINARY: case TIME: @@ -88,6 +87,10 @@ public int getDefaultPrecision(SqlTypeName typeName) { case INTERVAL_MINUTE_SECOND: case INTERVAL_SECOND: return SqlTypeName.DEFAULT_INTERVAL_START_PRECISION; + case INTEGER: + return DEFAULT_INTEGER_PRECISION; + case BIGINT: + return DEFAULT_BIGINT_PRECISION; default: return -1; } From 52de7573ae2b996ba1b2db13f5ba5971812496d9 Mon Sep 17 00:00:00 2001 From: Kevin Ge Date: Tue, 9 Apr 2024 17:59:09 -0400 Subject: [PATCH 03/13] spotless check --- .../java/com/linkedin/coral/common/HiveTypeSystem.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java b/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java index 7a8075e65..54d83991b 100644 --- a/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java +++ b/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java @@ -1,5 +1,5 @@ /** - * Copyright 2017-2023 LinkedIn Corporation. All rights reserved. + * Copyright 2017-2024 LinkedIn Corporation. All rights reserved. * Licensed under the BSD-2 Clause license. * See LICENSE in the project root for license information. */ @@ -14,7 +14,6 @@ // Copied from Hive source code before HIVE-22978 patch public class HiveTypeSystem extends RelDataTypeSystemImpl { - // TODO: Rename to CoralTypeSystem // TODO: This should come from type system; Currently there is no definition // in type system for this. private static final int MAX_DECIMAL_PRECISION = 38; @@ -30,8 +29,8 @@ public class HiveTypeSystem extends RelDataTypeSystemImpl { private static final int DEFAULT_CHAR_PRECISION = 255; private static final int MAX_BINARY_PRECISION = Integer.MAX_VALUE; private static final int MAX_TIMESTAMP_PRECISION = 9; - private static final int DEFAULT_INTEGER_PRECISION = 10; - private static final int DEFAULT_BIGINT_PRECISION = 19; + private static final int DEFAULT_INTEGER_PRECISION = 10; + private static final int DEFAULT_BIGINT_PRECISION = 19; @Override public int getMaxScale(SqlTypeName typeName) { From ad1f5b42f2c2d519c466f6e20b9d4d6fbdbca1b6 Mon Sep 17 00:00:00 2001 From: Kevin Ge Date: Wed, 10 Apr 2024 14:04:13 -0400 Subject: [PATCH 04/13] fix converting type to typespec bug --- .../FromUtcTimestampOperatorTransformer.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/FromUtcTimestampOperatorTransformer.java b/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/FromUtcTimestampOperatorTransformer.java index bb8230da8..3bf3f6ad6 100644 --- a/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/FromUtcTimestampOperatorTransformer.java +++ b/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/FromUtcTimestampOperatorTransformer.java @@ -1,5 +1,5 @@ /** - * Copyright 2023 LinkedIn Corporation. All rights reserved. + * Copyright 2023-2024 LinkedIn Corporation. All rights reserved. * Licensed under the BSD-2 Clause license. * See LICENSE in the project root for license information. */ @@ -11,15 +11,13 @@ import java.util.Set; import org.apache.calcite.rel.type.RelDataType; -import org.apache.calcite.sql.SqlBasicTypeNameSpec; import org.apache.calcite.sql.SqlCall; -import org.apache.calcite.sql.SqlDataTypeSpec; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.SqlOperator; -import org.apache.calcite.sql.SqlTypeNameSpec; import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.calcite.sql.type.BasicSqlType; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.calcite.sql.type.SqlTypeUtil; import com.linkedin.coral.common.HiveTypeSystem; import com.linkedin.coral.common.calcite.CalciteUtil; @@ -122,12 +120,6 @@ protected SqlCall transform(SqlCall sqlCall) { } private SqlCall castOperand(SqlNode operand, RelDataType relDataType) { - return SqlStdOperatorTable.CAST.createCall(ZERO, operand, getSqlDataTypeSpecForCasting(relDataType)); - } - - private SqlDataTypeSpec getSqlDataTypeSpecForCasting(RelDataType relDataType) { - final SqlTypeNameSpec typeNameSpec = new SqlBasicTypeNameSpec(relDataType.getSqlTypeName(), - relDataType.getPrecision(), relDataType.getScale(), null, ZERO); - return new SqlDataTypeSpec(typeNameSpec, ZERO); + return SqlStdOperatorTable.CAST.createCall(ZERO, operand, SqlTypeUtil.convertTypeToSpec(relDataType)); } } From 0218a7f6c51faeab9f91fe8ee2291abe4924b94f Mon Sep 17 00:00:00 2001 From: Kevin Ge Date: Wed, 10 Apr 2024 16:52:18 -0400 Subject: [PATCH 05/13] add UT --- .../coral/hive/hive2rel/HiveToRelConverterTest.java | 9 +++++++++ .../java/com/linkedin/coral/hive/hive2rel/TestUtils.java | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/HiveToRelConverterTest.java b/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/HiveToRelConverterTest.java index d8f047777..6d79c2263 100644 --- a/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/HiveToRelConverterTest.java +++ b/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/HiveToRelConverterTest.java @@ -622,6 +622,15 @@ public void testNameSakeColumnNamesShouldGetUniqueIdentifiers() { assertEquals(generated, expected); } + @Test + public void testUnionIntAndBigInt() { + final String sql = "SELECT a FROM test.tableOne UNION ALL SELECT z FROM test.tableTwo"; + RelNode rel = converter.convertSql(sql); + assertEquals(rel.getRowType().getFieldCount(), 1); + // Should be BIGINT since it is a less restrictive type than INT + assertEquals(rel.getRowType().getFieldList().get(0).getType().getSqlTypeName(), SqlTypeName.BIGINT); + } + private String relToString(String sql) { return RelOptUtil.toString(converter.convertSql(sql)); } diff --git a/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/TestUtils.java b/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/TestUtils.java index 2ddeb312e..b626f5128 100644 --- a/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/TestUtils.java +++ b/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/TestUtils.java @@ -81,7 +81,7 @@ public static TestHive setupDefaultHive(HiveConf conf) throws IOException { try { driver.run("CREATE DATABASE IF NOT EXISTS test"); driver.run("CREATE TABLE IF NOT EXISTS test.tableOne(a int, b varchar(30), c double, d timestamp)"); - driver.run("CREATE TABLE IF NOT EXISTS test.tableTwo(x int, y double)"); + driver.run("CREATE TABLE IF NOT EXISTS test.tableTwo(x int, y double, z bigint)"); driver.run("CREATE DATABASE IF NOT EXISTS fuzzy_union"); From 071b434786c84a8bc3b92c898ce2b403fc1d8966 Mon Sep 17 00:00:00 2001 From: Kevin Ge Date: Thu, 11 Apr 2024 11:39:46 -0400 Subject: [PATCH 06/13] add tinyint and smallint precisions --- .../main/java/com/linkedin/coral/common/HiveTypeSystem.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java b/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java index 54d83991b..3c3afc8d6 100644 --- a/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java +++ b/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java @@ -29,6 +29,8 @@ public class HiveTypeSystem extends RelDataTypeSystemImpl { private static final int DEFAULT_CHAR_PRECISION = 255; private static final int MAX_BINARY_PRECISION = Integer.MAX_VALUE; private static final int MAX_TIMESTAMP_PRECISION = 9; + private static final int DEFAULT_TINYINT_PRECISION = 3; + private static final int DEFAULT_SMALLINT_PRECISION = 5; private static final int DEFAULT_INTEGER_PRECISION = 10; private static final int DEFAULT_BIGINT_PRECISION = 19; @@ -86,6 +88,10 @@ public int getDefaultPrecision(SqlTypeName typeName) { case INTERVAL_MINUTE_SECOND: case INTERVAL_SECOND: return SqlTypeName.DEFAULT_INTERVAL_START_PRECISION; + case TINYINT: + return DEFAULT_TINYINT_PRECISION; + case SMALLINT: + return DEFAULT_SMALLINT_PRECISION; case INTEGER: return DEFAULT_INTEGER_PRECISION; case BIGINT: From 8bdf787bb23bb6cecd141d9a80b9a4b2dbc2694b Mon Sep 17 00:00:00 2001 From: Kevin Ge Date: Thu, 11 Apr 2024 11:44:40 -0400 Subject: [PATCH 07/13] spotless --- .../linkedin/coral/hive/hive2rel/HiveToRelConverterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/HiveToRelConverterTest.java b/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/HiveToRelConverterTest.java index 6d79c2263..7ed3ee8e3 100644 --- a/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/HiveToRelConverterTest.java +++ b/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/HiveToRelConverterTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2017-2023 LinkedIn Corporation. All rights reserved. + * Copyright 2017-2024 LinkedIn Corporation. All rights reserved. * Licensed under the BSD-2 Clause license. * See LICENSE in the project root for license information. */ From 5b4cd4c021046136007adc5f163e76b54efa63ad Mon Sep 17 00:00:00 2001 From: Kevin Ge Date: Thu, 11 Apr 2024 11:59:26 -0400 Subject: [PATCH 08/13] spotless --- .../test/java/com/linkedin/coral/hive/hive2rel/TestUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/TestUtils.java b/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/TestUtils.java index b626f5128..b7eca5062 100644 --- a/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/TestUtils.java +++ b/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/TestUtils.java @@ -1,5 +1,5 @@ /** - * Copyright 2017-2023 LinkedIn Corporation. All rights reserved. + * Copyright 2017-2024 LinkedIn Corporation. All rights reserved. * Licensed under the BSD-2 Clause license. * See LICENSE in the project root for license information. */ From 4445feaa191766802cf09302409fe0f638004f31 Mon Sep 17 00:00:00 2001 From: Kevin Ge Date: Thu, 11 Apr 2024 16:57:14 -0400 Subject: [PATCH 09/13] spotless --- .../src/main/java/com/linkedin/coral/common/HiveTypeSystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java b/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java index 3c3afc8d6..d7f5b160e 100644 --- a/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java +++ b/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java @@ -29,7 +29,7 @@ public class HiveTypeSystem extends RelDataTypeSystemImpl { private static final int DEFAULT_CHAR_PRECISION = 255; private static final int MAX_BINARY_PRECISION = Integer.MAX_VALUE; private static final int MAX_TIMESTAMP_PRECISION = 9; - private static final int DEFAULT_TINYINT_PRECISION = 3; + private static final int DEFAULT_TINYINT_PRECISION = 3; private static final int DEFAULT_SMALLINT_PRECISION = 5; private static final int DEFAULT_INTEGER_PRECISION = 10; private static final int DEFAULT_BIGINT_PRECISION = 19; From 93e873cd6b46787832aaad020d76d007a47b2ff9 Mon Sep 17 00:00:00 2001 From: Kevin Ge Date: Fri, 12 Apr 2024 17:03:57 -0400 Subject: [PATCH 10/13] new UTs --- .../linkedin/coral/common/HiveTypeSystem.java | 2 +- .../hive/hive2rel/HiveToRelConverterTest.java | 31 ++++++++++++++++++- .../coral/hive/hive2rel/TestUtils.java | 4 ++- .../rel2trino/HiveToTrinoConverterTest.java | 15 +++++++++ 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java b/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java index d7f5b160e..6372a220b 100644 --- a/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java +++ b/coral-common/src/main/java/com/linkedin/coral/common/HiveTypeSystem.java @@ -12,7 +12,7 @@ import org.apache.calcite.sql.type.SqlTypeUtil; -// Copied from Hive source code before HIVE-22978 patch +// Precision and scale values copied from Hive source code public class HiveTypeSystem extends RelDataTypeSystemImpl { // TODO: This should come from type system; Currently there is no definition // in type system for this. diff --git a/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/HiveToRelConverterTest.java b/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/HiveToRelConverterTest.java index 7ed3ee8e3..e2eafb0e7 100644 --- a/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/HiveToRelConverterTest.java +++ b/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/HiveToRelConverterTest.java @@ -624,13 +624,42 @@ public void testNameSakeColumnNamesShouldGetUniqueIdentifiers() { @Test public void testUnionIntAndBigInt() { - final String sql = "SELECT a FROM test.tableOne UNION ALL SELECT z FROM test.tableTwo"; + final String sql = "SELECT a FROM test.tableOne UNION ALL SELECT bigint_col FROM test.tableInt"; RelNode rel = converter.convertSql(sql); assertEquals(rel.getRowType().getFieldCount(), 1); // Should be BIGINT since it is a less restrictive type than INT assertEquals(rel.getRowType().getFieldList().get(0).getType().getSqlTypeName(), SqlTypeName.BIGINT); } + @Test + public void testUnionIntAndSmallInt() { + final String sql = "SELECT smallint_col FROM test.tableInt UNION ALL SELECT a FROM test.tableOne"; + RelNode rel = converter.convertSql(sql); + assertEquals(rel.getRowType().getFieldCount(), 1); + // Should be INT since it is a less restrictive type than SMALLINT + assertEquals(rel.getRowType().getFieldList().get(0).getType().getSqlTypeName(), SqlTypeName.INTEGER); + } + + @Test + public void testUnionIntAndTinyInt() { + final String sql = "SELECT tinyint_col FROM test.tableInt UNION ALL SELECT a FROM test.tableOne"; + RelNode rel = converter.convertSql(sql); + assertEquals(rel.getRowType().getFieldCount(), 1); + // Should be INT since it is a less restrictive type than TINYINT + assertEquals(rel.getRowType().getFieldList().get(0).getType().getSqlTypeName(), SqlTypeName.INTEGER); + } + + @Test + public void testIntCastToBigIntDuringComparison() { + // We're testing that a comparison between INT and BIGINT sees a cast on the more restrictive type to the + // less restrictive type and not the other way around. In other words, the INT is cast to BIGINT. + final String sql = "SELECT CASE WHEN int_col = bigint_col THEN 'abc' ELSE 'def' END FROM test.tableInt"; + String expected = "LogicalProject(EXPR$0=[CASE(=(CAST($2):BIGINT, $3), 'abc', 'def')])\n" + + " LogicalTableScan(table=[[hive, test, tableint]])\n"; + + assertEquals(relToString(sql), expected); + } + private String relToString(String sql) { return RelOptUtil.toString(converter.convertSql(sql)); } diff --git a/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/TestUtils.java b/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/TestUtils.java index b7eca5062..a704b83a2 100644 --- a/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/TestUtils.java +++ b/coral-hive/src/test/java/com/linkedin/coral/hive/hive2rel/TestUtils.java @@ -81,7 +81,9 @@ public static TestHive setupDefaultHive(HiveConf conf) throws IOException { try { driver.run("CREATE DATABASE IF NOT EXISTS test"); driver.run("CREATE TABLE IF NOT EXISTS test.tableOne(a int, b varchar(30), c double, d timestamp)"); - driver.run("CREATE TABLE IF NOT EXISTS test.tableTwo(x int, y double, z bigint)"); + driver.run("CREATE TABLE IF NOT EXISTS test.tableTwo(x int, y double)"); + driver.run( + "CREATE TABLE IF NOT EXISTS test.tableInt(tinyint_col tinyint, smallint_col smallint, int_col int, bigint_col bigint)"); driver.run("CREATE DATABASE IF NOT EXISTS fuzzy_union"); diff --git a/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/HiveToTrinoConverterTest.java b/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/HiveToTrinoConverterTest.java index 7f5cb2ce9..ecc515a05 100644 --- a/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/HiveToTrinoConverterTest.java +++ b/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/HiveToTrinoConverterTest.java @@ -994,4 +994,19 @@ public void testSqlSelectAliasAppenderTransformerWithoutTableAliasPrefix() { + "WHERE \"tablea\".\"a\" > 5"; assertEquals(expandedSql, expected); } + + @Test + public void testIntCastToBigIntDuringComparison() { + // We're testing that a comparison between INT and BIGINT sees a cast on the more restrictive type to the + // less restrictive type and not the other way around. In other words, the INT is cast to BIGINT. + RelNode relNode = TestUtils.getHiveToRelConverter().convertSql( + "SELECT CASE WHEN a_integer = a_bigint THEN 'abc' ELSE 'def' END FROM test.table_from_utc_timestamp"); + RelToTrinoConverter relToTrinoConverter = TestUtils.getRelToTrinoConverter(); + String expandedSql = relToTrinoConverter.convert(relNode); + + String expected = + "SELECT CASE WHEN CAST(\"table_from_utc_timestamp\".\"a_integer\" AS BIGINT) = \"table_from_utc_timestamp\".\"a_bigint\" THEN 'abc' ELSE 'def' END\n" + + "FROM \"test\".\"table_from_utc_timestamp\" AS \"table_from_utc_timestamp\""; + assertEquals(expandedSql, expected); + } } From 0dc5ce149daa82ec89c0b73d4eccecda44cec661 Mon Sep 17 00:00:00 2001 From: Kevin Ge Date: Thu, 18 Jul 2024 13:57:44 -0400 Subject: [PATCH 11/13] add tableInt to rel to trino tests --- .../coral/trino/rel2trino/HiveToTrinoConverterTest.java | 6 +++--- .../java/com/linkedin/coral/trino/rel2trino/TestUtils.java | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/HiveToTrinoConverterTest.java b/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/HiveToTrinoConverterTest.java index ecc515a05..f9ea69a49 100644 --- a/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/HiveToTrinoConverterTest.java +++ b/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/HiveToTrinoConverterTest.java @@ -1000,13 +1000,13 @@ public void testIntCastToBigIntDuringComparison() { // We're testing that a comparison between INT and BIGINT sees a cast on the more restrictive type to the // less restrictive type and not the other way around. In other words, the INT is cast to BIGINT. RelNode relNode = TestUtils.getHiveToRelConverter().convertSql( - "SELECT CASE WHEN a_integer = a_bigint THEN 'abc' ELSE 'def' END FROM test.table_from_utc_timestamp"); + "SELECT CASE WHEN int_col = bigint_col THEN 'abc' ELSE 'def' END FROM test.tableInt"); RelToTrinoConverter relToTrinoConverter = TestUtils.getRelToTrinoConverter(); String expandedSql = relToTrinoConverter.convert(relNode); String expected = - "SELECT CASE WHEN CAST(\"table_from_utc_timestamp\".\"a_integer\" AS BIGINT) = \"table_from_utc_timestamp\".\"a_bigint\" THEN 'abc' ELSE 'def' END\n" - + "FROM \"test\".\"table_from_utc_timestamp\" AS \"table_from_utc_timestamp\""; + "SELECT CASE WHEN CAST(\"tableint\".\"int_col\" AS BIGINT) = \"tableint\".\"bigint_col\" THEN 'abc' ELSE 'def' END\n" + + "FROM \"test\".\"tableint\" AS \"tableint\""; assertEquals(expandedSql, expected); } } diff --git a/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/TestUtils.java b/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/TestUtils.java index 148085261..3e6f088f8 100644 --- a/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/TestUtils.java +++ b/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/TestUtils.java @@ -425,6 +425,9 @@ public static void initializeTablesAndViews(HiveConf conf) throws HiveException, run(driver, "CREATE TABLE IF NOT EXISTS test.tableFour(icol int, scol string, acol array, mcol map)"); + run(driver, + "CREATE TABLE IF NOT EXISTS test.tableInt(tinyint_col tinyint, smallint_col smallint, int_col int, bigint_col bigint)"); + } public static HiveConf loadResourceHiveConf() { From 26304ea358d277d36d0c73bd7662661a28c71541 Mon Sep 17 00:00:00 2001 From: Kevin Ge Date: Thu, 18 Jul 2024 14:00:22 -0400 Subject: [PATCH 12/13] spotless --- .../coral/trino/rel2trino/HiveToTrinoConverterTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/HiveToTrinoConverterTest.java b/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/HiveToTrinoConverterTest.java index f9ea69a49..82379efd7 100644 --- a/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/HiveToTrinoConverterTest.java +++ b/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/HiveToTrinoConverterTest.java @@ -999,8 +999,8 @@ public void testSqlSelectAliasAppenderTransformerWithoutTableAliasPrefix() { public void testIntCastToBigIntDuringComparison() { // We're testing that a comparison between INT and BIGINT sees a cast on the more restrictive type to the // less restrictive type and not the other way around. In other words, the INT is cast to BIGINT. - RelNode relNode = TestUtils.getHiveToRelConverter().convertSql( - "SELECT CASE WHEN int_col = bigint_col THEN 'abc' ELSE 'def' END FROM test.tableInt"); + RelNode relNode = TestUtils.getHiveToRelConverter() + .convertSql("SELECT CASE WHEN int_col = bigint_col THEN 'abc' ELSE 'def' END FROM test.tableInt"); RelToTrinoConverter relToTrinoConverter = TestUtils.getRelToTrinoConverter(); String expandedSql = relToTrinoConverter.convert(relNode); From 729686da13a89c709b60d8b9b30b05525e16a7b0 Mon Sep 17 00:00:00 2001 From: Kevin Ge Date: Wed, 24 Jul 2024 20:00:11 -0400 Subject: [PATCH 13/13] remove redundant test --- .../trino/rel2trino/HiveToTrinoConverterTest.java | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/HiveToTrinoConverterTest.java b/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/HiveToTrinoConverterTest.java index 82379efd7..7f5cb2ce9 100644 --- a/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/HiveToTrinoConverterTest.java +++ b/coral-trino/src/test/java/com/linkedin/coral/trino/rel2trino/HiveToTrinoConverterTest.java @@ -994,19 +994,4 @@ public void testSqlSelectAliasAppenderTransformerWithoutTableAliasPrefix() { + "WHERE \"tablea\".\"a\" > 5"; assertEquals(expandedSql, expected); } - - @Test - public void testIntCastToBigIntDuringComparison() { - // We're testing that a comparison between INT and BIGINT sees a cast on the more restrictive type to the - // less restrictive type and not the other way around. In other words, the INT is cast to BIGINT. - RelNode relNode = TestUtils.getHiveToRelConverter() - .convertSql("SELECT CASE WHEN int_col = bigint_col THEN 'abc' ELSE 'def' END FROM test.tableInt"); - RelToTrinoConverter relToTrinoConverter = TestUtils.getRelToTrinoConverter(); - String expandedSql = relToTrinoConverter.convert(relNode); - - String expected = - "SELECT CASE WHEN CAST(\"tableint\".\"int_col\" AS BIGINT) = \"tableint\".\"bigint_col\" THEN 'abc' ELSE 'def' END\n" - + "FROM \"test\".\"tableint\" AS \"tableint\""; - assertEquals(expandedSql, expected); - } }