Skip to content

Commit

Permalink
[native] Disable Parsing Decimal as Double (#24065)
Browse files Browse the repository at this point in the history
  • Loading branch information
zuyu authored Nov 19, 2024
1 parent 0edeb7e commit 42412f4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ public void testAnalyzeStats()
// column_name | data_size | distinct_values_count | nulls_fraction | row_count | low_value | high_value
assertQuery("SHOW STATS FOR region",
"SELECT * FROM (VALUES" +
"('regionkey', NULL, 5.0, 0.0, NULL, '0', '4', NULL)," +
"('name', 54.0, 5.0, 0.0, NULL, NULL, NULL, NULL)," +
"('comment', 350.0, 5.0, 0.0, NULL, NULL, NULL, NULL)," +
"(NULL, NULL, NULL, NULL, 5.0, NULL, NULL, NULL))");
"('regionkey', NULL, 5e0, 0e0, NULL, '0', '4', NULL)," +
"('name', 5.4e1, 5e0, 0e0, NULL, NULL, NULL, NULL)," +
"('comment', 3.5e2, 5e0, 0e0, NULL, NULL, NULL, NULL)," +
"(NULL, NULL, NULL, NULL, 5e0, NULL, NULL, NULL))");

// Create a partitioned table and run analyze on it.
String tmpTableName = generateRandomTableName();
Expand All @@ -291,17 +291,17 @@ public void testAnalyzeStats()
assertUpdate(String.format("ANALYZE %s", tmpTableName), 25);
assertQuery(String.format("SHOW STATS for %s", tmpTableName),
"SELECT * FROM (VALUES" +
"('name', 277.0, 1.0, 0.0, NULL, NULL, NULL, NULL)," +
"('regionkey', NULL, 5.0, 0.0, NULL, '0', '4', NULL)," +
"('nationkey', NULL, 25.0, 0.0, NULL, '0', '24', NULL)," +
"(NULL, NULL, NULL, NULL, 25.0, NULL, NULL, NULL))");
"('name', 2.77e2, 1e0, 0e0, NULL, NULL, NULL, NULL)," +
"('regionkey', NULL, 5e0, 0e0, NULL, '0', '4', NULL)," +
"('nationkey', NULL, 2.5e1, 0e0, NULL, '0', '24', NULL)," +
"(NULL, NULL, NULL, NULL, 2.5e1, NULL, NULL, NULL))");
assertUpdate(String.format("ANALYZE %s WITH (partitions = ARRAY[ARRAY['0','0'],ARRAY['4', '11']])", tmpTableName), 2);
assertQuery(String.format("SHOW STATS for (SELECT * FROM %s where regionkey=4 and nationkey=11)", tmpTableName),
"SELECT * FROM (VALUES" +
"('name', 8.0, 1.0, 0.0, NULL, NULL, NULL, NULL)," +
"('regionkey', NULL, 1.0, 0.0, NULL, '4', '4', NULL)," +
"('nationkey', NULL, 1.0, 0.0, NULL, '11', '11', NULL)," +
"(NULL, NULL, NULL, NULL, 1.0, NULL, NULL, NULL))");
"('name', 8e0, 1e0, 0e0, NULL, NULL, NULL, NULL)," +
"('regionkey', NULL, 1e0, 0e0, NULL, '4', '4', NULL)," +
"('nationkey', NULL, 1e0, 0e0, NULL, '11', '11', NULL)," +
"(NULL, NULL, NULL, NULL, 1e0, NULL, NULL, NULL))");
}
finally {
dropTableIfExists(tmpTableName);
Expand All @@ -321,9 +321,9 @@ public void testAnalyzeStatsOnDecimals()
assertUpdate(String.format("ANALYZE %s", tmpTableName), 7);
assertQuery(String.format("SHOW STATS for %s", tmpTableName),
"SELECT * FROM (VALUES" +
"('c0', NULL,4.0 , 0.2857142857142857, NULL, '-542392.89', '1000000.12', NULL)," +
"('c1', NULL,4.0 , 0.2857142857142857, NULL, '-6.72398239210929E12', '2.823982323232357E13', NULL)," +
"(NULL, NULL, NULL, NULL, 7.0, NULL, NULL, NULL))");
"('c0', NULL, 4e0, 2.857142857142857e-1, NULL, '-542392.89', '1000000.12', NULL)," +
"('c1', NULL, 4e0, 2.857142857142857e-1, NULL, '-6.72398239210929E12', '2.823982323232357E13', NULL)," +
"(NULL, NULL, NULL, NULL, 7e0, NULL, NULL, NULL))");
}
finally {
dropTableIfExists(tmpTableName);
Expand Down Expand Up @@ -503,13 +503,13 @@ public void testCast()
// Cast to Json type.
assertQuery("SELECT cast(regionkey = 2 as JSON) FROM nation");
assertQuery("SELECT cast(size as JSON), cast(partkey as JSON), cast(brand as JSON), cast(name as JSON) FROM part");
assertQuery("SELECT cast(nationkey + 0.01 as JSON), cast(array[suppkey, nationkey] as JSON), cast(map(array[name, address, phone], array[1.1, 2.2, 3.3]) as JSON), cast(row(name, suppkey) as JSON), cast(array[map(array[name, address], array[1, 2]), map(array[name, phone], array[3, 4])] as JSON), cast(map(array[name, address, phone], array[array[1, 2], array[3, 4], array[5, 6]]) as JSON), cast(map(array[suppkey], array[name]) as JSON), cast(row(array[name, address], array[], array[null], map(array[phone], array[null])) as JSON) from supplier");
assertQuery("SELECT cast(nationkey + 1e-2 as JSON), cast(array[suppkey, nationkey] as JSON), cast(map(array[name, address, phone], array[1.1, 2.2, 3.3]) as JSON), cast(row(name, suppkey) as JSON), cast(array[map(array[name, address], array[1, 2]), map(array[name, phone], array[3, 4])] as JSON), cast(map(array[name, address, phone], array[array[1e0, 2], array[3, 4], array[5, 6]]) as JSON), cast(map(array[suppkey], array[name]) as JSON), cast(row(array[name, address], array[], array[null], map(array[phone], array[null])) as JSON) from supplier");
assertQuery("SELECT cast(orderdate as JSON) FROM orders");
assertQueryFails("SELECT cast(map(array[from_unixtime(suppkey)], array[1]) as JSON) from supplier", "Cannot cast .* to JSON");

assertQuery("SELECT try_cast(regionkey = 2 as JSON) FROM nation");
assertQuery("SELECT try_cast(size as JSON), try_cast(partkey as JSON), try_cast(brand as JSON), try_cast(name as JSON) FROM part");
assertQuery("SELECT try_cast(nationkey + 0.01 as JSON), try_cast(array[suppkey, nationkey] as JSON), try_cast(map(array[name, address, phone], array[1.1, 2.2, 3.3]) as JSON), try_cast(row(name, suppkey) as JSON), try_cast(array[map(array[name, address], array[1, 2]), map(array[name, phone], array[3, 4])] as JSON), try_cast(map(array[name, address, phone], array[array[1, 2], array[3, 4], array[5, 6]]) as JSON), try_cast(map(array[suppkey], array[name]) as JSON), try_cast(row(array[name, address], array[], array[null], map(array[phone], array[null])) as JSON) from supplier");
assertQuery("SELECT try_cast(nationkey + 1e-2 as JSON), try_cast(array[suppkey, nationkey] as JSON), try_cast(map(array[name, address, phone], array[1.1, 2.2, 3.3]) as JSON), try_cast(row(name, suppkey) as JSON), try_cast(array[map(array[name, address], array[1, 2]), map(array[name, phone], array[3, 4])] as JSON), try_cast(map(array[name, address, phone], array[array[1e0, 2], array[3, 4], array[5, 6]]) as JSON), try_cast(map(array[suppkey], array[name]) as JSON), try_cast(row(array[name, address], array[], array[null], map(array[phone], array[null])) as JSON) from supplier");
assertQuery("SELECT try_cast(orderdate as JSON) FROM orders");
assertQueryFails("SELECT try_cast(map(array[from_unixtime(suppkey)], array[1]) as JSON) from supplier", "Cannot cast .* to JSON");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public static Map<String, String> getNativeWorkerSystemProperties()
return ImmutableMap.<String, String>builder()
.put("native-execution-enabled", "true")
.put("optimizer.optimize-hash-generation", "false")
.put("parse-decimal-literals-as-double", "true")
.put("regex-library", "RE2J")
.put("offset-clause-enabled", "true")
// By default, Presto will expand some functions into its SQL equivalent (e.g. array_duplicates()).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ public static QueryRunner createJavaQueryRunner(Optional<Path> baseDataDirectory
HiveQueryRunner.createQueryRunner(
ImmutableList.of(),
ImmutableMap.of(
"parse-decimal-literals-as-double", "true",
"regex-library", "RE2J",
"offset-clause-enabled", "true"),
security,
Expand Down Expand Up @@ -228,7 +227,6 @@ public static QueryRunner createJavaIcebergQueryRunner(Optional<Path> baseDataDi

DistributedQueryRunner queryRunner = createIcebergQueryRunner(
ImmutableMap.of(
"parse-decimal-literals-as-double", "true",
"regex-library", "RE2J",
"offset-clause-enabled", "true",
"query.max-stage-count", "110"),
Expand Down

0 comments on commit 42412f4

Please sign in to comment.