Java Code Examples for org.apache.calcite.sql.type.SqlTypeFamily#NUMERIC
The following examples show how to use
org.apache.calcite.sql.type.SqlTypeFamily#NUMERIC .
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: RelDataTypeSystemImpl.java From Bats with Apache License 2.0 | 5 votes |
@Override public int getNumTypeRadix(SqlTypeName typeName) { if (typeName.getFamily() == SqlTypeFamily.NUMERIC && getDefaultPrecision(typeName) != -1) { return 10; } return 0; }
Example 2
Source File: RexUtil.java From Bats with Apache License 2.0 | 5 votes |
/** * Returns whether the input is a 'loss-less' cast, that is, a cast from which * the original value of the field can be certainly recovered. * * <p>For instance, int → bigint is loss-less (as you can cast back to * int without loss of information), but bigint → int is not loss-less. * * <p>The implementation of this method does not return false positives. * However, it is not complete. */ public static boolean isLosslessCast(RexNode node) { if (!node.isA(SqlKind.CAST)) { return false; } final RelDataType source = ((RexCall) node).getOperands().get(0).getType(); final SqlTypeName sourceSqlTypeName = source.getSqlTypeName(); final RelDataType target = node.getType(); final SqlTypeName targetSqlTypeName = target.getSqlTypeName(); // 1) Both INT numeric types if (SqlTypeFamily.INTEGER.getTypeNames().contains(sourceSqlTypeName) && SqlTypeFamily.INTEGER.getTypeNames().contains(targetSqlTypeName)) { return targetSqlTypeName.compareTo(sourceSqlTypeName) >= 0; } // 2) Both CHARACTER types: it depends on the precision (length) if (SqlTypeFamily.CHARACTER.getTypeNames().contains(sourceSqlTypeName) && SqlTypeFamily.CHARACTER.getTypeNames().contains(targetSqlTypeName)) { return targetSqlTypeName.compareTo(sourceSqlTypeName) >= 0 && source.getPrecision() <= target.getPrecision(); } // 3) From NUMERIC family to CHARACTER family: it depends on the precision/scale if (sourceSqlTypeName.getFamily() == SqlTypeFamily.NUMERIC && targetSqlTypeName.getFamily() == SqlTypeFamily.CHARACTER) { int sourceLength = source.getPrecision() + 1; // include sign if (source.getScale() != -1 && source.getScale() != 0) { sourceLength += source.getScale() + 1; // include decimal mark } return target.getPrecision() >= sourceLength; } // Return FALSE by default return false; }
Example 3
Source File: TypeUtils.java From dremio-oss with Apache License 2.0 | 5 votes |
public static boolean isNumeric(final RField field) { final Optional<SqlTypeFamily> familyOpt = getSqlTypeFamily(field); if (!familyOpt.isPresent()) { return false; } final SqlTypeFamily family = familyOpt.get(); return family == SqlTypeFamily.NUMERIC; }
Example 4
Source File: DruidJsonFilter.java From calcite with Apache License 2.0 | 5 votes |
@Nullable private static DruidJsonFilter toBetweenDruidFilter(RexNode rexNode, RelDataType rowType, DruidQuery query) { if (rexNode.getKind() != SqlKind.BETWEEN) { return null; } final RexCall rexCall = (RexCall) rexNode; if (rexCall.getOperands().size() < 4) { return null; } // BETWEEN (ASYMMETRIC, REF, 'lower-bound', 'upper-bound') final RexNode refNode = rexCall.getOperands().get(1); final RexNode lhs = rexCall.getOperands().get(2); final RexNode rhs = rexCall.getOperands().get(3); final String lhsLiteralValue = toDruidLiteral(lhs, rowType, query); final String rhsLiteralValue = toDruidLiteral(rhs, rowType, query); if (lhsLiteralValue == null || rhsLiteralValue == null) { return null; } final boolean isNumeric = lhs.getType().getFamily() == SqlTypeFamily.NUMERIC || lhs.getType().getFamily() == SqlTypeFamily.NUMERIC; final Pair<String, ExtractionFunction> druidColumn = DruidQuery .toDruidColumn(refNode, rowType, query); final String columnName = druidColumn.left; final ExtractionFunction extractionFunction = druidColumn.right; if (columnName == null) { return null; } return new JsonBound(columnName, lhsLiteralValue, false, rhsLiteralValue, false, isNumeric, extractionFunction); }
Example 5
Source File: RelDataTypeSystemImpl.java From calcite with Apache License 2.0 | 5 votes |
@Override public int getNumTypeRadix(SqlTypeName typeName) { if (typeName.getFamily() == SqlTypeFamily.NUMERIC && getDefaultPrecision(typeName) != -1) { return 10; } return 0; }
Example 6
Source File: RexUtil.java From calcite with Apache License 2.0 | 5 votes |
/** * Returns whether the conversion from {@code source} to {@code target} type * is a 'loss-less' cast, that is, a cast from which * the original value of the field can be certainly recovered. * * <p>For instance, int → bigint is loss-less (as you can cast back to * int without loss of information), but bigint → int is not loss-less. * * <p>The implementation of this method does not return false positives. * However, it is not complete. * @param source source type * @param target target type * @return true iff the conversion is a loss-less cast */ @API(since = "1.22", status = API.Status.EXPERIMENTAL) public static boolean isLosslessCast(RelDataType source, RelDataType target) { final SqlTypeName sourceSqlTypeName = source.getSqlTypeName(); final SqlTypeName targetSqlTypeName = target.getSqlTypeName(); // 1) Both INT numeric types if (SqlTypeFamily.INTEGER.getTypeNames().contains(sourceSqlTypeName) && SqlTypeFamily.INTEGER.getTypeNames().contains(targetSqlTypeName)) { return targetSqlTypeName.compareTo(sourceSqlTypeName) >= 0; } // 2) Both CHARACTER types: it depends on the precision (length) if (SqlTypeFamily.CHARACTER.getTypeNames().contains(sourceSqlTypeName) && SqlTypeFamily.CHARACTER.getTypeNames().contains(targetSqlTypeName)) { return targetSqlTypeName.compareTo(sourceSqlTypeName) >= 0 && source.getPrecision() <= target.getPrecision(); } // 3) From NUMERIC family to CHARACTER family: it depends on the precision/scale if (sourceSqlTypeName.getFamily() == SqlTypeFamily.NUMERIC && targetSqlTypeName.getFamily() == SqlTypeFamily.CHARACTER) { int sourceLength = source.getPrecision() + 1; // include sign if (source.getScale() != -1 && source.getScale() != 0) { sourceLength += source.getScale() + 1; // include decimal mark } return target.getPrecision() >= sourceLength; } // Return FALSE by default return false; }