Skip to content

Commit

Permalink
fix(iceberg): Date partition value parse issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nmahadevuni committed Feb 20, 2025
1 parent a766a3a commit 6d88a9e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1409,12 +1409,18 @@ IcebergPrestoToVeloxConnector::toVeloxColumnHandle(
// TODO(imjalpreet): Modify 'hiveType' argument of the 'HiveColumnHandle'
// constructor similar to how Hive Connector is handling for bucketing
velox::type::fbhive::HiveTypeParser hiveTypeParser;
auto type = stringToType(icebergColumn->type, typeParser);
connector::hive::HiveColumnHandle::ColumnParseParameters columnParseParameters;
if (type->isDate()) {
columnParseParameters.partitionDateValueFormat = connector::hive::HiveColumnHandle::ColumnParseParameters::kDaysSinceEpoch;
}
return std::make_unique<connector::hive::HiveColumnHandle>(
icebergColumn->columnIdentity.name,
toHiveColumnType(icebergColumn->columnType),
stringToType(icebergColumn->type, typeParser),
stringToType(icebergColumn->type, typeParser),
toRequiredSubfields(icebergColumn->requiredSubfields));
type,
type,
toRequiredSubfields(icebergColumn->requiredSubfields),
columnParseParameters);
}

std::unique_ptr<velox::connector::ConnectorTableHandle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,24 @@ protected ExpectedQueryRunner createExpectedQueryRunner()
@Override
protected void createTables()
{
createTableToTestHiddenColumns();
createTestTables();
}

private void createTableToTestHiddenColumns()
private void createTestTables()
{
QueryRunner javaQueryRunner = ((QueryRunner) getExpectedQueryRunner());
if (!javaQueryRunner.tableExists(getSession(), "test_hidden_columns")) {
javaQueryRunner.execute("CREATE TABLE test_hidden_columns AS SELECT * FROM tpch.tiny.region WHERE regionkey=0");
javaQueryRunner.execute("INSERT INTO test_hidden_columns SELECT * FROM tpch.tiny.region WHERE regionkey=1");
}

javaQueryRunner.execute("DROP TABLE IF EXISTS test_hidden_columns");
javaQueryRunner.execute("CREATE TABLE test_hidden_columns AS SELECT * FROM tpch.tiny.region WHERE regionkey=0");
javaQueryRunner.execute("INSERT INTO test_hidden_columns SELECT * FROM tpch.tiny.region WHERE regionkey=1");

javaQueryRunner.execute("DROP TABLE IF EXISTS ice_table_partitioned");
javaQueryRunner.execute("CREATE TABLE ice_table_partitioned(c1 INT, ds DATE) WITH (partitioning = ARRAY['ds'])");
javaQueryRunner.execute("INSERT INTO ice_table_partitioned VALUES(1, date'2022-04-09'), (2, date'2022-03-18'), (3, date'1993-01-01')");

javaQueryRunner.execute("DROP TABLE IF EXISTS ice_table");
javaQueryRunner.execute("CREATE TABLE ice_table(c1 INT, ds DATE)");
javaQueryRunner.execute("INSERT INTO ice_table VALUES(1, date'2022-04-09'), (2, date'2022-03-18'), (3, date'1993-01-01')");
}

@Test
Expand Down Expand Up @@ -94,4 +102,11 @@ public void testDataSequenceNumberHiddenColumn()
.getOnlyValue(),
0L);
}

@Test
public void testDateQueries()
{
assertQuery("SELECT * FROM ice_table_partitioned WHERE ds >= date'1994-01-01'", "VALUES (1, date'2022-04-09'), (2, date'2022-03-18')");
assertQuery("SELECT * FROM ice_table WHERE ds = date'2022-04-09'", "VALUES (1, date'2022-04-09')");
}
}

0 comments on commit 6d88a9e

Please sign in to comment.