-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Draft] Add support to filter out plans that use Timestamp with Timezone #23179
Draft
kgpai
wants to merge
1
commit into
prestodb:master
Choose a base branch
from
kgpai:filter_out_timestamp_tz
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
// clang-format off | ||
#include "presto_cpp/main/types/PrestoToVeloxConnector.h" | ||
#include "presto_cpp/main/types/PrestoToVeloxQueryPlan.h" | ||
#include "presto_cpp/main/common/Configs.h" | ||
#include <velox/type/Filter.h> | ||
#include "velox/core/QueryCtx.h" | ||
#include "velox/exec/HashPartitionFunction.h" | ||
|
@@ -23,6 +24,10 @@ | |
#include "velox/vector/ComplexVector.h" | ||
#include "velox/vector/FlatVector.h" | ||
#include "velox/core/Expressions.h" | ||
#include "velox/connectors/hive/TableHandle.h" | ||
#include "velox/core/ITypedExpr.h" | ||
#include "velox/functions/prestosql/types/TimestampWithTimeZoneType.h" | ||
|
||
// clang-format on | ||
|
||
#include <folly/String.h> | ||
|
@@ -1756,7 +1761,7 @@ protocol::PlanNodeId toPartitionedOutputNodeId(const protocol::PlanNodeId& id) { | |
|
||
} // namespace | ||
|
||
core::PlanFragment VeloxQueryPlanConverterBase::toVeloxQueryPlan( | ||
core::PlanFragment VeloxQueryPlanConverterBase::toVeloxQueryPlanImpl( | ||
const protocol::PlanFragment& fragment, | ||
const std::shared_ptr<protocol::TableWriteInfo>& tableWriteInfo, | ||
const protocol::TaskId& taskId) { | ||
|
@@ -1924,6 +1929,124 @@ core::PlanFragment VeloxQueryPlanConverterBase::toVeloxQueryPlan( | |
return planFragment; | ||
} | ||
|
||
namespace { | ||
|
||
bool rowHasTimestampWithTz(const RowTypePtr row) { | ||
for (auto child : row->children()) { | ||
if (isTimestampWithTimeZoneType(child)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool exprHasTimestampWithTz(const std::vector<core::TypedExprPtr>& exprs) { | ||
for (auto expr : exprs) { | ||
if (isTimestampWithTimeZoneType(expr->type())) { | ||
return true; | ||
} | ||
if (exprHasTimestampWithTz(expr->inputs())) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} // namespace | ||
|
||
bool planHasTimestampWithTimeZone(const core::PlanNodePtr planNode) { | ||
// Do output types have timestamp with tz ? | ||
if (rowHasTimestampWithTz(planNode->outputType())) { | ||
return true; | ||
} | ||
|
||
// Is it a projectNode with timestamp with tz ? | ||
if (auto projectNode = | ||
std::dynamic_pointer_cast<const core::ProjectNode>(planNode)) { | ||
if (!projectNode->projections().empty() && | ||
exprHasTimestampWithTz(projectNode->projections())) { | ||
return true; | ||
} | ||
} | ||
|
||
// Is it a filterNode with timestamp with tz ? | ||
if (auto filterNode = | ||
std::dynamic_pointer_cast<const core::FilterNode>(planNode)) { | ||
if (filterNode->filter() && | ||
exprHasTimestampWithTz({filterNode->filter()})) { | ||
return true; | ||
} | ||
} | ||
|
||
// Is it one of the joinNodes with timestamp with tz ? | ||
if (auto joinNode = | ||
std::dynamic_pointer_cast<const core::AbstractJoinNode>(planNode)) { | ||
if (joinNode->filter() && exprHasTimestampWithTz({joinNode->filter()})) { | ||
return true; | ||
} | ||
} | ||
|
||
if (auto joinNode = | ||
std::dynamic_pointer_cast<const core::NestedLoopJoinNode>(planNode)) { | ||
if (joinNode->joinCondition() && | ||
exprHasTimestampWithTz({joinNode->joinCondition()})) { | ||
return true; | ||
} | ||
} | ||
|
||
// Does aggregation use timestamp with tz ? | ||
if (auto aggNode = | ||
std::dynamic_pointer_cast<const core::AggregationNode>(planNode)) { | ||
for (auto agg : aggNode->aggregates()) { | ||
if (agg.call && | ||
(agg.call->type() && isTimestampWithTimeZoneType(agg.call->type()) || | ||
exprHasTimestampWithTz(agg.call->inputs()))) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
// Is it tablescan with remaining filter ? | ||
if (auto tableScanNode = | ||
std::dynamic_pointer_cast<const core::TableScanNode>(planNode)) { | ||
if (auto hiveTableHandle = | ||
std::dynamic_pointer_cast<connector::hive::HiveTableHandle>( | ||
tableScanNode->tableHandle())) { | ||
if (hiveTableHandle->remainingFilter() && | ||
exprHasTimestampWithTz({hiveTableHandle->remainingFilter()})) { | ||
return true; | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AggregationNode::aggregates_::call is a CallTypedExprPtr that can contain a LambdaTypedExprPtr as input. Should we check it too? |
||
|
||
// Do source plans have timestamp with tz ? | ||
for (auto plan : planNode->sources()) { | ||
if (planHasTimestampWithTimeZone(plan)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
core::PlanFragment VeloxQueryPlanConverterBase::toVeloxQueryPlan( | ||
const protocol::PlanFragment& fragment, | ||
const std::shared_ptr<protocol::TableWriteInfo>& tableWriteInfo, | ||
const protocol::TaskId& taskId) { | ||
auto planFragment = toVeloxQueryPlanImpl(fragment, tableWriteInfo, taskId); | ||
|
||
if (SystemConfig::instance() | ||
->optionalProperty<bool>(kFailOnTimestampWithTimezone) | ||
.value_or(false)) { | ||
VELOX_CHECK( | ||
!planHasTimestampWithTimeZone(planFragment.planNode), | ||
"Plan uses Timestamp with Timezone"); | ||
} | ||
return planFragment; | ||
} | ||
|
||
core::PlanNodePtr VeloxQueryPlanConverterBase::toVeloxQueryPlan( | ||
const std::shared_ptr<const protocol::OutputNode>& node, | ||
const std::shared_ptr<protocol::TableWriteInfo>& tableWriteInfo, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can AbstractJoinNode be used standalone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would cover both HashJoin and MergeJoin.