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 |
allNullable(List<RelDataType> types)
Returns whether all of array of types are nullable.
|
static boolean |
areCharacterSetsMismatched(RelDataType t1,
RelDataType t2)
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 by
isSameFamily(RelDataType, RelDataType). |
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 int |
comparePrecision(int p0,
int p1)
Returns whether a precision is greater or equal than another,
treating
RelDataType.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 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's
equalSansNullability(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[] 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 RelDataType |
getMaxPrecisionScaleDecimal(RelDataTypeFactory factory)
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 |
inCharOrBinaryFamilies(RelDataType type)
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 type
SqlTypeName.NULL. |
static boolean |
isApproximateNumeric(RelDataType type)
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 |
isBigint(RelDataType type)
Returns whether a type is BIGINT.
|
static boolean |
isBinary(RelDataType type)
Returns whether a type is BINARY.
|
static boolean |
isBoolean(RelDataType type)
Returns whether a type is BOOLEAN.
|
static boolean |
isBoundedVariableWidth(RelDataType type)
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 |
isDouble(RelDataType type)
Returns whether a type is DOUBLE.
|
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 |
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 in
typeNames 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 type
type1 and type2 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, treating
RelDataType.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.
|
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 RelDataType deriveCollectionQueryComponentType(SqlTypeName collectionType, RelDataType origin)
origin - original component typepublic static List<RelDataType> deriveAndCollectTypes(SqlValidator validator, SqlValidatorScope scope, List<? extends SqlNode> operands)
@API(since="1.26",
status=EXPERIMENTAL)
public static RelDataType deriveType(SqlCallBinding binding)
binding - binding to derive the type from@API(since="1.26",
status=EXPERIMENTAL)
public static RelDataType deriveType(SqlCallBinding binding,
SqlNode node)
binding - binding to derive the type fromnode - node type to derive@API(since="1.26",
status=EXPERIMENTAL)
public static List<RelDataType> deriveType(SqlCallBinding binding,
List<? extends SqlNode> nodes)
binding - binding to derive the type fromnodes - the list of nodes to derive types frompublic static RelDataType promoteToRowType(RelDataTypeFactory typeFactory, RelDataType type, @Nullable 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 allNullable(List<RelDataType> types)
public static boolean containsNullable(List<RelDataType> types)
public static boolean containsNullable(RelDataType type)
public static RelDataType keepSourceTypeAndTargetNullability(RelDataType sourceRelDataType, RelDataType targetRelDataType, RelDataTypeFactory typeFactory)
public static boolean isOfSameTypeName(SqlTypeName typeName, RelDataType type)
public static boolean isOfSameTypeName(Collection<SqlTypeName> typeNames, RelDataType type)
typeNames matches
type.getSqlTypeName().public static boolean isDatetime(RelDataType type)
public static boolean isDate(RelDataType type)
public static boolean isTimestamp(RelDataType type)
@EnsuresNonNullIf(expression="#1.getIntervalQualifier()",
result=true)
public static boolean isInterval(RelDataType type)
@EnsuresNonNullIf(expression="#1.getCharset()",result=true) @EnsuresNonNullIf(expression="#1.getCollation()",result=true) 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 isDouble(RelDataType type)
public static boolean isBigint(RelDataType type)
public static boolean isExactNumeric(RelDataType type)
public static boolean hasScale(RelDataType type)
public static long maxValue(RelDataType type)
public static boolean isApproximateNumeric(RelDataType type)
public static boolean isNumeric(RelDataType type)
public static boolean isNull(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 type@Deprecated public static boolean isJavaPrimitive(RelDataType type)
@Deprecated public static @Nullable String getPrimitiveWrapperJavaClassName(@Nullable RelDataType type)
@Deprecated public static @Nullable String getNumericJavaClassName(@Nullable 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.leastRestrictive(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
SqlTypeAssignmentRule) 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, @Nullable String charSetName, int maxPrecision, int maxScale)
type - type descriptorcharSetName - charSet namemaxPrecision - The max allowed precision.maxScale - max allowed scalepublic 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 createMapTypeFromRecord(RelDataTypeFactory typeFactory, RelDataType type)
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 boolean equalSansNullability(RelDataType type1, RelDataType type2)
equalSansNullability(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.
type1 - First typetype2 - Second typepublic static boolean equalAsCollectionSansNullability(RelDataTypeFactory factory, RelDataType type1, RelDataType type2)
They need not come from the same factory.
factory - Type factorytype1 - First typetype2 - Second typepublic static boolean equalAsMapSansNullability(RelDataTypeFactory factory, RelDataType type1, RelDataType type2)
They need not come from the same factory.
factory - Type factorytype1 - First typetype2 - Second typepublic static boolean equalAsStructSansNullability(RelDataTypeFactory factory, RelDataType type1, RelDataType type2, @Nullable SqlNameMatcher nameMatcher)
They do not need to come from the same factory.
factory - Type factorytype1 - First typetype2 - Second typenameMatcher - Name matcher used to compare the field names, if null,
the field names are also ignoredpublic static int findField(RelDataType type, String fieldName)
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".
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 @Nullable RelDataType leastRestrictiveForComparison(RelDataTypeFactory typeFactory, RelDataType type1, RelDataType type2)
type1 and type2 using
=.protected static RelDataTypeFamily family(RelDataType type)
public static boolean areSameFamily(Iterable<RelDataType> types)
isSameFamily(RelDataType, RelDataType).types - Types to checkpublic static boolean isUnicode(RelDataType type)
type - type to testpublic static int maxPrecision(int p0,
int p1)
RelDataType.PRECISION_NOT_SPECIFIED as infinity.public static int comparePrecision(int p0,
int p1)
RelDataType.PRECISION_NOT_SPECIFIED as infinity.public static boolean isArray(RelDataType type)
public static boolean isRow(RelDataType type)
public static boolean isMap(RelDataType type)
public static boolean isMultiset(RelDataType type)
public static boolean isCollection(RelDataType type)
public static boolean isCharacter(RelDataType type)
@Deprecated public static boolean hasCharactor(RelDataType type)
hasCharacter(RelDataType)public static boolean hasCharacter(RelDataType type)
public static boolean isString(RelDataType type)
public static boolean isBoolean(RelDataType type)
public static boolean isBinary(RelDataType type)
public static boolean isAtomic(RelDataType type)
public static RelDataType getMaxPrecisionScaleDecimal(RelDataTypeFactory factory)
public static RelDataType extractLastNFields(RelDataTypeFactory typeFactory, RelDataType type, int numToKeep)
public static boolean isValidDecimalValue(@Nullable BigDecimal value, RelDataType toType)
value - Value of literaltoType - Type of the literalCopyright © 2012-2022 Apache Software Foundation. All Rights Reserved.