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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]