Package org.apache.calcite.sql.type
Enum SqlTypeName
- java.lang.Object
-
- java.lang.Enum<SqlTypeName>
-
- org.apache.calcite.sql.type.SqlTypeName
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<SqlTypeName>
public enum SqlTypeName extends java.lang.Enum<SqlTypeName>
Enumeration of the type names which can be used to construct a SQL type. Rationale for this class's existence (instead of just using the standard java.sql.Type ordinals):Types
does not include all SQL2003 data-types;- SqlTypeName provides a type-safe enumeration;
- SqlTypeName provides a place to hang extra information such as whether the type carries precision and scale.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SqlTypeName.Limit
Limit.private static interface
SqlTypeName.PrecScale
Flags indicating precision/scale combinations.
-
Enum Constant Summary
-
Field Summary
Fields Modifier and Type Field Description static java.util.List<SqlTypeName>
ALL_TYPES
static java.util.List<SqlTypeName>
APPROX_TYPES
static java.util.List<SqlTypeName>
BINARY_TYPES
static java.util.List<SqlTypeName>
BOOLEAN_TYPES
static java.util.List<SqlTypeName>
CHAR_TYPES
static java.util.List<SqlTypeName>
DATETIME_TYPES
static java.util.Set<SqlTypeName>
DAY_INTERVAL_TYPES
static int
DEFAULT_INTERVAL_FRACTIONAL_SECOND_PRECISION
static int
DEFAULT_INTERVAL_START_PRECISION
static java.util.List<SqlTypeName>
EXACT_TYPES
private SqlTypeFamily
family
static java.util.List<SqlTypeName>
FRACTIONAL_TYPES
static java.util.List<SqlTypeName>
INT_TYPES
static java.util.Set<SqlTypeName>
INTERVAL_TYPES
private static java.util.Map<java.lang.Integer,SqlTypeName>
JDBC_TYPE_TO_NAME
private int
jdbcOrdinal
static int
MAX_DATETIME_PRECISION
static int
MAX_INTERVAL_FRACTIONAL_SECOND_PRECISION
static int
MAX_INTERVAL_START_PRECISION
static int
MIN_INTERVAL_FRACTIONAL_SECOND_PRECISION
static int
MIN_INTERVAL_START_PRECISION
static java.util.List<SqlTypeName>
NUMERIC_TYPES
private int
signatures
Bitwise-or of flags indicating allowable precision/scale combinations.private boolean
special
Returns true if not of a "pure" standard sql type.static java.util.List<SqlTypeName>
STRING_TYPES
private static java.util.Map<java.lang.String,SqlTypeName>
VALUES_MAP
static java.util.Set<SqlTypeName>
YEAR_INTERVAL_TYPES
-
Constructor Summary
Constructors Modifier Constructor Description private
SqlTypeName(int signatures, boolean special, int jdbcType, SqlTypeFamily family)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
allowsNoPrecNoScale()
boolean
allowsPrec()
boolean
allowsPrecNoScale()
boolean
allowsPrecScale(boolean precision, boolean scale)
Returns whether this type can be specified with a given combination of precision and scale.boolean
allowsScale()
private static java.util.List<SqlTypeName>
combine(java.util.List<SqlTypeName> list0, java.util.List<SqlTypeName> list1)
SqlLiteral
createLiteral(java.lang.Object o, SqlParserPos pos)
static SqlTypeName
get(java.lang.String name)
Looks up a type name from its name.int
getDefaultScale()
org.apache.calcite.avatica.util.TimeUnit
getEndUnit()
ReturnsSECOND
for bothHOUR TO SECOND
andSECOND
.SqlTypeFamily
getFamily()
Gets the SqlTypeFamily containing this SqlTypeName.int
getJdbcOrdinal()
java.lang.Object
getLimit(boolean sign, SqlTypeName.Limit limit, boolean beyond, int precision, int scale)
Returns the limit of this datatype.int
getMinPrecision()
Returns the minimum precision (or length) allowed for this type, or -1 if precision/length are not applicable for this type.int
getMinScale()
Returns the minimum scale (or fractional second precision in the case of intervals) allowed for this type, or -1 if precision/length are not applicable for this type.java.lang.String
getName()
static SqlTypeName
getNameForJdbcType(int jdbcType)
Gets the SqlTypeName corresponding to a JDBC type.private java.math.BigDecimal
getNumericLimit(int radix, int exponent, boolean sign, SqlTypeName.Limit limit, boolean beyond)
org.apache.calcite.avatica.util.TimeUnit
getStartUnit()
ReturnsHOUR
forHOUR TO SECOND
andHOUR
,SECOND
forSECOND
.boolean
isSpecial()
boolean
isYearMonth()
static SqlTypeName
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static SqlTypeName[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
BOOLEAN
public static final SqlTypeName BOOLEAN
-
TINYINT
public static final SqlTypeName TINYINT
-
SMALLINT
public static final SqlTypeName SMALLINT
-
INTEGER
public static final SqlTypeName INTEGER
-
BIGINT
public static final SqlTypeName BIGINT
-
DECIMAL
public static final SqlTypeName DECIMAL
-
FLOAT
public static final SqlTypeName FLOAT
-
REAL
public static final SqlTypeName REAL
-
DOUBLE
public static final SqlTypeName DOUBLE
-
DATE
public static final SqlTypeName DATE
-
TIME
public static final SqlTypeName TIME
-
TIME_WITH_LOCAL_TIME_ZONE
public static final SqlTypeName TIME_WITH_LOCAL_TIME_ZONE
-
TIMESTAMP
public static final SqlTypeName TIMESTAMP
-
TIMESTAMP_WITH_LOCAL_TIME_ZONE
public static final SqlTypeName TIMESTAMP_WITH_LOCAL_TIME_ZONE
-
INTERVAL_YEAR
public static final SqlTypeName INTERVAL_YEAR
-
INTERVAL_YEAR_MONTH
public static final SqlTypeName INTERVAL_YEAR_MONTH
-
INTERVAL_MONTH
public static final SqlTypeName INTERVAL_MONTH
-
INTERVAL_DAY
public static final SqlTypeName INTERVAL_DAY
-
INTERVAL_DAY_HOUR
public static final SqlTypeName INTERVAL_DAY_HOUR
-
INTERVAL_DAY_MINUTE
public static final SqlTypeName INTERVAL_DAY_MINUTE
-
INTERVAL_DAY_SECOND
public static final SqlTypeName INTERVAL_DAY_SECOND
-
INTERVAL_HOUR
public static final SqlTypeName INTERVAL_HOUR
-
INTERVAL_HOUR_MINUTE
public static final SqlTypeName INTERVAL_HOUR_MINUTE
-
INTERVAL_HOUR_SECOND
public static final SqlTypeName INTERVAL_HOUR_SECOND
-
INTERVAL_MINUTE
public static final SqlTypeName INTERVAL_MINUTE
-
INTERVAL_MINUTE_SECOND
public static final SqlTypeName INTERVAL_MINUTE_SECOND
-
INTERVAL_SECOND
public static final SqlTypeName INTERVAL_SECOND
-
CHAR
public static final SqlTypeName CHAR
-
VARCHAR
public static final SqlTypeName VARCHAR
-
BINARY
public static final SqlTypeName BINARY
-
VARBINARY
public static final SqlTypeName VARBINARY
-
NULL
public static final SqlTypeName NULL
-
ANY
public static final SqlTypeName ANY
-
SYMBOL
public static final SqlTypeName SYMBOL
-
MULTISET
public static final SqlTypeName MULTISET
-
ARRAY
public static final SqlTypeName ARRAY
-
MAP
public static final SqlTypeName MAP
-
DISTINCT
public static final SqlTypeName DISTINCT
-
STRUCTURED
public static final SqlTypeName STRUCTURED
-
ROW
public static final SqlTypeName ROW
-
OTHER
public static final SqlTypeName OTHER
-
CURSOR
public static final SqlTypeName CURSOR
-
COLUMN_LIST
public static final SqlTypeName COLUMN_LIST
-
DYNAMIC_STAR
public static final SqlTypeName DYNAMIC_STAR
-
GEOMETRY
public static final SqlTypeName GEOMETRY
-
-
Field Detail
-
MAX_DATETIME_PRECISION
public static final int MAX_DATETIME_PRECISION
- See Also:
- Constant Field Values
-
DEFAULT_INTERVAL_START_PRECISION
public static final int DEFAULT_INTERVAL_START_PRECISION
- See Also:
- Constant Field Values
-
DEFAULT_INTERVAL_FRACTIONAL_SECOND_PRECISION
public static final int DEFAULT_INTERVAL_FRACTIONAL_SECOND_PRECISION
- See Also:
- Constant Field Values
-
MIN_INTERVAL_START_PRECISION
public static final int MIN_INTERVAL_START_PRECISION
- See Also:
- Constant Field Values
-
MIN_INTERVAL_FRACTIONAL_SECOND_PRECISION
public static final int MIN_INTERVAL_FRACTIONAL_SECOND_PRECISION
- See Also:
- Constant Field Values
-
MAX_INTERVAL_START_PRECISION
public static final int MAX_INTERVAL_START_PRECISION
- See Also:
- Constant Field Values
-
MAX_INTERVAL_FRACTIONAL_SECOND_PRECISION
public static final int MAX_INTERVAL_FRACTIONAL_SECOND_PRECISION
- See Also:
- Constant Field Values
-
VALUES_MAP
private static final java.util.Map<java.lang.String,SqlTypeName> VALUES_MAP
-
ALL_TYPES
public static final java.util.List<SqlTypeName> ALL_TYPES
-
BOOLEAN_TYPES
public static final java.util.List<SqlTypeName> BOOLEAN_TYPES
-
BINARY_TYPES
public static final java.util.List<SqlTypeName> BINARY_TYPES
-
INT_TYPES
public static final java.util.List<SqlTypeName> INT_TYPES
-
EXACT_TYPES
public static final java.util.List<SqlTypeName> EXACT_TYPES
-
APPROX_TYPES
public static final java.util.List<SqlTypeName> APPROX_TYPES
-
NUMERIC_TYPES
public static final java.util.List<SqlTypeName> NUMERIC_TYPES
-
FRACTIONAL_TYPES
public static final java.util.List<SqlTypeName> FRACTIONAL_TYPES
-
CHAR_TYPES
public static final java.util.List<SqlTypeName> CHAR_TYPES
-
STRING_TYPES
public static final java.util.List<SqlTypeName> STRING_TYPES
-
DATETIME_TYPES
public static final java.util.List<SqlTypeName> DATETIME_TYPES
-
YEAR_INTERVAL_TYPES
public static final java.util.Set<SqlTypeName> YEAR_INTERVAL_TYPES
-
DAY_INTERVAL_TYPES
public static final java.util.Set<SqlTypeName> DAY_INTERVAL_TYPES
-
INTERVAL_TYPES
public static final java.util.Set<SqlTypeName> INTERVAL_TYPES
-
JDBC_TYPE_TO_NAME
private static final java.util.Map<java.lang.Integer,SqlTypeName> JDBC_TYPE_TO_NAME
-
signatures
private final int signatures
Bitwise-or of flags indicating allowable precision/scale combinations.
-
special
private final boolean special
-
jdbcOrdinal
private final int jdbcOrdinal
-
family
private final SqlTypeFamily family
-
-
Constructor Detail
-
SqlTypeName
private SqlTypeName(int signatures, boolean special, int jdbcType, SqlTypeFamily family)
-
-
Method Detail
-
values
public static SqlTypeName[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (SqlTypeName c : SqlTypeName.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static SqlTypeName valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
get
public static SqlTypeName get(java.lang.String name)
Looks up a type name from its name.- Returns:
- Type name, or null if not found
-
allowsNoPrecNoScale
public boolean allowsNoPrecNoScale()
-
allowsPrecNoScale
public boolean allowsPrecNoScale()
-
allowsPrec
public boolean allowsPrec()
-
allowsScale
public boolean allowsScale()
-
allowsPrecScale
public boolean allowsPrecScale(boolean precision, boolean scale)
Returns whether this type can be specified with a given combination of precision and scale. For example,Varchar.allowsPrecScale(true, false)
returnstrue
, because the VARCHAR type allows a precision parameter, as inVARCHAR(10)
.Varchar.allowsPrecScale(true, true)
returnstrue
, because the VARCHAR type does not allow a precision and a scale parameter, as inVARCHAR(10, 4)
.allowsPrecScale(false, true)
returnsfalse
for every type.
- Parameters:
precision
- Whether the precision/length field is part of the type specificationscale
- Whether the scale field is part of the type specification- Returns:
- Whether this combination of precision/scale is valid
-
isSpecial
public boolean isSpecial()
-
getJdbcOrdinal
public int getJdbcOrdinal()
- Returns:
- the ordinal from
Types
corresponding to this SqlTypeName
-
combine
private static java.util.List<SqlTypeName> combine(java.util.List<SqlTypeName> list0, java.util.List<SqlTypeName> list1)
-
getDefaultScale
public int getDefaultScale()
- Returns:
- default scale for this type if supported, otherwise -1 if scale is either unsupported or must be specified explicitly
-
getFamily
public SqlTypeFamily getFamily()
Gets the SqlTypeFamily containing this SqlTypeName.- Returns:
- containing family, or null for none
-
getNameForJdbcType
public static SqlTypeName getNameForJdbcType(int jdbcType)
Gets the SqlTypeName corresponding to a JDBC type.- Parameters:
jdbcType
- the JDBC type of interest- Returns:
- corresponding SqlTypeName, or null if the type is not known
-
getLimit
public java.lang.Object getLimit(boolean sign, SqlTypeName.Limit limit, boolean beyond, int precision, int scale)
Returns the limit of this datatype. For example,Datatype limits Datatype sign limit beyond precision scale Returns Integer true true false -1 -1 2147483647 (2 ^ 31 -1 = MAXINT) Integer true true true -1 -1 2147483648 (2 ^ 31 = MAXINT + 1) Integer false true false -1 -1 -2147483648 (-2 ^ 31 = MININT) Boolean true true false -1 -1 TRUE Varchar true true false 10 -1 'ZZZZZZZZZZ' - Parameters:
sign
- If true, returns upper limit, otherwise lower limitlimit
- If true, returns value at or near to overflow; otherwise value at or near to underflowbeyond
- If true, returns the value just beyond the limit, otherwise the value at the limitprecision
- Precision, or -1 if not applicablescale
- Scale, or -1 if not applicable- Returns:
- Limit value
-
getMinPrecision
public int getMinPrecision()
Returns the minimum precision (or length) allowed for this type, or -1 if precision/length are not applicable for this type.- Returns:
- Minimum allowed precision
-
getMinScale
public int getMinScale()
Returns the minimum scale (or fractional second precision in the case of intervals) allowed for this type, or -1 if precision/length are not applicable for this type.- Returns:
- Minimum allowed scale
-
getStartUnit
public org.apache.calcite.avatica.util.TimeUnit getStartUnit()
ReturnsHOUR
forHOUR TO SECOND
andHOUR
,SECOND
forSECOND
.
-
getEndUnit
public org.apache.calcite.avatica.util.TimeUnit getEndUnit()
ReturnsSECOND
for bothHOUR TO SECOND
andSECOND
.
-
isYearMonth
public boolean isYearMonth()
-
getNumericLimit
private java.math.BigDecimal getNumericLimit(int radix, int exponent, boolean sign, SqlTypeName.Limit limit, boolean beyond)
-
createLiteral
public SqlLiteral createLiteral(java.lang.Object o, SqlParserPos pos)
-
getName
public java.lang.String getName()
- Returns:
- name of this type
-
-