Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public abstract class AbstractTestHive
.add(new ColumnMetadata("smallint_to_bigint", SMALLINT))
.add(new ColumnMetadata("integer_to_bigint", INTEGER))
.add(new ColumnMetadata("integer_to_varchar", INTEGER))
//.add(new ColumnMetadata("varchar_to_integer", createUnboundedVarcharType())) // this coercion is not permitted in Hive 3. TODO test this on Hive < 3.
.add(new ColumnMetadata("varchar_to_integer", createUnboundedVarcharType()))
.add(new ColumnMetadata("float_to_double", REAL))
.add(new ColumnMetadata("varchar_to_drop_in_row", createUnboundedVarcharType()))
.build();
Expand All @@ -427,10 +427,10 @@ private static RowType toRowType(List<ColumnMetadata> columns)

private static final MaterializedResult MISMATCH_SCHEMA_PRIMITIVE_FIELDS_DATA_BEFORE =
MaterializedResult.resultBuilder(SESSION, TINYINT, TINYINT, TINYINT, SMALLINT, SMALLINT, INTEGER, INTEGER, createUnboundedVarcharType(), REAL, createUnboundedVarcharType())
.row((byte) -11, (byte) 12, (byte) -13, (short) 14, (short) 15, -16, 17, /*"2147483647",*/ 18.0f, "2016-08-01")
.row((byte) 21, (byte) -22, (byte) 23, (short) -24, (short) 25, 26, -27, /*"asdf",*/ -28.0f, "2016-08-02")
.row((byte) -31, (byte) -32, (byte) 33, (short) 34, (short) -35, 36, 37, /*"-923",*/ 39.5f, "2016-08-03")
.row(null, (byte) 42, (byte) 43, (short) 44, (short) -45, 46, 47, /*"2147483648",*/ 49.5f, "2016-08-03")
.row((byte) -11, (byte) 12, (byte) -13, (short) 14, (short) 15, -16, 17, "2147483647", 18.0f, "2016-08-01")
.row((byte) 21, (byte) -22, (byte) 23, (short) -24, (short) 25, 26, -27, "asdf", -28.0f, "2016-08-02")
.row((byte) -31, (byte) -32, (byte) 33, (short) 34, (short) -35, 36, 37, "-923", 39.5f, "2016-08-03")
.row(null, (byte) 42, (byte) 43, (short) 44, (short) -45, 46, 47, "2147483648", 49.5f, "2016-08-03")
.build();

private static final MaterializedResult MISMATCH_SCHEMA_TABLE_DATA_BEFORE =
Expand All @@ -443,7 +443,7 @@ private static RowType toRowType(List<ColumnMetadata> columns)
result.add(rowResult);
result.add(Arrays.asList(rowResult, null, rowResult));
result.add(ImmutableMap.of(rowResult.get(1), rowResult));
result.add(rowResult.get(8));
result.add(rowResult.get(9));
return new MaterializedRow(materializedRow.getPrecision(), result);
}).collect(toImmutableList()))
.build();
Expand All @@ -456,7 +456,7 @@ private static RowType toRowType(List<ColumnMetadata> columns)
.add(new ColumnMetadata("smallint_to_bigint", BIGINT))
.add(new ColumnMetadata("integer_to_bigint", BIGINT))
.add(new ColumnMetadata("integer_to_varchar", createUnboundedVarcharType()))
//.add(new ColumnMetadata("varchar_to_integer", INTEGER))
.add(new ColumnMetadata("varchar_to_integer", INTEGER))
.add(new ColumnMetadata("float_to_double", DOUBLE))
.add(new ColumnMetadata("varchar_to_drop_in_row", createUnboundedVarcharType()))
.build();
Expand All @@ -477,10 +477,10 @@ private static RowType toRowType(List<ColumnMetadata> columns)

private static final MaterializedResult MISMATCH_SCHEMA_PRIMITIVE_FIELDS_DATA_AFTER =
MaterializedResult.resultBuilder(SESSION, SMALLINT, INTEGER, BIGINT, INTEGER, BIGINT, BIGINT, createUnboundedVarcharType(), INTEGER, DOUBLE, createUnboundedVarcharType())
.row((short) -11, 12, -13L, 14, 15L, -16L, "17", /*2147483647,*/ 18.0, "2016-08-01")
.row((short) 21, -22, 23L, -24, 25L, 26L, "-27", /*null,*/ -28.0, "2016-08-02")
.row((short) -31, -32, 33L, 34, -35L, 36L, "37", /*-923,*/ 39.5, "2016-08-03")
.row(null, 42, 43L, 44, -45L, 46L, "47", /*null,*/ 49.5, "2016-08-03")
.row((short) -11, 12, -13L, 14, 15L, -16L, "17", 2147483647, 18.0, "2016-08-01")
.row((short) 21, -22, 23L, -24, 25L, 26L, "-27", null, -28.0, "2016-08-02")
.row((short) -31, -32, 33L, 34, -35L, 36L, "37", -923, 39.5, "2016-08-03")
.row(null, 42, 43L, 44, -45L, 46L, "47", null, 49.5, "2016-08-03")
.build();

private static final MaterializedResult MISMATCH_SCHEMA_TABLE_DATA_AFTER =
Expand All @@ -495,7 +495,7 @@ private static RowType toRowType(List<ColumnMetadata> columns)
result.add(appendFieldRowResult);
result.add(Arrays.asList(appendFieldRowResult, null, appendFieldRowResult));
result.add(ImmutableMap.of(result.get(1), dropFieldRowResult));
result.add(result.get(8));
result.add(result.get(9));
return new MaterializedRow(materializedRow.getPrecision(), result);
}).collect(toImmutableList()))
.build();
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<dep.wire.version>3.2.2</dep.wire.version>
<dep.kotlin.version>1.4.0</dep.kotlin.version>

<dep.docker.images.version>76</dep.docker.images.version>
<dep.docker.images.version>77</dep.docker.images.version>

<!--
America/Bahia_Banderas has:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ private static HiveTableDefinition.HiveTableDefinitionBuilder tableDefinitionBui
" int_to_bigint INT," +
" bigint_to_varchar BIGINT," +
" float_to_double " + floatType + "," +
//" double_to_float DOUBLE," + // this coercion is not permitted in Hive 3. TODO test this on Hive < 3.
" double_to_float DOUBLE," +
" shortdecimal_to_shortdecimal DECIMAL(10,2)," +
" shortdecimal_to_longdecimal DECIMAL(10,2)," +
" longdecimal_to_shortdecimal DECIMAL(20,12)," +
" longdecimal_to_longdecimal DECIMAL(20,12)," +
//" float_to_decimal " + floatType + "," + // this coercion is not permitted in Hive 3. TODO test this on Hive < 3.
//" double_to_decimal DOUBLE," + // this coercion is not permitted in Hive 3. TODO test this on Hive < 3.
" float_to_decimal " + floatType + "," +
" double_to_decimal DOUBLE," +
" decimal_to_float DECIMAL(10,5)," +
" decimal_to_double DECIMAL(10,5)," +
" short_decimal_to_varchar DECIMAL(10,5)," +
Expand Down Expand Up @@ -284,6 +284,7 @@ private void doTestHiveCoercion(HiveTableDefinition tableDefinition)
String tableName = mutableTableInstanceOf(tableDefinition).getNameInDatabase();

String floatToDoubleType = tableName.toLowerCase(ENGLISH).contains("parquet") ? "DOUBLE" : "REAL";
String floatToDecimalVal = tableName.toLowerCase(ENGLISH).contains("parquet") ? "12345.12345" : "12345.12300";
String decimalToFloatVal = tableName.toLowerCase(ENGLISH).contains("parquet") ? "12345.12345" : "12345.124";

