org.eigenbase.sql.type
Class SqlTypeUtil.TypeBuilder
java.lang.Object
org.eigenbase.sql.type.SqlTypeUtil.TypeBuilder
- Enclosing class:
- SqlTypeUtil
public static class SqlTypeUtil.TypeBuilder
- extends Object
Convenience class for building a struct type with several fields.
TypeBuilder is more convenient because it supports chained calls to
add one field at a time. The chained syntax means that you can use a
TypeBuilder in contexts where only an expression is allowed, for example
in a field initializer. There are several overloadings of the
add
method for types which take different parameters, and you can
explicitly state whether you want a field to be nullable.
For example, to create the type
(A BOOLEAN NOT NULL, B VARCHAR(10), C DECIMAL(6,2))
the code is
RelDataTypeFactory typeFactory;
return new TypeBuilder(typeFactory)
.add("A", SqlTypeName.BOOLEAN, false)
.add("B", SqlTypeName.VARCHAR(10), true)
.add("C", SqlTypeName.DECIMAL, 6, 2, false)
.type();
The equivalent conventional code is:
RelDataTypeFactory typeFactory;
String[] names = {"A", "B", "C"};
RelDataType[] types = {
typeFactory.createSqlType(SqlTypeName.BOOLEAN),
typeFactory.createTypeWithNullability(
typeFactory.createSqlType(SqlTypeName.VARCHAR, 10),
true),
typeFactory.createSqlType(SqlTypeName.DECIMAL, 6, 2)
};
return typeFactory.createStructType(names, types);
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
fieldList
private final List<RelDataTypeFieldImpl> fieldList
typeFactory
private final RelDataTypeFactory typeFactory
SqlTypeUtil.TypeBuilder
public SqlTypeUtil.TypeBuilder(RelDataTypeFactory typeFactory)
add
public SqlTypeUtil.TypeBuilder add(String name,
SqlTypeName typeName,
boolean nullable)
add
public SqlTypeUtil.TypeBuilder add(String name,
SqlTypeName typeName,
int precision,
boolean nullable)
add
public SqlTypeUtil.TypeBuilder add(String name,
SqlTypeName typeName,
int precision,
int scale,
boolean nullable)
type
public RelDataType type()