From 881498946a2ad9fc67cc816cf114cb53513043d2 Mon Sep 17 00:00:00 2001 From: cgivre Date: Wed, 13 Nov 2024 22:55:04 -0500 Subject: [PATCH] WIP --- .../org/apache/drill/common/types/Types.java | 18 ++++----- .../logical/DrillReduceAggregatesRule.java | 4 ++ .../exec/planner/physical/AggPrelBase.java | 38 +++++++++++++++++++ .../exec/store/parquet/TestVarlenDecimal.java | 2 +- pom.xml | 2 +- 5 files changed, 52 insertions(+), 12 deletions(-) diff --git a/common/src/main/java/org/apache/drill/common/types/Types.java b/common/src/main/java/org/apache/drill/common/types/Types.java index 4f152fd30b1..1b36409d17f 100644 --- a/common/src/main/java/org/apache/drill/common/types/Types.java +++ b/common/src/main/java/org/apache/drill/common/types/Types.java @@ -17,19 +17,18 @@ */ package org.apache.drill.common.types; -import static org.apache.drill.common.types.TypeProtos.DataMode.REPEATED; +import com.google.protobuf.TextFormat; +import org.apache.drill.common.exceptions.DrillRuntimeException; +import org.apache.drill.common.types.TypeProtos.DataMode; +import org.apache.drill.common.types.TypeProtos.MajorType; +import org.apache.drill.common.types.TypeProtos.MinorType; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.apache.drill.common.exceptions.DrillRuntimeException; -import org.apache.drill.common.types.TypeProtos.DataMode; -import org.apache.drill.common.types.TypeProtos.MajorType; -import org.apache.drill.common.types.TypeProtos.MinorType; - -import com.google.protobuf.TextFormat; +import static org.apache.drill.common.types.TypeProtos.DataMode.REPEATED; public class Types { private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Types.class); @@ -816,7 +815,7 @@ public static MajorType.Builder calculateTypePrecisionAndScale(MajorType leftTyp return typeBuilder.setPrecision(Math.max(leftType.getPrecision(), rightType.getPrecision())); } - MinorType minorType = leftType.getMinorType(); + MinorType minorType = leftType.getMinorType();s if (isDecimalType(leftType)) { int scale = Math.max(leftType.getScale(), rightType.getScale()); // resulting precision should take into account resulting scale value and be calculated as @@ -936,11 +935,10 @@ public static int maxPrecision(MinorType type) { return 28; case DECIMAL38DENSE: case DECIMAL38SPARSE: + case VARDECIMAL: return 38; case DECIMAL9: return 9; - case VARDECIMAL: - return 38; default: return 0; } diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillReduceAggregatesRule.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillReduceAggregatesRule.java index 1b67da275a8..0dfe35ca5c9 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillReduceAggregatesRule.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillReduceAggregatesRule.java @@ -419,6 +419,7 @@ private static AggregateCall getAggCall(AggregateCall oldCall, oldCall.isDistinct(), oldCall.isApproximate(), oldCall.ignoreNulls(), + oldCall.rexList, oldCall.getArgList(), oldCall.filterArg, oldCall.distinctKeys, @@ -541,6 +542,7 @@ private RexNode reduceStddev( oldCall.isDistinct(), oldCall.isApproximate(), oldCall.ignoreNulls(), + oldCall.rexList, ImmutableIntList.of(argSquaredOrdinal), oldCall.filterArg, oldCall.distinctKeys, @@ -562,6 +564,7 @@ private RexNode reduceStddev( oldCall.isDistinct(), oldCall.isApproximate(), oldCall.ignoreNulls(), + oldCall.rexList, ImmutableIntList.of(argOrdinal), oldCall.filterArg, oldCall.distinctKeys, @@ -739,6 +742,7 @@ public void onMatch(RelOptRuleCall call) { oldAggregateCall.isDistinct(), oldAggregateCall.isApproximate(), oldAggregateCall.ignoreNulls(), + oldAggregateCall.rexList, oldAggregateCall.getArgList(), oldAggregateCall.filterArg, oldAggregateCall.distinctKeys, diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/AggPrelBase.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/AggPrelBase.java index ed236f7cdab..f15b0791774 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/AggPrelBase.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/AggPrelBase.java @@ -17,6 +17,7 @@ */ package org.apache.drill.exec.planner.physical; +import com.google.common.collect.ImmutableList; import org.apache.drill.common.expression.IfExpression; import org.apache.drill.common.expression.NullExpression; import com.google.common.collect.Lists; @@ -179,6 +180,7 @@ protected void createKeysAndExprs() { aggCall.e.isDistinct(), aggCall.e.isApproximate(), false, + ImmutableList.of(), Collections.singletonList(aggExprOrdinal), aggCall.e.filterArg, null, @@ -186,6 +188,40 @@ protected void createKeysAndExprs() { aggCall.e.getType(), aggCall.e.getName()); + /* + SqlAggFunction aggFunction, + boolean distinct, + boolean approximate, + boolean ignoreNulls, + List argList, + int filterArg, + @Nullable ImmutableBitSet distinctKeys, + RelCollation collation, + RelDataType type, + @Nullable String name + +SqlAggFunction aggFunction, + boolean distinct, + boolean approximate, + boolean ignoreNulls, + List rexList, + List argList, + int filterArg, + @Nullable ImmutableBitSet distinctKeys, RelCollation collation, + RelDataType type, @Nullable String name + + public static AggregateCall create(SqlAggFunction aggFunction, boolean distinct, boolean approximate, boolean ignoreNulls, + List argList, int filterArg, + @Nullable ImmutableBitSet distinctKeys, RelCollation collation, + RelDataType type, @Nullable String name) { + final boolean distinct2 = distinct + && (aggFunction.getDistinctOptionality() != Optionality.IGNORED); + return new AggregateCall(aggFunction, distinct2, approximate, ignoreNulls, + argList, filterArg, distinctKeys, collation, type, name); + } + + */ + phase2AggCallList.add(newAggCall); } else { AggregateCall newAggCall = @@ -194,6 +230,7 @@ protected void createKeysAndExprs() { aggCall.e.isDistinct(), aggCall.e.isApproximate(), false, + ImmutableList.of(), Collections.singletonList(aggExprOrdinal), aggCall.e.filterArg, null, @@ -270,6 +307,7 @@ public Prel prepareForLateralUnnestPipeline(List children) { aggCall.isDistinct(), aggCall.isApproximate(), false, + ImmutableList.of(), arglist, aggCall.filterArg, null, diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestVarlenDecimal.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestVarlenDecimal.java index 61f8e4df872..5397e810477 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestVarlenDecimal.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestVarlenDecimal.java @@ -197,7 +197,7 @@ public void testWideningLimit() throws Exception { // A union of VARDECIMALs that requires a widening to an unsupported // DECIMAL(40, 6). The resulting column should be limited DECIMAL(38, 6) // and a precision loss warning logged. - String query = "SELECT CAST(10 AS DECIMAL(38, 4)) AS `Col1` " + + String query = "SELECT CAST('10' AS DECIMAL(38, 4)) AS `Col1` " + "UNION ALL " + "SELECT CAST(22 AS DECIMAL(29, 6)) AS `Col1`"; diff --git a/pom.xml b/pom.xml index 460376d6536..6a933b7281d 100644 --- a/pom.xml +++ b/pom.xml @@ -56,7 +56,7 @@ 1.11.4 1.78.1 org.apache.calcite - 1.34.0 + 1.35.0 2.6 1.9.4 1.4