[
https://issues.apache.org/jira/browse/DRILL-3962?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18030440#comment-18030440
]
ASF GitHub Bot commented on DRILL-3962:
---------------------------------------
cgivre commented on code in PR #3026:
URL: https://github.com/apache/drill/pull/3026#discussion_r2437171439
##########
exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/union/UnionAllRecordBatch.java:
##########
@@ -301,14 +305,32 @@ private void inferOutputFieldsBothSide(final BatchSchema
leftSchema, final Batch
builder.setMinorType(leftField.getType().getMinorType());
builder = Types.calculateTypePrecisionAndScale(leftField.getType(),
rightField.getType(), builder);
} else {
- TypeProtos.MinorType outputMinorType =
TypeCastRules.getLeastRestrictiveType(
- leftField.getType().getMinorType(),
- rightField.getType().getMinorType()
- );
- if (outputMinorType == null) {
- throw new DrillRuntimeException("Type mismatch between " +
leftField.getType().getMinorType().toString() +
- " on the left side and " +
rightField.getType().getMinorType().toString() +
- " on the right side in column " + index + " of UNION ALL");
+ TypeProtos.MinorType leftType = leftField.getType().getMinorType();
+ TypeProtos.MinorType rightType = rightField.getType().getMinorType();
+ TypeProtos.MinorType outputMinorType;
+
+ // Special handling for GROUPING SETS expansion:
+ // When unioning different grouping sets, NULL columns are
represented as INT (Drill's default).
+ // If one side is INT and the other is not, prefer the non-INT type
since INT is likely a NULL placeholder.
+ if (popConfig.isGroupingSetsExpansion() &&
+ leftType == TypeProtos.MinorType.INT && rightType !=
TypeProtos.MinorType.INT) {
+ // Left is INT (likely NULL placeholder), right is actual data -
prefer right type
+ outputMinorType = rightType;
+ logger.debug("GROUPING SETS: Preferring {} over INT for column
{}", rightType, index);
+ } else if (popConfig.isGroupingSetsExpansion() &&
+ rightType == TypeProtos.MinorType.INT && leftType !=
TypeProtos.MinorType.INT) {
+ // Right is INT (likely NULL placeholder), left is actual data -
prefer left type
+ outputMinorType = leftType;
+ logger.debug("GROUPING SETS: Preferring {} over INT for column
{}", leftType, index);
+ } else {
+ // Normal case: use standard type cast rules
+ outputMinorType = TypeCastRules.getLeastRestrictiveType(leftType,
rightType);
+ if (outputMinorType == null) {
+ throw new DrillRuntimeException("Type mismatch between " +
leftType.toString() +
+ " on the left side and " + rightType.toString() +
+ " on the right side in column " + index + " of UNION ALL");
+ }
+ logger.debug("Using standard type rules: {} + {} -> {}", leftType,
rightType, outputMinorType);
Review Comment:
Fixed.
> Add support of ROLLUP, CUBE, GROUPING SETS, GROUPING, GROUPING_ID, GROUP_ID
> support
> -----------------------------------------------------------------------------------
>
> Key: DRILL-3962
> URL: https://issues.apache.org/jira/browse/DRILL-3962
> Project: Apache Drill
> Issue Type: New Feature
> Reporter: Jinfeng Ni
> Assignee: Charles Givre
> Priority: Major
>
> These functions are important for BI analytical workload. Currently, Calcite
> supports those functions, but neither the planning or execution in Drill
> supports those functions.
> DRILL-3802 blocks those functions in Drill planning. But we should provide
> the support for those functions in both planning and execution of Drill.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)