use of org.apache.calcite.rel.type.RelDataTypeFactory in project calcite by apache.
the class RexSubQuery method exists.
/**
* Creates an EXISTS sub-query.
*/
public static RexSubQuery exists(RelNode rel) {
final RelDataTypeFactory typeFactory = rel.getCluster().getTypeFactory();
final RelDataType type = typeFactory.createSqlType(SqlTypeName.BOOLEAN);
return new RexSubQuery(type, SqlStdOperatorTable.EXISTS, ImmutableList.<RexNode>of(), rel);
}
use of org.apache.calcite.rel.type.RelDataTypeFactory in project calcite by apache.
the class RexSubQuery method scalar.
/**
* Creates a scalar sub-query.
*/
public static RexSubQuery scalar(RelNode rel) {
final List<RelDataTypeField> fieldList = rel.getRowType().getFieldList();
assert fieldList.size() == 1;
final RelDataTypeFactory typeFactory = rel.getCluster().getTypeFactory();
final RelDataType type = typeFactory.createTypeWithNullability(fieldList.get(0).getType(), true);
return new RexSubQuery(type, SqlStdOperatorTable.SCALAR_QUERY, ImmutableList.<RexNode>of(), rel);
}
use of org.apache.calcite.rel.type.RelDataTypeFactory in project calcite by apache.
the class RexSubQuery method type.
static RelDataType type(RelNode rel, ImmutableList<RexNode> nodes) {
assert rel.getRowType().getFieldCount() == nodes.size();
final RelDataTypeFactory typeFactory = rel.getCluster().getTypeFactory();
boolean nullable = false;
for (RexNode node : nodes) {
if (node.getType().isNullable()) {
nullable = true;
}
}
for (RelDataTypeField field : rel.getRowType().getFieldList()) {
if (field.getType().isNullable()) {
nullable = true;
}
}
return typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BOOLEAN), nullable);
}
use of org.apache.calcite.rel.type.RelDataTypeFactory in project calcite by apache.
the class SqlDataTypeSpec method deriveType.
/**
* Throws an error if the type is not built-in.
*/
public RelDataType deriveType(SqlValidator validator) {
String name = typeName.getSimple();
// for now we only support builtin datatypes
if (SqlTypeName.get(name) == null) {
throw validator.newValidationError(this, RESOURCE.unknownDatatypeName(name));
}
if (null != collectionsTypeName) {
final String collectionName = collectionsTypeName.getSimple();
if (SqlTypeName.get(collectionName) == null) {
throw validator.newValidationError(this, RESOURCE.unknownDatatypeName(collectionName));
}
}
RelDataTypeFactory typeFactory = validator.getTypeFactory();
return deriveType(typeFactory);
}
use of org.apache.calcite.rel.type.RelDataTypeFactory in project calcite by apache.
the class RelOptUtilTest method testTypeDump.
// ~ Methods ----------------------------------------------------------------
@Test
public void testTypeDump() {
RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
RelDataType t1 = typeFactory.builder().add("f0", SqlTypeName.DECIMAL, 5, 2).add("f1", SqlTypeName.VARCHAR, 10).build();
TestUtil.assertEqualsVerbose(TestUtil.fold("f0 DECIMAL(5, 2) NOT NULL,", "f1 VARCHAR(10) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL"), Util.toLinux(RelOptUtil.dumpType(t1) + "\n"));
RelDataType t2 = typeFactory.builder().add("f0", t1).add("f1", typeFactory.createMultisetType(t1, -1)).build();
TestUtil.assertEqualsVerbose(TestUtil.fold("f0 RECORD (", " f0 DECIMAL(5, 2) NOT NULL,", " f1 VARCHAR(10) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL) NOT NULL,", "f1 RECORD (", " f0 DECIMAL(5, 2) NOT NULL,", " f1 VARCHAR(10) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL) NOT NULL MULTISET NOT NULL"), Util.toLinux(RelOptUtil.dumpType(t2) + "\n"));
}
Aggregations