Skip to content

Commit c14f8b4

Browse files
nmahadevuniaditi-pandit
authored andcommitted
fix(iceberg): Date partition value parse issue
1 parent 8485839 commit c14f8b4

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

presto-native-execution/presto_cpp/main/types/PrestoToVeloxConnector.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -1409,12 +1409,18 @@ IcebergPrestoToVeloxConnector::toVeloxColumnHandle(
14091409
// TODO(imjalpreet): Modify 'hiveType' argument of the 'HiveColumnHandle'
14101410
// constructor similar to how Hive Connector is handling for bucketing
14111411
velox::type::fbhive::HiveTypeParser hiveTypeParser;
1412+
auto type = stringToType(icebergColumn->type, typeParser);
1413+
connector::hive::HiveColumnHandle::ColumnParseParameters columnParseParameters;
1414+
if (type->isDate()) {
1415+
columnParseParameters.partitionDateValueFormat = connector::hive::HiveColumnHandle::ColumnParseParameters::kDaysSinceEpoch;
1416+
}
14121417
return std::make_unique<connector::hive::HiveColumnHandle>(
14131418
icebergColumn->columnIdentity.name,
14141419
toHiveColumnType(icebergColumn->columnType),
1415-
stringToType(icebergColumn->type, typeParser),
1416-
stringToType(icebergColumn->type, typeParser),
1417-
toRequiredSubfields(icebergColumn->requiredSubfields));
1420+
type,
1421+
type,
1422+
toRequiredSubfields(icebergColumn->requiredSubfields),
1423+
columnParseParameters);
14181424
}
14191425

14201426
std::unique_ptr<velox::connector::ConnectorTableHandle>

presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestPrestoNativeIcebergGeneralQueries.java

+21-6
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,24 @@ protected ExpectedQueryRunner createExpectedQueryRunner()
4141
@Override
4242
protected void createTables()
4343
{
44-
createTableToTestHiddenColumns();
44+
createTestTables();
4545
}
4646

47-
private void createTableToTestHiddenColumns()
47+
private void createTestTables()
4848
{
4949
QueryRunner javaQueryRunner = ((QueryRunner) getExpectedQueryRunner());
50-
if (!javaQueryRunner.tableExists(getSession(), "test_hidden_columns")) {
51-
javaQueryRunner.execute("CREATE TABLE test_hidden_columns AS SELECT * FROM tpch.tiny.region WHERE regionkey=0");
52-
javaQueryRunner.execute("INSERT INTO test_hidden_columns SELECT * FROM tpch.tiny.region WHERE regionkey=1");
53-
}
50+
51+
javaQueryRunner.execute("DROP TABLE IF EXISTS test_hidden_columns");
52+
javaQueryRunner.execute("CREATE TABLE test_hidden_columns AS SELECT * FROM tpch.tiny.region WHERE regionkey=0");
53+
javaQueryRunner.execute("INSERT INTO test_hidden_columns SELECT * FROM tpch.tiny.region WHERE regionkey=1");
54+
55+
javaQueryRunner.execute("DROP TABLE IF EXISTS ice_table_partitioned");
56+
javaQueryRunner.execute("CREATE TABLE ice_table_partitioned(c1 INT, ds DATE) WITH (partitioning = ARRAY['ds'])");
57+
javaQueryRunner.execute("INSERT INTO ice_table_partitioned VALUES(1, date'2022-04-09'), (2, date'2022-03-18'), (3, date'1993-01-01')");
58+
59+
javaQueryRunner.execute("DROP TABLE IF EXISTS ice_table");
60+
javaQueryRunner.execute("CREATE TABLE ice_table(c1 INT, ds DATE)");
61+
javaQueryRunner.execute("INSERT INTO ice_table VALUES(1, date'2022-04-09'), (2, date'2022-03-18'), (3, date'1993-01-01')");
5462
}
5563

5664
@Test
@@ -94,4 +102,11 @@ public void testDataSequenceNumberHiddenColumn()
94102
.getOnlyValue(),
95103
0L);
96104
}
105+
106+
@Test
107+
public void testDateQueries()
108+
{
109+
assertQuery("SELECT * FROM ice_table_partitioned WHERE ds >= date'1994-01-01'", "VALUES (1, date'2022-04-09'), (2, date'2022-03-18')");
110+
assertQuery("SELECT * FROM ice_table WHERE ds = date'2022-04-09'", "VALUES (1, date'2022-04-09')");
111+
}
97112
}

0 commit comments

Comments
 (0)