insertTableRows(tableName, floatToDoubleType);
Expand All @@ -303,13 +304,13 @@ private void doTestHiveCoercion(HiveTableDefinition tableDefinition)
"int_to_bigint",
"bigint_to_varchar",
"float_to_double",
// "double_to_float",
"double_to_float",
"shortdecimal_to_shortdecimal",
"shortdecimal_to_longdecimal",
"longdecimal_to_shortdecimal",
"longdecimal_to_longdecimal",
// "float_to_decimal",
// "double_to_decimal",
"float_to_decimal",
"double_to_decimal",
"decimal_to_float",
"decimal_to_double",
"short_decimal_to_varchar",
Expand All @@ -320,7 +321,7 @@ private void doTestHiveCoercion(HiveTableDefinition tableDefinition)
"varchar_to_smaller_varchar",
"id");

Function<Engine, Map<String, List<Object>>> expected = engine -> expectedValuesForEngineProvider(engine, tableName, decimalToFloatVal);
Function<Engine, Map<String, List<Object>>> expected = engine -> expectedValuesForEngineProvider(engine, tableName, decimalToFloatVal, floatToDecimalVal);

Map<String, List<Object>> expectedPrestoResults = expected.apply(Engine.TRINO);
assertEquals(ImmutableSet.copyOf(prestoReadColumns), expectedPrestoResults.keySet());
Expand Down Expand Up @@ -352,13 +353,13 @@ protected void insertTableRows(String tableName, String floatToDoubleType)
" INTEGER '2323', " +
" 12345, " +
" REAL '0.5', " +
//" DOUBLE '0.5', " +
" DOUBLE '0.5', " +
" DECIMAL '12345678.12', " +
" DECIMAL '12345678.12', " +
" DECIMAL '12345678.123456123456', " +
" DECIMAL '12345678.123456123456', " +
//" %2$s '12345.12345', " +
//" DOUBLE '12345.12345', " +
" %2$s '12345.12345', " +
" DOUBLE '12345.12345', " +
" DECIMAL '12345.12345', " +
" DECIMAL '12345.12345', " +
" DECIMAL '12345.12345', " +
Expand All @@ -380,13 +381,13 @@ protected void insertTableRows(String tableName, String floatToDoubleType)
" INTEGER '-2323', " +
" -12345, " +
" REAL '-1.5', " +
//" DOUBLE '-1.5', " +
" DOUBLE '-1.5', " +
" DECIMAL '-12345678.12', " +
" DECIMAL '-12345678.12', " +
" DECIMAL '-12345678.123456123456', " +
" DECIMAL '-12345678.123456123456', " +
//" %2$s '-12345.12345', " +
//" DOUBLE '-12345.12345', " +
" %2$s '-12345.12345', " +
" DOUBLE '-12345.12345', " +
" DECIMAL '-12345.12345', " +
" DECIMAL '-12345.12345', " +
" DECIMAL '-12345.12345', " +
Expand All @@ -400,7 +401,7 @@ protected void insertTableRows(String tableName, String floatToDoubleType)
floatToDoubleType));
}

