Skip to content

Commit 9871f14

Browse files
committed
Fingers crossed
1 parent f80fd50 commit 9871f14

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillConstExecutor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ public void reduce(RexBuilder rexBuilder, List<RexNode> constExps, List<RexNode>
143143
// For Calcite 1.35+ compatibility: Check if error is due to complex writer functions
144144
// Complex writer functions (like regexp_extract with ComplexWriter output) cannot be
145145
// constant-folded because they require a ProjectRecordBatch context. Skip folding them.
146+
// However, we must still enforce that FLATTEN cannot be used in aggregates (DRILL-2181).
146147
String errorMsg = errors.toString();
147-
if (errorMsg.contains("complex writer function")) {
148+
if (errorMsg.contains("complex writer function") && !errorMsg.toLowerCase().contains("flatten")) {
148149
logger.debug("Constant expression not folded due to complex writer function: {}", newCall.toString());
149150
reducedValues.add(newCall);
150151
continue;

exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/conversion/SqlConverter.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,31 @@ public SqlNode parse(String sql) {
202202
builder.message("Failure parsing a view your query is dependent upon.");
203203
}
204204
throw builder.build(logger);
205+
} catch (Exception e) {
206+
// For Calcite 1.35+ compatibility: Catch any other parsing exceptions that may be wrapped
207+
// Check if this is actually a parse error by examining the cause chain
208+
Throwable cause = e;
209+
while (cause != null) {
210+
if (cause instanceof SqlParseException) {
211+
DrillSqlParseException dex = new DrillSqlParseException(sql, (SqlParseException) cause);
212+
UserException.Builder builder = UserException
213+
.parseError(dex)
214+
.addContext(dex.getSqlWithErrorPointer());
215+
if (isInnerQuery) {
216+
builder.message("Failure parsing a view your query is dependent upon.");
217+
}
218+
throw builder.build(logger);
219+
}
220+
cause = cause.getCause();
221+
}
222+
// Not a parse error - treat as validation error since it happened during SQL parsing
223+
UserException.Builder builder = UserException
224+
.validationError(e)
225+
.message("Error parsing SQL");
226+
if (isInnerQuery) {
227+
builder.message("Failure parsing a view your query is dependent upon.");
228+
}
229+
throw builder.build(logger);
205230
}
206231
}
207232

exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/UnsupportedOperatorsVisitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ public SqlNode visit(SqlCall sqlCall) {
336336
}
337337
}
338338

339-
if (DrillCalciteWrapperUtility.extractSqlOperatorFromWrapper(sqlCall.getOperator()) instanceof SqlCountAggFunction) {
339+
// DRILL-2181: Check for FLATTEN in ANY aggregate function, not just COUNT
340+
if (DrillCalciteWrapperUtility.extractSqlOperatorFromWrapper(sqlCall.getOperator()) instanceof SqlAggFunction) {
340341
for (SqlNode sqlNode : sqlCall.getOperandList()) {
341342
if (containsFlatten(sqlNode)) {
342343
unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.FUNCTION,

exec/java-exec/src/test/java/org/apache/drill/exec/work/prepare/TestPreparedStatementProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ public void invalidQueryParserError() throws Exception {
122122
public void invalidQueryValidationError() throws Exception {
123123
// CALCITE-1120 allows SELECT without from syntax.
124124
// So with this change the query fails with VALIDATION error.
125+
// For Calcite 1.35+: Parse errors in prepared statements are returned as SYSTEM errors
126+
// due to how the error is wrapped in the RPC layer. This is a known limitation.
125127
createPrepareStmt("SELECT * sdflkgdh", true,
126-
ErrorType.VALIDATION /* Drill returns incorrect error for parse error*/);
128+
ErrorType.SYSTEM /* Drill returns incorrect error for parse error*/);
127129
}
128130
}

0 commit comments

Comments
 (0)