Java Code Examples for org.apache.calcite.rel.type.RelDataType#getFamily()
The following examples show how to use
org.apache.calcite.rel.type.RelDataType#getFamily() .
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: SqlMultisetMemberOfOperator.java From Bats with Apache License 2.0 | 5 votes |
public boolean checkOperandTypes( SqlCallBinding callBinding, boolean throwOnFailure) { if (!OperandTypes.MULTISET.checkSingleOperandType( callBinding, callBinding.operand(1), 0, throwOnFailure)) { return false; } MultisetSqlType mt = (MultisetSqlType) callBinding.getValidator().deriveType( callBinding.getScope(), callBinding.operand(1)); RelDataType t0 = callBinding.getValidator().deriveType( callBinding.getScope(), callBinding.operand(0)); RelDataType t1 = mt.getComponentType(); if (t0.getFamily() != t1.getFamily()) { if (throwOnFailure) { throw callBinding.newValidationError( RESOURCE.typeNotComparableNear(t0.toString(), t1.toString())); } return false; } return true; }
Example 2
Source File: SqlTypeUtil.java From calcite with Apache License 2.0 | 5 votes |
/** * Tests whether a value can be assigned to a site. * * @param toType type of the target site * @param fromType type of the source value * @return true iff assignable */ public static boolean canAssignFrom( RelDataType toType, RelDataType fromType) { if (isAny(toType) || isAny(fromType)) { return true; } // TODO jvs 2-Jan-2005: handle all the other cases like // rows, collections, UDT's if (fromType.getSqlTypeName() == SqlTypeName.NULL) { // REVIEW jvs 4-Dec-2008: We allow assignment from NULL to any // type, including NOT NULL types, since in the case where no // rows are actually processed, the assignment is legal // (FRG-365). However, it would be better if the validator's // NULL type inference guaranteed that we had already // assigned a real (nullable) type to every NULL literal. return true; } if (fromType.getSqlTypeName() == SqlTypeName.ARRAY) { if (toType.getSqlTypeName() != SqlTypeName.ARRAY) { return false; } return canAssignFrom(toType.getComponentType(), fromType.getComponentType()); } if (areCharacterSetsMismatched(toType, fromType)) { return false; } return toType.getFamily() == fromType.getFamily(); }
Example 3
Source File: SqlMultisetMemberOfOperator.java From calcite with Apache License 2.0 | 5 votes |
public boolean checkOperandTypes( SqlCallBinding callBinding, boolean throwOnFailure) { if (!OperandTypes.MULTISET.checkSingleOperandType( callBinding, callBinding.operand(1), 0, throwOnFailure)) { return false; } MultisetSqlType mt = (MultisetSqlType) callBinding.getValidator().deriveType( callBinding.getScope(), callBinding.operand(1)); RelDataType t0 = callBinding.getValidator().deriveType( callBinding.getScope(), callBinding.operand(0)); RelDataType t1 = mt.getComponentType(); if (t0.getFamily() != t1.getFamily()) { if (throwOnFailure) { throw callBinding.newValidationError( RESOURCE.typeNotComparableNear(t0.toString(), t1.toString())); } return false; } return true; }
Example 4
Source File: StandardConvertletTable.java From calcite with Apache License 2.0 | 5 votes |
private static RelDataType consistentType(SqlRexContext cx, SqlOperandTypeChecker.Consistency consistency, List<RelDataType> types) { switch (consistency) { case COMPARE: if (SqlTypeUtil.areSameFamily(types)) { // All arguments are of same family. No need for explicit casts. return null; } final List<RelDataType> nonCharacterTypes = new ArrayList<>(); for (RelDataType type : types) { if (type.getFamily() != SqlTypeFamily.CHARACTER) { nonCharacterTypes.add(type); } } if (!nonCharacterTypes.isEmpty()) { final int typeCount = types.size(); types = nonCharacterTypes; if (nonCharacterTypes.size() < typeCount) { final RelDataTypeFamily family = nonCharacterTypes.get(0).getFamily(); if (family instanceof SqlTypeFamily) { // The character arguments might be larger than the numeric // argument. Give ourselves some headroom. switch ((SqlTypeFamily) family) { case INTEGER: case NUMERIC: nonCharacterTypes.add( cx.getTypeFactory().createSqlType(SqlTypeName.BIGINT)); } } } } // fall through case LEAST_RESTRICTIVE: return cx.getTypeFactory().leastRestrictive(types); default: return null; } }
Example 5
Source File: SqlTypeUtil.java From Bats with Apache License 2.0 | 5 votes |
/** * Tests whether a value can be assigned to a site. * * @param toType type of the target site * @param fromType type of the source value * @return true iff assignable */ public static boolean canAssignFrom( RelDataType toType, RelDataType fromType) { if (isAny(toType) || isAny(fromType)) { return true; } // TODO jvs 2-Jan-2005: handle all the other cases like // rows, collections, UDT's if (fromType.getSqlTypeName() == SqlTypeName.NULL) { // REVIEW jvs 4-Dec-2008: We allow assignment from NULL to any // type, including NOT NULL types, since in the case where no // rows are actually processed, the assignment is legal // (FRG-365). However, it would be better if the validator's // NULL type inference guaranteed that we had already // assigned a real (nullable) type to every NULL literal. return true; } if (fromType.getSqlTypeName() == SqlTypeName.ARRAY) { if (toType.getSqlTypeName() != SqlTypeName.ARRAY) { return false; } return canAssignFrom(toType.getComponentType(), fromType.getComponentType()); } if (areCharacterSetsMismatched(toType, fromType)) { return false; } return toType.getFamily() == fromType.getFamily(); }
Example 6
Source File: StandardConvertletTable.java From Bats with Apache License 2.0 | 5 votes |
private static RelDataType consistentType(SqlRexContext cx, SqlOperandTypeChecker.Consistency consistency, List<RelDataType> types) { switch (consistency) { case COMPARE: if (SqlTypeUtil.areSameFamily(types)) { // All arguments are of same family. No need for explicit casts. return null; } final List<RelDataType> nonCharacterTypes = new ArrayList<>(); for (RelDataType type : types) { if (type.getFamily() != SqlTypeFamily.CHARACTER) { nonCharacterTypes.add(type); } } if (!nonCharacterTypes.isEmpty()) { final int typeCount = types.size(); types = nonCharacterTypes; if (nonCharacterTypes.size() < typeCount) { final RelDataTypeFamily family = nonCharacterTypes.get(0).getFamily(); if (family instanceof SqlTypeFamily) { // The character arguments might be larger than the numeric // argument. Give ourselves some headroom. switch ((SqlTypeFamily) family) { case INTEGER: case NUMERIC: nonCharacterTypes.add( cx.getTypeFactory().createSqlType(SqlTypeName.BIGINT)); } } } } // fall through case LEAST_RESTRICTIVE: return cx.getTypeFactory().leastRestrictive(types); default: return null; } }
Example 7
Source File: SqlTypeUtil.java From Bats with Apache License 2.0 | 4 votes |
/** * @return true if two types are in same type family, or one or the other is * of type {@link SqlTypeName#NULL}. */ public static boolean inSameFamilyOrNull(RelDataType t1, RelDataType t2) { return (t1.getSqlTypeName() == SqlTypeName.NULL) || (t2.getSqlTypeName() == SqlTypeName.NULL) || (t1.getFamily() == t2.getFamily()); }
Example 8
Source File: SqlTypeUtil.java From Bats with Apache License 2.0 | 4 votes |
/** * @return true if type family is either character or binary */ public static boolean inCharOrBinaryFamilies(RelDataType type) { return (type.getFamily() == SqlTypeFamily.CHARACTER) || (type.getFamily() == SqlTypeFamily.BINARY); }
Example 9
Source File: SqlTypeUtil.java From Bats with Apache License 2.0 | 4 votes |
private static boolean isAny(RelDataType t) { return t.getFamily() == SqlTypeFamily.ANY; }
Example 10
Source File: SqlTypeUtil.java From Bats with Apache License 2.0 | 4 votes |
/** * @return true if two types are in same type family */ public static boolean inSameFamily(RelDataType t1, RelDataType t2) { return t1.getFamily() == t2.getFamily(); }
Example 11
Source File: ConvertletTable.java From dremio-oss with Apache License 2.0 | 4 votes |
private static RelDataType consistentType(SqlRexContext cx, SqlOperandTypeChecker.Consistency consistency, List<RelDataType> types) { switch (consistency) { case COMPARE: final Set<RelDataTypeFamily> families = Sets.newHashSet(RexUtil.families(types)); if (families.size() < 2) { // All arguments are of same family. No need for explicit casts. return null; } final List<RelDataType> nonCharacterTypes = Lists.newArrayList(); for (RelDataType type : types) { if (type.getFamily() != SqlTypeFamily.CHARACTER) { nonCharacterTypes.add(type); } } if (!nonCharacterTypes.isEmpty()) { final int typeCount = types.size(); types = nonCharacterTypes; if (nonCharacterTypes.size() < typeCount) { final RelDataTypeFamily family = nonCharacterTypes.get(0).getFamily(); if (family instanceof SqlTypeFamily) { // The character arguments might be larger than the numeric // argument. Give ourselves some headroom. switch ((SqlTypeFamily) family) { case INTEGER: case NUMERIC: nonCharacterTypes.add( cx.getTypeFactory().createSqlType(SqlTypeName.BIGINT)); } } } } // fall through case LEAST_RESTRICTIVE: return cx.getTypeFactory().leastRestrictive(types); default: return null; } }
Example 12
Source File: SqlTypeUtil.java From Bats with Apache License 2.0 | 4 votes |
/** * @return true if type is in SqlTypeFamily.Boolean */ public static boolean inBooleanFamily(RelDataType type) { return type.getFamily() == SqlTypeFamily.BOOLEAN; }
Example 13
Source File: SqlTypeUtil.java From Bats with Apache License 2.0 | 4 votes |
/** * @return true if type is in SqlTypeFamily.Character */ public static boolean inCharFamily(RelDataType type) { return type.getFamily() == SqlTypeFamily.CHARACTER; }
Example 14
Source File: SqlTypeUtil.java From calcite with Apache License 2.0 | 4 votes |
/** * @return true if type is in SqlTypeFamily.Character */ public static boolean inCharFamily(RelDataType type) { return type.getFamily() == SqlTypeFamily.CHARACTER; }
Example 15
Source File: SqlTypeUtil.java From calcite with Apache License 2.0 | 4 votes |
/** * @return true if type is in SqlTypeFamily.Boolean */ public static boolean inBooleanFamily(RelDataType type) { return type.getFamily() == SqlTypeFamily.BOOLEAN; }
Example 16
Source File: SqlTypeUtil.java From calcite with Apache License 2.0 | 4 votes |
/** * @return true if two types are in same type family */ public static boolean inSameFamily(RelDataType t1, RelDataType t2) { return t1.getFamily() == t2.getFamily(); }
Example 17
Source File: SqlTypeUtil.java From calcite with Apache License 2.0 | 4 votes |
/** * @return true if two types are in same type family, or one or the other is * of type {@link SqlTypeName#NULL}. */ public static boolean inSameFamilyOrNull(RelDataType t1, RelDataType t2) { return (t1.getSqlTypeName() == SqlTypeName.NULL) || (t2.getSqlTypeName() == SqlTypeName.NULL) || (t1.getFamily() == t2.getFamily()); }
Example 18
Source File: SqlTypeUtil.java From calcite with Apache License 2.0 | 4 votes |
/** * @return true if type family is either character or binary */ public static boolean inCharOrBinaryFamilies(RelDataType type) { return (type.getFamily() == SqlTypeFamily.CHARACTER) || (type.getFamily() == SqlTypeFamily.BINARY); }
Example 19
Source File: SqlTypeUtil.java From calcite with Apache License 2.0 | 4 votes |
private static boolean isAny(RelDataType t) { return t.getFamily() == SqlTypeFamily.ANY; }