Class SqlTypeUtil
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic RelDataType
addCharsetAndCollation
(RelDataType type, RelDataTypeFactory typeFactory) Adds collation and charset to a character type, returns other types unchanged.static boolean
allNullable
(List<RelDataType> types) Returns whether all of array of types are nullable.static boolean
Determines whether two types both have different character sets.static boolean
areSameFamily
(Iterable<RelDataType> types) Returns whether all types in a collection have the same family, as determined byisSameFamily(RelDataType, RelDataType)
.static boolean
canAssignFrom
(RelDataType toType, RelDataType fromType) Tests whether a value can be assigned to a site.static boolean
canBeRepresentedExactly
(@Nullable BigDecimal value, RelDataType toType) Returns whether the decimal value can be represented without information loss using the specified type.static boolean
canCastFrom
(RelDataType toType, RelDataType fromType, boolean coerce) Compares two types and returns whetherfromType
can be cast totoType
, using either coercion or assignment.static boolean
canCastFrom
(RelDataType toType, RelDataType fromType, SqlTypeMappingRule typeMappingRule) Compares two types and returns whetherfromType
can be cast totoType
.static int
comparePrecision
(int p0, int p1) Returns whether a precision is greater or equal than another, treatingRelDataType.PRECISION_NOT_SPECIFIED
as infinity.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 SqlDataTypeSpec
convertTypeToSpec
(RelDataType type, @Nullable String charSetName, int maxPrecision, int maxScale) 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
createMapTypeFromRecord
(RelDataTypeFactory typeFactory, RelDataType type) Creates a MAP type from a record type.static RelDataType
createMultisetType
(RelDataTypeFactory typeFactory, RelDataType type, boolean nullable) static RelDataType
createRecordTypeFromMap
(RelDataTypeFactory typeFactory, RelDataType type) Creates a ROW type from a map type.static List<RelDataType>
deriveAndCollectTypes
(SqlValidator validator, SqlValidatorScope scope, List<? extends SqlNode> operands) Iterates over all operands, derives their types, and collects them into a list.static RelDataType
deriveCollectionQueryComponentType
(SqlTypeName collectionType, RelDataType origin) Derives component type for ARRAY, MULTISET, MAP when input is sub-query.static RelDataType
deriveType
(SqlCallBinding binding) Derives type of the call via its binding.static List<RelDataType>
deriveType
(SqlCallBinding binding, List<? extends SqlNode> nodes) Derives types for the list of nodes.static RelDataType
deriveType
(SqlCallBinding binding, SqlNode node) Derives type of the given call under given binding.static boolean
equalAsCollectionSansNullability
(RelDataTypeFactory factory, RelDataType type1, RelDataType type2) Returns whether two collection types are equal, ignoring nullability.static boolean
equalAsMapSansNullability
(RelDataTypeFactory factory, RelDataType type1, RelDataType type2) Returns whether two map types are equal, ignoring nullability.static boolean
equalAsStructSansNullability
(RelDataTypeFactory factory, RelDataType type1, RelDataType type2, @Nullable SqlNameMatcher nameMatcher) Returns whether two struct types are equal, ignoring nullability.static boolean
equalSansNullability
(RelDataTypeFactory factory, RelDataType type1, RelDataType type2) Returns whether two types are equal, ignoring nullability.static boolean
equalSansNullability
(RelDataType type1, RelDataType type2) This is a poorman'sequalSansNullability(RelDataTypeFactory, RelDataType, RelDataType)
.static RelDataType
extractLastNFields
(RelDataTypeFactory typeFactory, RelDataType type, int numToKeep) Keeps only the last N fields and returns the new struct type.protected static RelDataTypeFamily
family
(RelDataType type) 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 @Nullable [] flatteningMap) Flattens a record type by recursively expanding any fields which are themselves record types.static RelDataType
fromMeasure
(RelDataTypeFactory typeFactory, RelDataType type) Strips MEASURE wrappers from a type.static int
getMaxByteSize
(RelDataType type) Computes the maximum number of bytes required to represent a value of a type having user-defined precision.static RelDataType
Returns a DECIMAL type with the maximum precision for the current type system.static long
getMaxValue
(RelDataType type) Returns the maximum unscaled value of a numeric type.static long
getMinValue
(RelDataType type) Returns the minimum unscaled value of a numeric type.static @Nullable String
getNumericJavaClassName
(@Nullable RelDataType type) Deprecated.static @Nullable String
getPrimitiveWrapperJavaClassName
(@Nullable RelDataType type) Deprecated.static boolean
hasCharacter
(RelDataType type) Returns whether a type is a CHARACTER or contains a CHARACTER type.static boolean
hasCharactor
(RelDataType type) Deprecated.static boolean
hasScale
(RelDataType type) Returns whether a type's scale is set.static boolean
inBooleanFamily
(RelDataType type) Returns whether a type is in SqlTypeFamily.Boolean.static boolean
inCharFamily
(RelDataType type) Returns whether a type is in SqlTypeFamily.Character.static boolean
inCharFamily
(SqlTypeName typeName) Returns whether a type name is in SqlTypeFamily.Character.static boolean
Returns whether a type family is either character or binary.static boolean
inSameFamily
(RelDataType t1, RelDataType t2) Returns whether two types are in same type family.static boolean
inSameFamilyOrNull
(RelDataType t1, RelDataType t2) Returns whether two types are in same type family, or one or the other is of typeSqlTypeName.NULL
.static boolean
Returns whether a type is numeric with approximate precision.static boolean
isArray
(RelDataType type) Returns whether a type is ARRAY.static boolean
isAtomic
(RelDataType type) Returns whether a type is atomic (datetime, numeric, string or BOOLEAN).static boolean
isBinary
(RelDataType type) Returns whether a type is BINARY.static boolean
isBoolean
(RelDataType type) Returns whether a type is BOOLEAN.static boolean
Returns whether a type is variable width with bounded precision.static boolean
isCharacter
(RelDataType type) Returns whether a type is CHARACTER.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
isCollection
(RelDataType type) Returns whether a type is ARRAY or MULTISET.static boolean
isComparable
(RelDataType type1, RelDataType type2) Returns whether two types are comparable.static boolean
isDate
(RelDataType type) Returns whether a type is DATE.static boolean
isDatetime
(RelDataType type) Returns whether a type is DATE, TIME, or TIMESTAMP.static boolean
isDecimal
(RelDataType type) Returns whether a type is DECIMAL.static boolean
isExactNumeric
(RelDataType type) Returns whether a type is numeric with exact precision.static boolean
isFlat
(RelDataType type) Returns whether a type is flat.static boolean
isInterval
(RelDataType type) Returns whether a type is some kind of INTERVAL.static boolean
isIntType
(RelDataType type) Returns whether a type is one of the integer types.static boolean
isJavaPrimitive
(RelDataType type) Deprecated.static boolean
isLob
(RelDataType type) Returns whether a type is a LOB of some kind.static boolean
isMap
(RelDataType type) Returns whether a type is MAP.static boolean
static boolean
isMultiset
(RelDataType type) Returns whether a type is MULTISET.static boolean
isNull
(RelDataType type) Returns whether a type is the NULL type.static boolean
isNumeric
(RelDataType type) Returns whether a type is numeric.static boolean
isOfSameTypeName
(Collection<SqlTypeName> typeNames, RelDataType type) Returns true if any element intypeNames
matches type.getSqlTypeName().static boolean
isOfSameTypeName
(SqlTypeName typeName, RelDataType type) Returns typeName.equals(type.getSqlTypeName()).static boolean
isRow
(RelDataType type) Returns whether a type is ROW.static boolean
isString
(RelDataType type) Returns whether a type is STRING.static boolean
isTimestamp
(RelDataType type) Returns whether a type is TIMESTAMP.static boolean
isUnicode
(RelDataType type) Checks whether a type represents Unicode character data.static boolean
isValidDecimalValue
(@Nullable BigDecimal value, RelDataType toType) Returns whether the decimal value is valid for the type.static RelDataType
keepSourceTypeAndTargetNullability
(RelDataType sourceRelDataType, RelDataType targetRelDataType, RelDataTypeFactory typeFactory) Creates a RelDataType having the same type of the sourceRelDataType, and the same nullability as the targetRelDataType.static @Nullable RelDataType
leastRestrictiveForComparison
(RelDataTypeFactory typeFactory, RelDataType type1, RelDataType type2) Returns the least restrictive type T, such that a value of type T can be compared with values of typetype1
andtype2
using=
.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 int
maxPrecision
(int p0, int p1) Returns the larger of two precisions, treatingRelDataType.PRECISION_NOT_SPECIFIED
as infinity.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, @Nullable 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.
-
Constructor Details
-
SqlTypeUtil
public SqlTypeUtil()
-
-
Method Details
-
isCharTypeComparable
Checks whether two types or more are char comparable.- Returns:
- Returns true if all operands are of char type and if they are comparable, i.e. of the same charset and collation of same charset
-
isCharTypeComparable
public static boolean isCharTypeComparable(SqlCallBinding binding, List<SqlNode> operands, boolean throwOnFailure) Returns whether the operands to a call are char type-comparable.- Parameters:
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 failure- Returns:
- whether operands are valid
-
deriveCollectionQueryComponentType
public static RelDataType deriveCollectionQueryComponentType(SqlTypeName collectionType, RelDataType origin) Derives component type for ARRAY, MULTISET, MAP when input is sub-query.- Parameters:
origin
- original component type- Returns:
- component type
-
deriveAndCollectTypes
public static List<RelDataType> deriveAndCollectTypes(SqlValidator validator, SqlValidatorScope scope, List<? extends SqlNode> operands) Iterates over all operands, derives their types, and collects them into a list. -
deriveType
@API(since="1.26", status=EXPERIMENTAL) public static RelDataType deriveType(SqlCallBinding binding) Derives type of the call via its binding.- Parameters:
binding
- binding to derive the type from- Returns:
- datatype of the call
-
deriveType
@API(since="1.26", status=EXPERIMENTAL) public static RelDataType deriveType(SqlCallBinding binding, SqlNode node) Derives type of the given call under given binding.- Parameters:
binding
- binding to derive the type fromnode
- node type to derive- Returns:
- datatype of the given node
-
deriveType
@API(since="1.26", status=EXPERIMENTAL) public static List<RelDataType> deriveType(SqlCallBinding binding, List<? extends SqlNode> nodes) Derives types for the list of nodes.- Parameters:
binding
- binding to derive the type fromnodes
- the list of nodes to derive types from- Returns:
- the list of types of the given nodes
-
promoteToRowType
public static RelDataType promoteToRowType(RelDataTypeFactory typeFactory, RelDataType type, @Nullable String fieldName) Promotes a type to a row type (does nothing if it already is one).- Parameters:
type
- type to be promotedfieldName
- name to give field in row type; null for default of "ROW_VALUE"- Returns:
- row type
-
makeNullableIfOperandsAre
public 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. -
makeNullableIfOperandsAre
public static RelDataType makeNullableIfOperandsAre(RelDataTypeFactory typeFactory, List<RelDataType> argTypes, RelDataType type) Recreates a given RelDataType with nullability iff any of the param argTypes are nullable. -
allNullable
Returns whether all of array of types are nullable. -
containsNullable
Returns whether one or more of an array of types is nullable. -
containsNullable
Determines whether a type or any of its fields (if a structured type) are nullable. -
keepSourceTypeAndTargetNullability
public static RelDataType keepSourceTypeAndTargetNullability(RelDataType sourceRelDataType, RelDataType targetRelDataType, RelDataTypeFactory typeFactory) Creates a RelDataType having the same type of the sourceRelDataType, and the same nullability as the targetRelDataType. -
isOfSameTypeName
Returns typeName.equals(type.getSqlTypeName()). If typeName.equals(SqlTypeName.Any) true is always returned. -
isOfSameTypeName
Returns true if any element intypeNames
matches type.getSqlTypeName(). -
isDatetime
Returns whether a type is DATE, TIME, or TIMESTAMP. -
isDate
Returns whether a type is DATE. -
isTimestamp
Returns whether a type is TIMESTAMP. -
isInterval
@EnsuresNonNullIf(expression="#1.getIntervalQualifier()", result=true) public static boolean isInterval(RelDataType type) Returns whether a type is some kind of INTERVAL. -
inCharFamily
@EnsuresNonNullIf(expression="#1.getCharset()",result=true) @EnsuresNonNullIf(expression="#1.getCollation()",result=true) public static boolean inCharFamily(RelDataType type) Returns whether a type is in SqlTypeFamily.Character. -
inCharFamily
Returns whether a type name is in SqlTypeFamily.Character. -
inBooleanFamily
Returns whether a type is in SqlTypeFamily.Boolean. -
inSameFamily
Returns whether two types are in same type family. -
inSameFamilyOrNull
Returns whether two types are in same type family, or one or the other is of typeSqlTypeName.NULL
. -
inCharOrBinaryFamilies
Returns whether a type family is either character or binary. -
isLob
Returns whether a type is a LOB of some kind. -
isBoundedVariableWidth
Returns whether a type is variable width with bounded precision. -
isIntType
Returns whether a type is one of the integer types. -
isDecimal
Returns whether a type is DECIMAL. -
isExactNumeric
Returns whether a type is numeric with exact precision. -
hasScale
Returns whether a type's scale is set. -
maxValue
Returns the maximum value of an integral type, as a long value. -
isApproximateNumeric
Returns whether a type is numeric with approximate precision. -
isNumeric
Returns whether a type is numeric. -
isNull
Returns whether a type is the NULL type. -
sameNamedType
Tests whether two types have the same name and structure, possibly with differing modifiers. For example, VARCHAR(1) and VARCHAR(10) are considered the same, while VARCHAR(1) and CHAR(1) are considered different. Likewise, VARCHAR(1) MULTISET and VARCHAR(10) MULTISET are considered the same.- Returns:
- true if types have same name and structure
-
getMaxByteSize
Computes the maximum number of bytes required to represent a value of a type having user-defined precision. This computation assumes no overhead such as length indicators and NUL-terminators. Complex types for which multiple representations are possible (e.g. DECIMAL or TIMESTAMP) return 0.- Parameters:
type
- type for which to compute storage- Returns:
- maximum bytes, or 0 for a fixed-width type or type with unknown maximum
-
getMinValue
Returns the minimum unscaled value of a numeric type.- Parameters:
type
- a numeric type
-
getMaxValue
Returns the maximum unscaled value of a numeric type.- Parameters:
type
- a numeric type
-
isJavaPrimitive
Deprecated.Returns whether a type has a representation as a Java primitive (ignoring nullability). -
getPrimitiveWrapperJavaClassName
@Deprecated public static @Nullable String getPrimitiveWrapperJavaClassName(@Nullable RelDataType type) Deprecated.Returns the class name of the wrapper for the primitive data type. -
getNumericJavaClassName
Deprecated.Returns the class name of a numeric data type. -
isMeasure
-
canAssignFrom
Tests whether a value can be assigned to a site.- Parameters:
toType
- type of the target sitefromType
- type of the source value- Returns:
- true iff assignable
-
areCharacterSetsMismatched
Determines whether two types both have different character sets. If one or the other type has no character set (e.g. in cast from INT to VARCHAR), that is not a mismatch.- Parameters:
t1
- first typet2
- second type- Returns:
- true iff mismatched
-
canCastFrom
Compares two types and returns whetherfromType
can be cast totoType
, using either coercion or assignment.REVIEW jvs 17-Dec-2004: the coerce param below shouldn't really be necessary. We're using it as a hack because
SqlTypeFactoryImpl.leastRestrictive(java.util.List<org.apache.calcite.rel.type.RelDataType>, org.apache.calcite.sql.type.SqlTypeMappingRule)
isn't complete enough yet. Once it is, this param (and the non-coerce rules ofSqlTypeAssignmentRule
) should go away.- Parameters:
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.- Returns:
- whether cast is legal
-
canCastFrom
public static boolean canCastFrom(RelDataType toType, RelDataType fromType, SqlTypeMappingRule typeMappingRule) Compares two types and returns whetherfromType
can be cast totoType
.A type mapping rule (i.e.
SqlTypeCoercionRule
orSqlTypeAssignmentRule
) controls what types are allowed to be cast from/to.- Parameters:
toType
- target of assignmentfromType
- source of assignmenttypeMappingRule
- SqlTypeMappingRule- Returns:
- whether cast is legal
-
flattenRecordType
public static RelDataType flattenRecordType(RelDataTypeFactory typeFactory, RelDataType recordType, int @Nullable [] flatteningMap) Flattens a record type by recursively expanding any fields which are themselves record types. For each record type, a representative null value field is also prepended (with state NULL for a null value and FALSE for non-null), and all component types are asserted to be nullable, since SQL doesn't allow NOT NULL to be specified on attributes.- Parameters:
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())- Returns:
- flattened equivalent
-
needsNullIndicator
-
convertTypeToSpec
public static SqlDataTypeSpec convertTypeToSpec(RelDataType type, @Nullable String charSetName, int maxPrecision, int maxScale) Converts an instance of RelDataType to an instance of SqlDataTypeSpec.- Parameters:
type
- type descriptorcharSetName
- charSet namemaxPrecision
- The max allowed precision.maxScale
- max allowed scale- Returns:
- corresponding parse representation
-
convertTypeToSpec
Converts an instance of RelDataType to an instance of SqlDataTypeSpec.- Parameters:
type
- type descriptor- Returns:
- corresponding parse representation
-
createMultisetType
public static RelDataType createMultisetType(RelDataTypeFactory typeFactory, RelDataType type, boolean nullable) -
createArrayType
public static RelDataType createArrayType(RelDataTypeFactory typeFactory, RelDataType type, boolean nullable) -
createMapType
public static RelDataType createMapType(RelDataTypeFactory typeFactory, RelDataType keyType, RelDataType valueType, boolean nullable) -
createMapTypeFromRecord
Creates a MAP type from a record type. The record type must have exactly two fields. -
createRecordTypeFromMap
Creates a ROW type from a map type. The record type will have two fields. -
addCharsetAndCollation
Adds collation and charset to a character type, returns other types unchanged.- Parameters:
type
- TypetypeFactory
- Type factory- Returns:
- Type with added charset and collation, or unchanged type if it is not a char type.
-
equalSansNullability
public static boolean equalSansNullability(RelDataTypeFactory factory, RelDataType type1, RelDataType type2) Returns whether two types are equal, ignoring nullability.They need not come from the same factory.
- Parameters:
factory
- Type factorytype1
- First typetype2
- Second type- Returns:
- whether types are equal, ignoring nullability
-
equalSansNullability
This is a poorman'sequalSansNullability(RelDataTypeFactory, RelDataType, RelDataType)
.We assume that "not null" is represented in the type's digest as a trailing "NOT NULL" (case sensitive).
If you got a type factory,
equalSansNullability(RelDataTypeFactory, RelDataType, RelDataType)
is preferred.- Parameters:
type1
- First typetype2
- Second type- Returns:
- true if the types are equal or the only difference is nullability
-
equalAsCollectionSansNullability
public static boolean equalAsCollectionSansNullability(RelDataTypeFactory factory, RelDataType type1, RelDataType type2) Returns whether two collection types are equal, ignoring nullability.They need not come from the same factory.
- Parameters:
factory
- Type factorytype1
- First typetype2
- Second type- Returns:
- Whether types are equal, ignoring nullability
-
equalAsMapSansNullability
public static boolean equalAsMapSansNullability(RelDataTypeFactory factory, RelDataType type1, RelDataType type2) Returns whether two map types are equal, ignoring nullability.They need not come from the same factory.
- Parameters:
factory
- Type factorytype1
- First typetype2
- Second type- Returns:
- Whether types are equal, ignoring nullability
-
equalAsStructSansNullability
public static boolean equalAsStructSansNullability(RelDataTypeFactory factory, RelDataType type1, RelDataType type2, @Nullable SqlNameMatcher nameMatcher) Returns whether two struct types are equal, ignoring nullability.They do not need to come from the same factory.
- Parameters:
factory
- Type factorytype1
- First typetype2
- Second typenameMatcher
- Name matcher used to compare the field names, if null, the field names are also ignored- Returns:
- Whether types are equal, ignoring nullability
-
findField
Returns the ordinal of a given field in a record type, or -1 if the field is not found.The
fieldName
is always simple, if the field is nested within a record field, returns index of the outer field instead. i.g. for row type (a int, b (b1 bigint, b2 varchar(20) not null)), returns 1 for both simple name "b1" and "b2".- Parameters:
type
- Record typefieldName
- Name of field- Returns:
- Ordinal of field
-
projectTypes
public static List<RelDataType> projectTypes(RelDataType rowType, List<? extends Number> requiredFields) Selects data types of the specified fields from an input row type. This is useful when identifying data types of a function that is going to operate on inputs that are specified as field ordinals (e.g. aggregate calls).- Parameters:
rowType
- input row typerequiredFields
- ordinals of the projected fields- Returns:
- list of data types that are requested by requiredFields
-
createEmptyStructType
Records a struct type with no fields.- Parameters:
typeFactory
- Type factory- Returns:
- Struct type with no fields
-
isFlat
Returns whether a type is flat. It is not flat if it is a record type that has one or more fields that are themselves record types. -
isComparable
Returns whether two types are comparable. They need to be scalar types of the same family, or struct types whose fields are pairwise comparable. Note that types in the CHARACTER family are comparable with many other types (seecanConvertStringInCompare(org.apache.calcite.rel.type.RelDataTypeFamily)
).- Parameters:
type1
- First typetype2
- Second type- Returns:
- Whether types are comparable
-
leastRestrictiveForComparison
public static @Nullable RelDataType leastRestrictiveForComparison(RelDataTypeFactory typeFactory, RelDataType type1, RelDataType type2) Returns the least restrictive type T, such that a value of type T can be compared with values of typetype1
andtype2
using=
. -
family
-
areSameFamily
Returns whether all types in a collection have the same family, as determined byisSameFamily(RelDataType, RelDataType)
.- Parameters:
types
- Types to check- Returns:
- true if all types are of the same family
-
isUnicode
Checks whether a type represents Unicode character data.- Parameters:
type
- type to test- Returns:
- whether type represents Unicode character data
-
maxPrecision
public static int maxPrecision(int p0, int p1) Returns the larger of two precisions, treatingRelDataType.PRECISION_NOT_SPECIFIED
as infinity. -
comparePrecision
public static int comparePrecision(int p0, int p1) Returns whether a precision is greater or equal than another, treatingRelDataType.PRECISION_NOT_SPECIFIED
as infinity. -
isArray
Returns whether a type is ARRAY. -
isRow
Returns whether a type is ROW. -
isMap
Returns whether a type is MAP. -
isMultiset
Returns whether a type is MULTISET. -
isCollection
Returns whether a type is ARRAY or MULTISET. -
isCharacter
Returns whether a type is CHARACTER. -
hasCharactor
Deprecated.Returns whether a type is a CHARACTER or contains a CHARACTER type. -
hasCharacter
Returns whether a type is a CHARACTER or contains a CHARACTER type. -
isString
Returns whether a type is STRING. -
isBoolean
Returns whether a type is BOOLEAN. -
isBinary
Returns whether a type is BINARY. -
isAtomic
Returns whether a type is atomic (datetime, numeric, string or BOOLEAN). -
getMaxPrecisionScaleDecimal
Returns a DECIMAL type with the maximum precision for the current type system. -
extractLastNFields
public static RelDataType extractLastNFields(RelDataTypeFactory typeFactory, RelDataType type, int numToKeep) Keeps only the last N fields and returns the new struct type. -
canBeRepresentedExactly
Returns whether the decimal value can be represented without information loss using the specified type. For example, 1111.11 - cannot be represented exactly using DECIMAL(3, 1) since it overflows. - cannot be represented exactly using DECIMAL(6, 3) since it overflows. - cannot be represented exactly using DECIMAL(6, 1) since it requires rounding. - can be represented exactly using DECIMAL(6, 2)- Parameters:
value
- A decimal valuetoType
- A DECIMAL type.- Returns:
- whether the value is valid for the type
-
isValidDecimalValue
Returns whether the decimal value is valid for the type. For example, 1111.11 is not valid for DECIMAL(3, 1) since it overflows.- Parameters:
value
- Value of literaltoType
- Type of the literal- Returns:
- whether the value is valid for the type
-
fromMeasure
Strips MEASURE wrappers from a type.For example:
- "
INTEGER
" remains "INTEGER
"; - "
MEASURE<DECIMAL>
" becomes "DECIMAL
"; - "
(empno INTEGER NOT NULL, rating MEASURE<DECIMAL>)
" becomes "(empno INTEGER NOT NULL, rating DECIMAL)
".
- "
-
hasCharacter(RelDataType)