protected Map<String, List<Object>> expectedValuesForEngineProvider(Engine engine, String tableName, String decimalToFloatVal)
protected Map<String, List<Object>> expectedValuesForEngineProvider(Engine engine, String tableName, String decimalToFloatVal, String floatToDecimalVal)
{
String hiveValueForCaseChangeField;
Predicate<String> isFormat = formatName -> tableName.toLowerCase(ENGLISH).contains(formatName);
Expand Down Expand Up @@ -493,7 +494,7 @@ else if (getHiveVersionMajor() == 3 && isFormat.test("orc")) {
.put("float_to_double", Arrays.asList(
0.5,
-1.5))
// .put("double_to_float", Arrays.asList(0.5, -1.5))
.put("double_to_float", Arrays.asList(0.5, -1.5))
.put("shortdecimal_to_shortdecimal", Arrays.asList(
new BigDecimal("12345678.1200"),
new BigDecimal("-12345678.1200")))
Expand All @@ -506,8 +507,8 @@ else if (getHiveVersionMajor() == 3 && isFormat.test("orc")) {
.put("longdecimal_to_longdecimal", Arrays.asList(
new BigDecimal("12345678.12345612345600"),
new BigDecimal("-12345678.12345612345600")))
// .put("float_to_decimal", Arrays.asList(new BigDecimal(floatToDecimalVal), new BigDecimal("-" + floatToDecimalVal)))
// .put("double_to_decimal", Arrays.asList(new BigDecimal("12345.12345"), new BigDecimal("-12345.12345")))
.put("float_to_decimal", Arrays.asList(new BigDecimal(floatToDecimalVal), new BigDecimal("-" + floatToDecimalVal)))
.put("double_to_decimal", Arrays.asList(new BigDecimal("12345.12345"), new BigDecimal("-12345.12345")))
.put("decimal_to_float", Arrays.asList(
Float.parseFloat(decimalToFloatVal),
-Float.parseFloat(decimalToFloatVal)))
Expand Down Expand Up @@ -719,13 +720,13 @@ private void assertProperAlteredTableSchema(String tableName)
row("int_to_bigint", "bigint"),
row("bigint_to_varchar", "varchar"),
row("float_to_double", "double"),
//row("double_to_float", floatType),
row("double_to_float", floatType),
row("shortdecimal_to_shortdecimal", "decimal(18,4)"),
row("shortdecimal_to_longdecimal", "decimal(20,4)"),
row("longdecimal_to_shortdecimal", "decimal(12,2)"),
row("longdecimal_to_longdecimal", "decimal(38,14)"),
//row("float_to_decimal", "decimal(10,5)"),
//row("double_to_decimal", "decimal(10,5)"),
row("float_to_decimal", "decimal(10,5)"),
row("double_to_decimal", "decimal(10,5)"),
row("decimal_to_float", floatType),
row("decimal_to_double", "double"),
row("short_decimal_to_varchar", "varchar"),
Expand Down Expand Up @@ -763,13 +764,13 @@ private void assertColumnTypes(
.put("int_to_bigint", BIGINT)
.put("bigint_to_varchar", VARCHAR)
.put("float_to_double", DOUBLE)
//.put( "double_to_float", floatType)
.put("double_to_float", floatType)
.put("shortdecimal_to_shortdecimal", DECIMAL)
.put("shortdecimal_to_longdecimal", DECIMAL)
.put("longdecimal_to_shortdecimal", DECIMAL)
.put("longdecimal_to_longdecimal", DECIMAL)
//.put("float_to_decimal", DECIMAL)
//.put("double_to_decimal", DECIMAL)
.put("float_to_decimal", DECIMAL)
.put("double_to_decimal", DECIMAL)
.put("decimal_to_float", floatType)
.put("decimal_to_double", DOUBLE)
.put("short_decimal_to_varchar", VARCHAR)
Expand Down Expand Up @@ -801,13 +802,13 @@ private static void alterTableColumnTypes(String tableName)
onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN int_to_bigint int_to_bigint bigint", tableName));
onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN bigint_to_varchar bigint_to_varchar string", tableName));
onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN float_to_double float_to_double double", tableName));
//onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN double_to_float double_to_float %s", tableName, floatType));
onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN double_to_float double_to_float %s", tableName, floatType));
onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN shortdecimal_to_shortdecimal shortdecimal_to_shortdecimal DECIMAL(18,4)", tableName));
onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN shortdecimal_to_longdecimal shortdecimal_to_longdecimal DECIMAL(20,4)", tableName));
onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN longdecimal_to_shortdecimal longdecimal_to_shortdecimal DECIMAL(12,2)", tableName));
onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN longdecimal_to_longdecimal longdecimal_to_longdecimal DECIMAL(38,14)", tableName));
//onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN float_to_decimal float_to_decimal DECIMAL(10,5)", tableName));
//onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN double_to_decimal double_to_decimal DECIMAL(10,5)", tableName));
onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN float_to_decimal float_to_decimal DECIMAL(10,5)", tableName));
onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN double_to_decimal double_to_decimal DECIMAL(10,5)", tableName));
onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN decimal_to_float decimal_to_float %s", tableName, floatType));
onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN decimal_to_double decimal_to_double double", tableName));
onHive().executeQuery(format("ALTER TABLE %s CHANGE COLUMN short_decimal_to_varchar short_decimal_to_varchar string", tableName));
Expand Down