@Override public int getMaxNumericScale() { return RelDataTypeSystem.DEFAULT.getMaxNumericScale(); }
@Test public void testLegalDecimalType() { RelDataTypeSystem typeSystem = new KylinRelDataTypeSystem(); RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(typeSystem); DataType dataType = DataType.getType("decimal(30, 10)"); RelDataType relDataType = OLAPTable.createSqlType(typeFactory, dataType, true); Assert.assertTrue(relDataType instanceof BasicSqlType); Assert.assertEquals(relDataType.getSqlTypeName(), SqlTypeName.DECIMAL); Assert.assertEquals(relDataType.getPrecision(), 30); Assert.assertTrue(relDataType.getPrecision() <= typeSystem.getMaxNumericPrecision()); Assert.assertEquals(relDataType.getScale(), 10); Assert.assertTrue(relDataType.getScale() <= typeSystem.getMaxNumericScale()); }
@Test public void testIllegalDecimalType() { RelDataTypeSystem typeSystem = new KylinRelDataTypeSystem(); RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(typeSystem); DataType dataType = DataType.getType("decimal(40, 10)"); RelDataType relDataType = OLAPTable.createSqlType(typeFactory, dataType, true); Assert.assertTrue(relDataType instanceof BasicSqlType); Assert.assertEquals(relDataType.getSqlTypeName(), SqlTypeName.DECIMAL); Assert.assertTrue(typeSystem.getMaxNumericPrecision() < 40); Assert.assertEquals(relDataType.getPrecision(), typeSystem.getMaxNumericPrecision()); Assert.assertEquals(relDataType.getScale(), 10); Assert.assertTrue(relDataType.getScale() <= typeSystem.getMaxNumericScale()); } }
@Override public int getMaxNumericScale() { return RelDataTypeSystem.DEFAULT.getMaxNumericScale(); }
public int getMaxNumericScale() { return typeSystem.getMaxNumericScale(); }
public int getMaxNumericScale() { return typeSystem.getMaxNumericScale(); }
@Override public void computeScalePrecision(int leftPrecision, int leftScale, int rightPrecision, int rightScale) { // compute the output scale and precision here int maxResultIntegerDigits = Math.min(leftPrecision - leftScale + rightScale, MAX_NUMERIC_PRECISION); outputScale = Math.max(6, leftScale + rightPrecision + 1); outputScale = Math.min(outputScale, MAX_NUMERIC_PRECISION - maxResultIntegerDigits); outputScale = Math.min(outputScale, DRILL_REL_DATATYPE_SYSTEM.getMaxNumericScale()); outputPrecision = maxResultIntegerDigits + outputScale; adjustScaleAndPrecision(); } }
/** * Creates a numeric literal. */ public RexLiteral makeExactLiteral(BigDecimal bd) { RelDataType relType; int scale = bd.scale(); long l = bd.unscaledValue().longValue(); assert scale >= 0; assert scale <= typeFactory.getTypeSystem().getMaxNumericScale() : scale; assert BigDecimal.valueOf(l, scale).equals(bd); if (scale == 0) { if ((l >= Integer.MIN_VALUE) && (l <= Integer.MAX_VALUE)) { relType = typeFactory.createSqlType(SqlTypeName.INTEGER); } else { relType = typeFactory.createSqlType(SqlTypeName.BIGINT); } } else { int precision = bd.unscaledValue().abs().toString().length(); if (precision > scale) { // bd is greater than or equal to 1 relType = typeFactory.createSqlType(SqlTypeName.DECIMAL, precision, scale); } else { // bd is less than 1 relType = typeFactory.createSqlType(SqlTypeName.DECIMAL, scale + 1, scale); } } return makeExactLiteral(bd, relType); }
/** * Creates a numeric literal. */ public RexLiteral makeExactLiteral(BigDecimal bd) { RelDataType relType; int scale = bd.scale(); assert scale >= 0; assert scale <= typeFactory.getTypeSystem().getMaxNumericScale() : scale; if (scale == 0) { if (bd.compareTo(INT_MIN) >= 0 && bd.compareTo(INT_MAX) <= 0) { relType = typeFactory.createSqlType(SqlTypeName.INTEGER); } else { relType = typeFactory.createSqlType(SqlTypeName.BIGINT); } } else { int precision = bd.unscaledValue().abs().toString().length(); if (precision > scale) { // bd is greater than or equal to 1 relType = typeFactory.createSqlType(SqlTypeName.DECIMAL, precision, scale); } else { // bd is less than 1 relType = typeFactory.createSqlType(SqlTypeName.DECIMAL, scale + 1, scale); } } return makeExactLiteral(bd, relType); }
@Override public TypeProtos.MajorType getType(List<LogicalExpression> logicalExpressions, FunctionAttributes attributes) { int scale = 0; // Get the max scale and precision from the inputs for (LogicalExpression e : logicalExpressions) { scale = Math.max(scale, e.getMajorType().getScale()); } return TypeProtos.MajorType.newBuilder() .setMinorType(TypeProtos.MinorType.VARDECIMAL) .setScale(Math.min(Math.max(6, scale), DRILL_REL_DATATYPE_SYSTEM.getMaxNumericScale())) .setPrecision(DRILL_REL_DATATYPE_SYSTEM.getMaxNumericPrecision()) .setMode(TypeProtos.DataMode.OPTIONAL) .build(); } }
scale, maxNumericPrecision - dout); scale = Math.min(scale, getTypeSystem().getMaxNumericScale());
scale, maxNumericPrecision - dout); scale = Math.min(scale, getTypeSystem().getMaxNumericScale());
scale = Math.min(scale, typeSystem.getMaxNumericScale()); int precision = p1 + p2; precision =
scale = Math.min(scale, typeSystem.getMaxNumericScale()); int precision = p1 + p2; precision =
DrillRelDataTypeSystem.DRILL_REL_DATATYPE_SYSTEM.getMaxNumericPrecision(), Math.min(Math.max(6, operandType.getScale()), DrillRelDataTypeSystem.DRILL_REL_DATATYPE_SYSTEM.getMaxNumericScale())); return factory.createTypeWithNullability(sqlType, isNullable); } else if (TypeCastRules.getLeastRestrictiveType(Lists.newArrayList(inputMinorType, TypeProtos.MinorType.FLOAT8))
int s2 = type.getScale(); final int maxPrecision = typeSystem.getMaxNumericPrecision(); final int maxScale = typeSystem.getMaxNumericScale();
int s2 = type.getScale(); final int maxPrecision = typeSystem.getMaxNumericPrecision(); final int maxScale = typeSystem.getMaxNumericScale();
DrillRelDataTypeSystem.DRILL_REL_DATATYPE_SYSTEM.getMaxNumericPrecision(), Math.min(operandType.getScale(), DrillRelDataTypeSystem.DRILL_REL_DATATYPE_SYSTEM.getMaxNumericScale())); return factory.createTypeWithNullability(sqlType, isNullable); } else if (TypeCastRules.getLeastRestrictiveType(Lists.newArrayList(inputMinorType, TypeProtos.MinorType.FLOAT8))