Java Code Examples for org.apache.calcite.rel.type.RelDataType#PRECISION_NOT_SPECIFIED
The following examples show how to use
org.apache.calcite.rel.type.RelDataType#PRECISION_NOT_SPECIFIED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlTests.java From calcite with Apache License 2.0 | 6 votes |
/** * Helper function to get the string representation of a RelDataType * (include precision/scale but no charset or collation) * * @param sqlType Type * @return String representation of type */ public static String getTypeString(RelDataType sqlType) { switch (sqlType.getSqlTypeName()) { case VARCHAR: case CHAR: String actual = sqlType.getSqlTypeName().name(); if (sqlType.getPrecision() != RelDataType.PRECISION_NOT_SPECIFIED) { actual = actual + "(" + sqlType.getPrecision() + ")"; } if (!sqlType.isNullable()) { actual += " NOT NULL"; } return actual; default: return sqlType.getFullTypeString(); } }
Example 2
Source File: TypeInferenceUtils.java From dremio-oss with Apache License 2.0 | 6 votes |
@Override public RelDataType inferReturnType(SqlOperatorBinding opBinding) { final RelDataTypeFactory factory = opBinding.getTypeFactory(); boolean isNullable = true; int precision = 0; for(RelDataType relDataType : opBinding.collectOperandTypes()) { if(!relDataType.isNullable()) { isNullable = false; } // If the underlying columns cannot offer information regarding the precision (i.e., the length) of the VarChar, // Dremio uses the largest to represent it if(relDataType.getPrecision() == TypeHelper.VARCHAR_DEFAULT_CAST_LEN || relDataType.getPrecision() == RelDataType.PRECISION_NOT_SPECIFIED) { precision = TypeHelper.VARCHAR_DEFAULT_CAST_LEN; } else { precision += relDataType.getPrecision(); } } return factory.createTypeWithNullability( factory.createSqlType(SqlTypeName.VARCHAR, precision), isNullable); }
Example 3
Source File: TypeInferenceUtils.java From Bats with Apache License 2.0 | 6 votes |
@Override public RelDataType inferReturnType(SqlOperatorBinding opBinding) { // If the underlying columns cannot offer information regarding the precision of the VarChar, // Drill uses the largest to represent it. int totalPrecision = 0; for (RelDataType relDataType : opBinding.collectOperandTypes()) { if (isScalarStringType(relDataType.getSqlTypeName()) && relDataType.getPrecision() != RelDataType.PRECISION_NOT_SPECIFIED) { totalPrecision += relDataType.getPrecision(); } else { totalPrecision = Types.MAX_VARCHAR_LENGTH; break; } } totalPrecision = totalPrecision > Types.MAX_VARCHAR_LENGTH ? Types.MAX_VARCHAR_LENGTH : totalPrecision; boolean isNullable = isNullIfNull && isNullable(opBinding.collectOperandTypes()); return opBinding.getTypeFactory().createTypeWithNullability( opBinding.getTypeFactory().createSqlType(SqlTypeName.VARCHAR, totalPrecision), isNullable); }
Example 4
Source File: SqlIntervalQualifier.java From Bats with Apache License 2.0 | 5 votes |
public int getStartPrecision(RelDataTypeSystem typeSystem) { if (startPrecision == RelDataType.PRECISION_NOT_SPECIFIED) { return typeSystem.getDefaultPrecision(typeName()); } else { return startPrecision; } }
Example 5
Source File: SqlTypeFactoryTest.java From calcite with Apache License 2.0 | 5 votes |
/** Unit test for {@link SqlTypeUtil#comparePrecision(int, int)} * and {@link SqlTypeUtil#maxPrecision(int, int)}. */ @Test void testMaxPrecision() { final int un = RelDataType.PRECISION_NOT_SPECIFIED; checkPrecision(1, 1, 1, 0); checkPrecision(2, 1, 2, 1); checkPrecision(2, 100, 100, -1); checkPrecision(2, un, un, -1); checkPrecision(un, 2, un, 1); checkPrecision(un, un, un, 0); }
Example 6
Source File: SqlIntervalQualifier.java From calcite with Apache License 2.0 | 5 votes |
public int getFractionalSecondPrecisionPreservingDefault() { if (useDefaultFractionalSecondPrecision()) { return RelDataType.PRECISION_NOT_SPECIFIED; } else { return fractionalSecondPrecision; } }
Example 7
Source File: SqlIntervalQualifier.java From calcite with Apache License 2.0 | 5 votes |
public int getFractionalSecondPrecision(RelDataTypeSystem typeSystem) { if (fractionalSecondPrecision == RelDataType.PRECISION_NOT_SPECIFIED) { return typeName().getDefaultScale(); } else { return fractionalSecondPrecision; } }
Example 8
Source File: SqlIntervalQualifier.java From calcite with Apache License 2.0 | 5 votes |
public int getStartPrecision(RelDataTypeSystem typeSystem) { if (startPrecision == RelDataType.PRECISION_NOT_SPECIFIED) { return typeSystem.getDefaultPrecision(typeName()); } else { return startPrecision; } }
Example 9
Source File: SqlIntervalQualifier.java From calcite with Apache License 2.0 | 5 votes |
public SqlIntervalQualifier( TimeUnit startUnit, TimeUnit endUnit, SqlParserPos pos) { this( startUnit, RelDataType.PRECISION_NOT_SPECIFIED, endUnit, RelDataType.PRECISION_NOT_SPECIFIED, pos); }
Example 10
Source File: SqlTypeUtil.java From calcite with Apache License 2.0 | 5 votes |
/** Returns whether a precision is greater or equal than another, * treating {@link RelDataType#PRECISION_NOT_SPECIFIED} as infinity. */ public static int comparePrecision(int p0, int p1) { if (p0 == p1) { return 0; } if (p0 == RelDataType.PRECISION_NOT_SPECIFIED) { return 1; } if (p1 == RelDataType.PRECISION_NOT_SPECIFIED) { return -1; } return Integer.compare(p0, p1); }
Example 11
Source File: SqlTypeUtil.java From Bats with Apache License 2.0 | 5 votes |
/** Returns whether a precision is greater or equal than another, * treating {@link RelDataType#PRECISION_NOT_SPECIFIED} as infinity. */ public static int comparePrecision(int p0, int p1) { if (p0 == p1) { return 0; } if (p0 == RelDataType.PRECISION_NOT_SPECIFIED) { return 1; } if (p1 == RelDataType.PRECISION_NOT_SPECIFIED) { return -1; } return Integer.compare(p0, p1); }
Example 12
Source File: SqlIntervalQualifier.java From Bats with Apache License 2.0 | 5 votes |
public int getFractionalSecondPrecisionPreservingDefault() { if (useDefaultFractionalSecondPrecision()) { return RelDataType.PRECISION_NOT_SPECIFIED; } else { return fractionalSecondPrecision; } }
Example 13
Source File: SqlIntervalQualifier.java From Bats with Apache License 2.0 | 5 votes |
public int getFractionalSecondPrecision(RelDataTypeSystem typeSystem) { if (fractionalSecondPrecision == RelDataType.PRECISION_NOT_SPECIFIED) { return typeName().getDefaultScale(); } else { return fractionalSecondPrecision; } }
Example 14
Source File: SqlIntervalQualifier.java From Bats with Apache License 2.0 | 5 votes |
public SqlIntervalQualifier( TimeUnit startUnit, TimeUnit endUnit, SqlParserPos pos) { this( startUnit, RelDataType.PRECISION_NOT_SPECIFIED, endUnit, RelDataType.PRECISION_NOT_SPECIFIED, pos); }
Example 15
Source File: PlanExecutor.java From quark with Apache License 2.0 | 4 votes |
private static int getPrecision(RelDataType type) { return type.getPrecision() == RelDataType.PRECISION_NOT_SPECIFIED ? 0 : type.getPrecision(); }
Example 16
Source File: SqlTypeUtil.java From Bats with Apache License 2.0 | 4 votes |
/** Returns the larger of two precisions, treating * {@link RelDataType#PRECISION_NOT_SPECIFIED} as infinity. */ public static int maxPrecision(int p0, int p1) { return (p0 == RelDataType.PRECISION_NOT_SPECIFIED || p0 >= p1 && p1 != RelDataType.PRECISION_NOT_SPECIFIED) ? p0 : p1; }
Example 17
Source File: SqlIntervalQualifier.java From Bats with Apache License 2.0 | 4 votes |
/** Returns {@code true} if fractional second precision is not specified. */ public boolean useDefaultFractionalSecondPrecision() { return fractionalSecondPrecision == RelDataType.PRECISION_NOT_SPECIFIED; }
Example 18
Source File: SqlIntervalQualifier.java From calcite with Apache License 2.0 | 4 votes |
/** Returns {@code true} if start precision is not specified. */ public boolean useDefaultStartPrecision() { return startPrecision == RelDataType.PRECISION_NOT_SPECIFIED; }
Example 19
Source File: SqlIntervalQualifier.java From Bats with Apache License 2.0 | 4 votes |
/** Returns {@code true} if start precision is not specified. */ public boolean useDefaultStartPrecision() { return startPrecision == RelDataType.PRECISION_NOT_SPECIFIED; }
Example 20
Source File: SqlTypeUtil.java From calcite with Apache License 2.0 | 4 votes |
/** Returns the larger of two precisions, treating * {@link RelDataType#PRECISION_NOT_SPECIFIED} as infinity. */ public static int maxPrecision(int p0, int p1) { return (p0 == RelDataType.PRECISION_NOT_SPECIFIED || p0 >= p1 && p1 != RelDataType.PRECISION_NOT_SPECIFIED) ? p0 : p1; }