Skip to content

Commit

Permalink
Fix date filter
Browse files Browse the repository at this point in the history
  • Loading branch information
rui-mo committed May 27, 2024
1 parent abaf323 commit e0e9fe7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
9 changes: 9 additions & 0 deletions velox/connectors/hive/HiveConnectorUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "velox/dwio/common/Reader.h"
#include "velox/expression/Expr.h"
#include "velox/expression/ExprToSubfieldFilter.h"
#include "velox/type/TimestampConversion.h"

namespace facebook::velox::connector::hive {

Expand Down Expand Up @@ -628,6 +629,14 @@ bool testFilters(
VELOX_CHECK(handlesIter != partitionKeysHandle.end());

// This is a non-null partition key
if (handlesIter->second->dataType()->isDate()) {
const auto result = util::castFromDateString(
StringView(iter->second.value()),
util::ParseMode::kStandardCast);
VELOX_CHECK(!result.hasError());
return applyFilter(*child->filter(), result.value());
}

return applyPartitionFilter(
handlesIter->second->dataType()->kind(),
iter->second.value(),
Expand Down
32 changes: 31 additions & 1 deletion velox/exec/tests/TableScanTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,37 @@ TEST_F(TableScanTest, partitionedTableDateKey) {
auto filePath = TempFilePath::create();
writeToFile(filePath->getPath(), vectors);
createDuckDbTable(vectors);
testPartitionedTable(filePath->getPath(), DATE(), "2023-10-27");
const std::string partitionValue = "2023-10-27";
testPartitionedTable(filePath->getPath(), DATE(), partitionValue);

// Test partition filter on date column.
{
auto split = HiveConnectorSplitBuilder(filePath->getPath())
.partitionKey("pkey", partitionValue)
.build();
auto outputType = ROW({"pkey", "c0", "c1"}, {DATE(), BIGINT(), DOUBLE()});
ColumnHandleMap assignments = {
{"pkey", partitionKey("pkey", DATE())},
{"c0", regularColumn("c0", BIGINT())},
{"c1", regularColumn("c1", DOUBLE())}};

SubfieldFilters filters;
// pkey > 2020-09-01.
filters[common::Subfield("pkey")] = std::make_unique<common::BigintRange>(
18506, std::numeric_limits<int64_t>::max(), false);

auto tableHandle = std::make_shared<HiveTableHandle>(
"test-hive", "hive_table", true, std::move(filters), nullptr, nullptr);
auto op = std::make_shared<TableScanNode>(
"0",
std::move(outputType),
std::move(tableHandle),
std::move(assignments));

std::string partitionValueStr = "'" + partitionValue + "'";
assertQuery(
op, split, fmt::format("SELECT {}, * FROM tmp", partitionValueStr));
}
}

std::vector<StringView> toStringViews(const std::vector<std::string>& values) {
Expand Down

0 comments on commit e0e9fe7

Please sign in to comment.