public abstract class SqlTypeUtil extends Object
| Constructor and Description |
|---|
SqlTypeUtil() |
| Modifier and Type | Method and Description |
|---|---|
static RelDataType |
addCharsetAndCollation(RelDataType type,
RelDataTypeFactory typeFactory)
Adds collation and charset to a character type, returns other types
unchanged.
|
static boolean |
areCharacterSetsMismatched(RelDataType t1,
RelDataType t2)
Determines whether two types both have different character sets.
|
static boolean |
canAssignFrom(RelDataType toType,
RelDataType fromType)
Tests whether a value can be assigned to a site.
|
static boolean |
canCastFrom(RelDataType toType,
RelDataType fromType,
boolean coerce)
Compares two types and returns true if fromType can be cast to toType.
|
static boolean |
containsNullable(List<RelDataType> types)
Returns whether one or more of an array of types is nullable.
|
static boolean |
containsNullable(RelDataType type)
Determines whether a type or any of its fields (if a structured type) are
nullable.
|
static SqlDataTypeSpec |
convertTypeToSpec(RelDataType type)
Converts an instance of RelDataType to an instance of SqlDataTypeSpec.
|
static RelDataType |
createArrayType(RelDataTypeFactory typeFactory,
RelDataType type,
boolean nullable) |
static RelDataType |
createEmptyStructType(RelDataTypeFactory typeFactory)
Records a struct type with no fields.
|
static RelDataType |
createMapType(RelDataTypeFactory typeFactory,
RelDataType keyType,
RelDataType valueType,
boolean nullable) |
static RelDataType |
createMultisetType(RelDataTypeFactory typeFactory,
RelDataType type,
boolean nullable) |
static List<RelDataType> |
deriveAndCollectTypes(SqlValidator validator,
SqlValidatorScope scope,
List<SqlNode> operands)
Iterates over all operands, derives their types, and collects them into
a list.
|
static boolean |
equalSansNullability(RelDataTypeFactory factory,
RelDataType type1,
RelDataType type2)
Returns whether two types are equal, ignoring nullability.
|
static int |
findField(RelDataType type,
String fieldName)
Returns the ordinal of a given field in a record type, or -1 if the field
is not found.
|
static RelDataType |
flattenRecordType(RelDataTypeFactory typeFactory,
RelDataType recordType,
int[] flatteningMap)
Flattens a record type by recursively expanding any fields which are
themselves record types.
|
static int |
getMaxByteSize(RelDataType type)
Computes the maximum number of bytes required to represent a value of a
type having user-defined precision.
|
static long |
getMaxValue(RelDataType type)
Determines the maximum unscaled value of a numeric type
|
static long |
getMinValue(RelDataType type)
Determines the minimum unscaled value of a numeric type
|
static String |
getNumericJavaClassName(RelDataType type) |
static String |
getPrimitiveWrapperJavaClassName(RelDataType type) |
static boolean |
inBooleanFamily(RelDataType type) |
static boolean |
inCharFamily(RelDataType type) |
static boolean |
inCharFamily(SqlTypeName typeName) |
static boolean |
inCharOrBinaryFamilies(RelDataType type) |
static boolean |
inSameFamily(RelDataType t1,
RelDataType t2) |
static boolean |
inSameFamilyOrNull(RelDataType t1,
RelDataType t2) |
static boolean |
isApproximateNumeric(RelDataType type) |
static boolean |
isBigint(RelDataType type) |
static boolean |
isBoundedVariableWidth(RelDataType type) |
static boolean |
isCharTypeComparable(List<RelDataType> argTypes)
Checks whether two types or more are char comparable.
|
static boolean |
isCharTypeComparable(SqlCallBinding binding,
List<SqlNode> operands,
boolean throwOnFailure)
Returns whether the operands to a call are char type-comparable.
|
static boolean |
isComparable(RelDataType type1,
RelDataType type2)
Returns whether two types are comparable.
|
static boolean |
isDatetime(RelDataType type) |
static boolean |
isDecimal(RelDataType type) |
static boolean |
isExactNumeric(RelDataType type) |
static boolean |
isFlat(RelDataType type)
Returns whether a type is flat.
|
static boolean |
isInterval(RelDataType type) |
static boolean |
isIntType(RelDataType type) |
static boolean |
isJavaPrimitive(RelDataType type) |
static boolean |
isLob(RelDataType type) |
static boolean |
isNumeric(RelDataType type) |
static boolean |
isOfSameTypeName(List<SqlTypeName> typeNames,
RelDataType type)
Returns true if any element in
typeNames matches
type.getSqlTypeName(). |
static boolean |
isOfSameTypeName(SqlTypeName typeName,
RelDataType type)
Returns typeName.equals(type.getSqlTypeName()).
|
static boolean |
isUnicode(RelDataType type)
Checks whether a type represents Unicode character data.
|
static RelDataType |
makeNullableIfOperandsAre(RelDataTypeFactory typeFactory,
List<RelDataType> argTypes,
RelDataType type)
Recreates a given RelDataType with nullability iff any of the param
argTypes are nullable.
|
static RelDataType |
makeNullableIfOperandsAre(SqlValidator validator,
SqlValidatorScope scope,
SqlCall call,
RelDataType type)
Recreates a given RelDataType with nullability iff any of the operands
of a call are nullable.
|
static long |
maxValue(RelDataType type)
Returns the maximum value of an integral type, as a long value
|
static boolean |
needsNullIndicator(RelDataType recordType) |
static List<RelDataType> |
projectTypes(RelDataType rowType,
List<? extends Number> requiredFields)
Selects data types of the specified fields from an input row type.
|
static RelDataType |
promoteToRowType(RelDataTypeFactory typeFactory,
RelDataType type,
String fieldName)
Promotes a type to a row type (does nothing if it already is one).
|
static boolean |
sameNamedType(RelDataType t1,
RelDataType t2)
Tests whether two types have the same name and structure, possibly with
differing modifiers.
|
public static boolean isCharTypeComparable(List<RelDataType> argTypes)
public static boolean isCharTypeComparable(SqlCallBinding binding, List<SqlNode> operands, boolean throwOnFailure)
binding - Binding of call to operandsoperands - Operands to check for compatibility; usually the
operands of the bound call, but not alwaysthrowOnFailure - Whether to throw an exception on failurepublic static List<RelDataType> deriveAndCollectTypes(SqlValidator validator, SqlValidatorScope scope, List<SqlNode> operands)
public static RelDataType promoteToRowType(RelDataTypeFactory typeFactory, RelDataType type, String fieldName)
type - type to be promotedfieldName - name to give field in row type; null for default of
"ROW_VALUE"public static RelDataType makeNullableIfOperandsAre(SqlValidator validator, SqlValidatorScope scope, SqlCall call, RelDataType type)
public static RelDataType makeNullableIfOperandsAre(RelDataTypeFactory typeFactory, List<RelDataType> argTypes, RelDataType type)
public static boolean containsNullable(List<RelDataType> types)
public static boolean containsNullable(RelDataType type)
public static boolean isOfSameTypeName(SqlTypeName typeName, RelDataType type)
public static boolean isOfSameTypeName(List<SqlTypeName> typeNames, RelDataType type)
typeNames matches
type.getSqlTypeName().public static boolean isDatetime(RelDataType type)
public static boolean isInterval(RelDataType type)
public static boolean inCharFamily(RelDataType type)
public static boolean inCharFamily(SqlTypeName typeName)
public static boolean inBooleanFamily(RelDataType type)
public static boolean inSameFamily(RelDataType t1, RelDataType t2)
public static boolean inSameFamilyOrNull(RelDataType t1, RelDataType t2)
SqlTypeName.NULL.public static boolean inCharOrBinaryFamilies(RelDataType type)
public static boolean isLob(RelDataType type)
public static boolean isBoundedVariableWidth(RelDataType type)
public static boolean isIntType(RelDataType type)
public static boolean isDecimal(RelDataType type)
public static boolean isBigint(RelDataType type)
public static boolean isExactNumeric(RelDataType type)
public static long maxValue(RelDataType type)
public static boolean isApproximateNumeric(RelDataType type)
public static boolean isNumeric(RelDataType type)
public static boolean sameNamedType(RelDataType t1, RelDataType t2)
public static int getMaxByteSize(RelDataType type)
type - type for which to compute storagepublic static long getMinValue(RelDataType type)
type - a numeric typepublic static long getMaxValue(RelDataType type)
type - a numeric typepublic static boolean isJavaPrimitive(RelDataType type)
public static String getPrimitiveWrapperJavaClassName(RelDataType type)
public static String getNumericJavaClassName(RelDataType type)
public static boolean canAssignFrom(RelDataType toType, RelDataType fromType)
toType - type of the target sitefromType - type of the source valuepublic static boolean areCharacterSetsMismatched(RelDataType t1, RelDataType t2)
t1 - first typet2 - second typepublic static boolean canCastFrom(RelDataType toType, RelDataType fromType, boolean coerce)
REVIEW jvs 17-Dec-2004: the coerce param below shouldn't really be
necessary. We're using it as a hack because
SqlTypeFactoryImpl.leastRestrictiveSqlType(java.util.List<org.apache.calcite.rel.type.RelDataType>) isn't complete enough
yet. Once it is, this param (and the non-coerce rules of
SqlTypeAssignmentRules) should go away.
toType - target of assignmentfromType - source of assignmentcoerce - if true, the SQL rules for CAST are used; if false, the
rules are similar to Java; e.g. you can't assign short x =
(int) y, and you can't assign int x = (String) z.public static RelDataType flattenRecordType(RelDataTypeFactory typeFactory, RelDataType recordType, int[] flatteningMap)
typeFactory - factory which should produced flattened typerecordType - type with possible nestingflatteningMap - if non-null, receives map from unflattened ordinal
to flattened ordinal (must have length at least
recordType.getFieldList().size())public static boolean needsNullIndicator(RelDataType recordType)
public static SqlDataTypeSpec convertTypeToSpec(RelDataType type)
type - type descriptorpublic static RelDataType createMultisetType(RelDataTypeFactory typeFactory, RelDataType type, boolean nullable)
public static RelDataType createArrayType(RelDataTypeFactory typeFactory, RelDataType type, boolean nullable)
public static RelDataType createMapType(RelDataTypeFactory typeFactory, RelDataType keyType, RelDataType valueType, boolean nullable)
public static RelDataType addCharsetAndCollation(RelDataType type, RelDataTypeFactory typeFactory)
type - TypetypeFactory - Type factorypublic static boolean equalSansNullability(RelDataTypeFactory factory, RelDataType type1, RelDataType type2)
They need not come from the same factory.
factory - Type factorytype1 - First typetype2 - Second typepublic static int findField(RelDataType type, String fieldName)
type - Record typefieldName - Name of fieldpublic static List<RelDataType> projectTypes(RelDataType rowType, List<? extends Number> requiredFields)
rowType - input row typerequiredFields - ordinals of the projected fieldspublic static RelDataType createEmptyStructType(RelDataTypeFactory typeFactory)
typeFactory - Type factorypublic static boolean isFlat(RelDataType type)
public static boolean isComparable(RelDataType type1, RelDataType type2)
type1 - First typetype2 - Second typepublic static boolean isUnicode(RelDataType type)
type - type to testCopyright © 2012–2015 The Apache Software Foundation. All rights reserved.