Skip to content

Commit 0ca1f3f

Browse files
committed
WIP
1 parent f4b20ec commit 0ca1f3f

File tree

4 files changed

+16
-29
lines changed

4 files changed

+16
-29
lines changed

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

+14-9
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@
1717
*/
1818
package org.apache.drill.exec.planner.sql;
1919

20-
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
2120
import com.google.common.collect.ImmutableMap;
2221
import com.google.common.collect.ImmutableSet;
2322
import com.google.common.collect.Lists;
24-
import org.slf4j.Logger;
25-
import org.slf4j.LoggerFactory;
2623
import org.apache.calcite.avatica.util.TimeUnit;
2724
import org.apache.calcite.rel.type.RelDataType;
2825
import org.apache.calcite.rel.type.RelDataTypeFactory;
@@ -35,17 +32,18 @@
3532
import org.apache.calcite.sql.SqlNode;
3633
import org.apache.calcite.sql.SqlNumericLiteral;
3734
import org.apache.calcite.sql.SqlOperatorBinding;
35+
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
3836
import org.apache.calcite.sql.parser.SqlParserPos;
3937
import org.apache.calcite.sql.type.SqlReturnTypeInference;
4038
import org.apache.calcite.sql.type.SqlTypeFamily;
4139
import org.apache.calcite.sql.type.SqlTypeName;
42-
40+
import org.apache.calcite.util.NlsString;
41+
import org.apache.drill.common.exceptions.UserException;
4342
import org.apache.drill.common.expression.ExpressionPosition;
4443
import org.apache.drill.common.expression.FunctionCall;
4544
import org.apache.drill.common.expression.FunctionCallFactory;
4645
import org.apache.drill.common.expression.LogicalExpression;
4746
import org.apache.drill.common.expression.MajorTypeInLogicalExpression;
48-
import org.apache.drill.common.exceptions.UserException;
4947
import org.apache.drill.common.types.TypeProtos;
5048
import org.apache.drill.common.types.Types;
5149
import org.apache.drill.exec.expr.annotations.FunctionTemplate;
@@ -54,6 +52,8 @@
5452
import org.apache.drill.exec.resolver.FunctionResolver;
5553
import org.apache.drill.exec.resolver.FunctionResolverFactory;
5654
import org.apache.drill.exec.resolver.TypeCastRules;
55+
import org.slf4j.Logger;
56+
import org.slf4j.LoggerFactory;
5757

5858
import java.util.List;
5959
import java.util.Optional;
@@ -744,7 +744,7 @@ public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
744744
}
745745

746746
final String part = ((SqlCharStringLiteral) ((SqlCallBinding) opBinding).operand(0))
747-
.getNlsString()
747+
.getValueAs(NlsString.class)
748748
.getValue()
749749
.toUpperCase();
750750

@@ -1023,14 +1023,19 @@ public static RelDataType createCalciteTypeWithNullability(RelDataTypeFactory ty
10231023
public static RelDataType convertToCalciteType(RelDataTypeFactory typeFactory,
10241024
TypeProtos.MajorType drillType, boolean isNullable) {
10251025
SqlTypeName sqlTypeName = getCalciteTypeFromDrillType(drillType.getMinorType());
1026+
int precision;
1027+
int scale;
1028+
10261029
switch (sqlTypeName) {
10271030
case DECIMAL:
1031+
precision = drillType.getPrecision();
1032+
scale = drillType.getScale();
10281033
return typeFactory.createTypeWithNullability(
1029-
typeFactory.createSqlType(sqlTypeName, drillType.getPrecision(),
1030-
drillType.getScale()), isNullable);
1034+
typeFactory.createSqlType(sqlTypeName, precision,
1035+
scale), isNullable);
10311036
case TIME:
10321037
case TIMESTAMP:
1033-
int precision = drillType.hasPrecision()
1038+
precision = drillType.hasPrecision()
10341039
? drillType.getPrecision()
10351040
: typeFactory.getTypeSystem().getDefaultPrecision(sqlTypeName);
10361041
return typeFactory.createTypeWithNullability(

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public RexNode makeCast(RelDataType type, RexNode exp) {
7373
BigDecimal bigDecimal = (BigDecimal) value;
7474
DecimalUtility.checkValueOverflow(bigDecimal, precision, scale);
7575
if (bigDecimal.precision() != precision || bigDecimal.scale() != scale) {
76-
return makeAbstractCast(type, exp);
76+
return makeAbstractCast(type, exp, false);
7777
}
7878
}
7979
}

exec/vector/src/main/java/org/apache/drill/exec/util/DecimalUtility.java

-18
Original file line numberDiff line numberDiff line change
@@ -451,22 +451,4 @@ public static void checkValueOverflow(BigDecimal value, int desiredPrecision, in
451451
.build(logger);
452452
}
453453
}
454-
455-
/**
456-
* Ensures that a BigDecimal value conforms to the specified precision and scale.
457-
*
458-
* @param value the BigDecimal to be adjusted
459-
* @param precision the desired precision
460-
* @param scale the desired scale
461-
* @return the adjusted BigDecimal value
462-
*/
463-
public static BigDecimal enforcePrecisionAndScale(BigDecimal value, int precision, int scale) {
464-
// Log values being checked
465-
logger.debug("Adjusting value: {}, desired precision: {}, desired scale: {}", value, precision, scale);
466-
if (value.precision() > precision) {
467-
throw new IllegalArgumentException("Precision overflow: value = " + value);
468-
}
469-
return value.setScale(scale, RoundingMode.HALF_UP);
470-
}
471-
472454
}

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<aircompressor.version>0.25</aircompressor.version>
5353
<antlr.version>4.9.3</antlr.version>
5454
<asm.version>9.5</asm.version>
55-
<avatica.version>1.23.0</avatica.version>
55+
<avatica.version>1.26.0</avatica.version>
5656
<avro.version>1.11.4</avro.version>
5757
<bouncycastle.version>1.78.1</bouncycastle.version>
5858
<caffeine.version>2.9.3</caffeine.version>

0 commit comments

Comments
 (0)