|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eigenbase.sql.type.SqlTypeUtil
public abstract class SqlTypeUtil
Contains utility methods used during SQL validation or type derivation.
Nested Class Summary | |
---|---|
static class |
SqlTypeUtil.TypeBuilder
Convenience class for building a struct type with several fields. |
Constructor Summary | |
---|---|
SqlTypeUtil()
|
Method Summary | |
---|---|
static RelDataType |
addCharsetAndCollation(RelDataType type,
RelDataTypeFactory typeFactory)
Adds collation and charset to a character type, returns other types unchanged. |
static RelDataType |
addField(RelDataTypeFactory typeFactory,
RelDataType type,
int at,
String fieldName,
RelDataType fieldType)
Adds a field to a record type at a specified position. |
static boolean |
areCharacterSetsMismatched(RelDataType t1,
RelDataType t2)
Determines whether two types both have different character sets. |
static boolean |
canAssignFrom(RelDataType toType,
RelDataType fromType)
Tests assignability of a value 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 RelDataType[] |
collectTypes(RelNode[] rels)
Collects the row types of an array of relational expressions. |
static boolean |
containsNullable(RelDataType type)
Determines whether a type or any of its fields (if a structured type) are nullable. |
static boolean |
containsNullable(RelDataType[] types)
Returns whether one or more of an array of types is nullable. |
static SqlDataTypeSpec |
convertTypeToSpec(RelDataType type)
Converts an instance of RelDataType to an instance of SqlDataTypeSpec. |
static RelDataType |
createEmptyStructType(RelDataTypeFactory typeFactory)
Records a struct type with no fields. |
static RelDataType |
createMultisetType(RelDataTypeFactory typeFactory,
RelDataType type,
boolean nullable)
|
static RelDataType |
createStructType(RelDataTypeFactory typeFactory,
RelDataType[] types)
Creates a record type with anonymous field names. |
static RelDataType[] |
deriveAndCollectTypes(SqlValidator validator,
SqlValidatorScope scope,
SqlNode[] operands)
Iterates over all operands, derives their types, and collects them into an array. |
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. |
private static boolean |
flattenFields(RelDataTypeFactory typeFactory,
RelDataType type,
List<RelDataTypeField> list,
int[] flatteningMap)
|
static RelDataType |
flattenRecordType(RelDataTypeFactory typeFactory,
RelDataType recordType,
int[] flatteningMap)
Flattens a record type by recursively expanding any fields which are themselves record types. |
static String[] |
getFieldNames(RelDataType type)
|
static RelDataType[] |
getFieldTypes(RelDataType 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 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(RelDataType[] argTypes)
Checks whether two types or more are char comparable. |
static boolean |
isCharTypeComparable(RelDataType[] argTypes,
int start,
int stop)
|
static boolean |
isCharTypeComparable(SqlCallBinding binding,
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 |
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(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,
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 nullablility iff any of a calls operand types 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 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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SqlTypeUtil()
Method Detail |
---|
public static boolean isCharTypeComparable(RelDataType[] argTypes)
public static boolean isCharTypeComparable(RelDataType[] argTypes, int start, int stop)
start
- zero based indexstop
- zero based indexpublic static boolean isCharTypeComparable(SqlCallBinding binding, 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 failure
public static RelDataType[] deriveAndCollectTypes(SqlValidator validator, SqlValidatorScope scope, SqlNode[] operands)
public static RelDataType[] collectTypes(RelNode[] rels)
rels
- array of relational expressions
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, RelDataType[] argTypes, RelDataType type)
public static boolean containsNullable(RelDataType[] types)
public static boolean containsNullable(RelDataType type)
public static boolean isOfSameTypeName(SqlTypeName typeName, RelDataType type)
public static boolean isOfSameTypeName(SqlTypeName[] typeNames, RelDataType type)
typeNames
matches
type.getSqlTypeName().
isOfSameTypeName(SqlTypeName, RelDataType)
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)
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 storage
public 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 value
public static boolean areCharacterSetsMismatched(RelDataType t1, RelDataType t2)
t1
- first typet2
- second type
public 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(org.eigenbase.reltype.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 String[] getFieldNames(RelDataType type)
public static RelDataType[] getFieldTypes(RelDataType type)
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 RelDataType createStructType(RelDataTypeFactory typeFactory, RelDataType[] types)
public static boolean needsNullIndicator(RelDataType recordType)
private static boolean flattenFields(RelDataTypeFactory typeFactory, RelDataType type, List<RelDataTypeField> list, int[] flatteningMap)
public static SqlDataTypeSpec convertTypeToSpec(RelDataType type)
type
- type descriptor
public static RelDataType createMultisetType(RelDataTypeFactory typeFactory, RelDataType type, boolean nullable)
public static RelDataType addCharsetAndCollation(RelDataType type, RelDataTypeFactory typeFactory)
type
- TypetypeFactory
- Type factory
public static boolean equalSansNullability(RelDataTypeFactory factory, RelDataType type1, RelDataType type2)
They need not come from the same factory.
factory
- Type factorytype1
- First typetype2
- Second type
public static RelDataType addField(RelDataTypeFactory typeFactory, RelDataType type, int at, String fieldName, RelDataType fieldType)
For example, if type is (A integer, B boolean)
, and
fieldType is varchar(10)
, then prepend(typeFactory,
type, 0, "Z", fieldType)
will return (Z varchar(10), A
integer, B boolean)
.
typeFactory
- Type factorytype
- Record typeat
- Ordinal to add fieldfieldName
- Name of new fieldfieldType
- Type of new field
public static int findField(RelDataType type, String fieldName)
type
- Record typefieldName
- Name of field
public static RelDataType createEmptyStructType(RelDataTypeFactory typeFactory)
typeFactory
- Type factory
public static boolean isComparable(RelDataType type1, RelDataType type2)
type1
- First typetype2
- Second type
public static boolean isUnicode(RelDataType type)
type
- type to test
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |