Skip to content

Commit

Permalink
More explicit error for decorrelation
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangfu0 committed Aug 8, 2023
1 parent 7b530d2 commit cc4e26d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,12 @@ protected RelRoot compileQuery(SqlNode sqlNode, PlannerContext plannerContext)

private RelRoot decorrelateIfNeeded(RelRoot relRoot) {
if (hasCorrelateNode(relRoot.rel)) {
relRoot = relRoot.withRel(RelDecorrelator.decorrelateQuery(relRoot.rel, RelBuilder.create(_config)));
try {
relRoot = relRoot.withRel(RelDecorrelator.decorrelateQuery(relRoot.rel, RelBuilder.create(_config)));
} catch (Throwable e) {
throw new UnsupportedOperationException(
"Failed to de-correlate the given query to a valid execution plan: " + RelOptUtil.toString(relRoot.rel), e);
}
}
return relRoot;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,8 @@ public RelDataType deriveSumType(RelDataTypeFactory typeFactory,
case BIGINT:
return typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
argumentType.isNullable());
case FLOAT:
case DOUBLE:
return typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE),
argumentType.isNullable());
default:
return super.deriveSumType(typeFactory, argumentType);
return argumentType;
}
}
}
13 changes: 11 additions & 2 deletions pinot-query-planner/src/test/resources/queries/JoinPlans.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@
"\n PinotLogicalExchange(distribution=[hash[0, 1]])",
"\n LogicalTableScan(table=[[a]])",
"\n PinotLogicalExchange(distribution=[hash[0, 1]])",
"\n LogicalProject(col1=[$0], col2=[$1], EXPR$0=[$2], col10=[CAST($0):VARCHAR], col20=[CAST($1):VARCHAR], EXPR$05=[CAST($2):DECIMAL(1000, 1)])",
"\n LogicalProject(col1=[$0], col2=[$1], EXPR$0=[$2], col10=[CAST($0):VARCHAR], col20=[CAST($1):VARCHAR], EXPR$05=[CAST($2):DECIMAL(12, 1)])",
"\n LogicalAggregate(group=[{0, 1}], agg#0=[$SUM0($2)])",
"\n PinotLogicalExchange(distribution=[hash[0, 1]])",
"\n LogicalAggregate(group=[{0, 1}], agg#0=[$SUM0($2)])",
Expand All @@ -358,7 +358,7 @@
"\n PinotLogicalExchange(distribution=[hash[0, 1]])",
"\n LogicalTableScan(table=[[a]])",
"\n PinotLogicalExchange(distribution=[hash[0, 1]])",
"\n LogicalProject(col1=[$0], col2=[$1], EXPR$0=[CAST(/(CAST($2):DECIMAL(12, 1) NOT NULL, $3)):DECIMAL(12, 1) NOT NULL], col10=[CAST($0):VARCHAR], col20=[CAST($1):VARCHAR], EXPR$05=[CAST(CAST(/(CAST($2):DECIMAL(12, 1) NOT NULL, $3)):DECIMAL(12, 1) NOT NULL):DECIMAL(12, 1)])",
"\n LogicalProject(col1=[$0], col2=[$1], EXPR$0=[CAST(/($2, $3)):DECIMAL(12, 1) NOT NULL], col10=[CAST($0):VARCHAR], col20=[CAST($1):VARCHAR], EXPR$05=[CAST(CAST(/($2, $3)):DECIMAL(12, 1) NOT NULL):DECIMAL(12, 1)])",
"\n LogicalAggregate(group=[{0, 1}], agg#0=[$SUM0($2)], agg#1=[COUNT($3)])",
"\n PinotLogicalExchange(distribution=[hash[0, 1]])",
"\n LogicalAggregate(group=[{0, 1}], agg#0=[$SUM0($2)], agg#1=[COUNT()])",
Expand Down Expand Up @@ -413,5 +413,14 @@
"expectedException": "Error explain query plan for.*"
}
]
},
"failed_to_decorrelate_due_to_type_mismatch": {
"queries": [
{
"description": "Decorrelation failed due to DECIMAL type mismatch",
"sql": "EXPLAIN PLAN FOR SELECT a.col1 FROM a WHERE a.col4 > (SELECT 0.5 * SUM(b.col3) FROM b WHERE b.col1 = a.col1)",
"expectedException": "Error explain query plan for.*"
}
]
}
}

0 comments on commit cc4e26d

Please sign in to comment.