Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cgivre committed Nov 14, 2024
1 parent 138563a commit 8814989
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 12 deletions.
18 changes: 8 additions & 10 deletions common/src/main/java/org/apache/drill/common/types/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ private static AggregateCall getAggCall(AggregateCall oldCall,
oldCall.isDistinct(),
oldCall.isApproximate(),
oldCall.ignoreNulls(),
oldCall.rexList,
oldCall.getArgList(),
oldCall.filterArg,
oldCall.distinctKeys,
Expand Down Expand Up @@ -541,6 +542,7 @@ private RexNode reduceStddev(
oldCall.isDistinct(),
oldCall.isApproximate(),
oldCall.ignoreNulls(),
oldCall.rexList,
ImmutableIntList.of(argSquaredOrdinal),
oldCall.filterArg,
oldCall.distinctKeys,
Expand All @@ -562,6 +564,7 @@ private RexNode reduceStddev(
oldCall.isDistinct(),
oldCall.isApproximate(),
oldCall.ignoreNulls(),
oldCall.rexList,
ImmutableIntList.of(argOrdinal),
oldCall.filterArg,
oldCall.distinctKeys,
Expand Down Expand Up @@ -739,6 +742,7 @@ public void onMatch(RelOptRuleCall call) {
oldAggregateCall.isDistinct(),
oldAggregateCall.isApproximate(),
oldAggregateCall.ignoreNulls(),
oldAggregateCall.rexList,
oldAggregateCall.getArgList(),
oldAggregateCall.filterArg,
oldAggregateCall.distinctKeys,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -179,13 +180,48 @@ protected void createKeysAndExprs() {
aggCall.e.isDistinct(),
aggCall.e.isApproximate(),
false,
ImmutableList.of(),
Collections.singletonList(aggExprOrdinal),
aggCall.e.filterArg,
null,
RelCollations.EMPTY,
aggCall.e.getType(),
aggCall.e.getName());

/*
SqlAggFunction aggFunction,
boolean distinct,
boolean approximate,
boolean ignoreNulls,
List<Integer> argList,
int filterArg,
@Nullable ImmutableBitSet distinctKeys,
RelCollation collation,
RelDataType type,
@Nullable String name
SqlAggFunction aggFunction,
boolean distinct,
boolean approximate,
boolean ignoreNulls,
List<RexNode> rexList,
List<Integer> 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<Integer> 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 =
Expand All @@ -194,6 +230,7 @@ protected void createKeysAndExprs() {
aggCall.e.isDistinct(),
aggCall.e.isApproximate(),
false,
ImmutableList.of(),
Collections.singletonList(aggExprOrdinal),
aggCall.e.filterArg,
null,
Expand Down Expand Up @@ -270,6 +307,7 @@ public Prel prepareForLateralUnnestPipeline(List<RelNode> children) {
aggCall.isDistinct(),
aggCall.isApproximate(),
false,
ImmutableList.of(),
arglist,
aggCall.filterArg,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`";

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<avro.version>1.11.4</avro.version>
<bouncycastle.version>1.78.1</bouncycastle.version>
<calcite.groupId>org.apache.calcite</calcite.groupId>
<calcite.version>1.34.0</calcite.version>
<calcite.version>1.35.0</calcite.version>
<codemodel.version>2.6</codemodel.version>
<commons.beanutils.version>1.9.4</commons.beanutils.version>
<commons.cli.version>1.4</commons.cli.version>
Expand Down

0 comments on commit 8814989

Please sign in to comment.