Search in sources :

Example 36 with RelDataTypeFactory

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);
}
Also used : RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 37 with RelDataTypeFactory

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);
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 38 with RelDataTypeFactory

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);
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory)

Example 39 with RelDataTypeFactory

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);
}
Also used : RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory)

Example 40 with RelDataTypeFactory

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"));
}
Also used : SqlTypeFactoryImpl(org.apache.calcite.sql.type.SqlTypeFactoryImpl) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) Test(org.junit.Test)

Aggregations

RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)128 RelDataType (org.apache.calcite.rel.type.RelDataType)97 RexNode (org.apache.calcite.rex.RexNode)47 RexBuilder (org.apache.calcite.rex.RexBuilder)38 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)30 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)20 RelNode (org.apache.calcite.rel.RelNode)20 AggregateCall (org.apache.calcite.rel.core.AggregateCall)15 SqlNode (org.apache.calcite.sql.SqlNode)14 SqlTypeFactoryImpl (org.apache.calcite.sql.type.SqlTypeFactoryImpl)14 BigDecimal (java.math.BigDecimal)12 List (java.util.List)10 RelDataTypeFactory (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeFactory)8 SqlAggFunction (org.apache.calcite.sql.SqlAggFunction)8 SqlTypeName (org.apache.calcite.sql.type.SqlTypeName)8 Calendar (java.util.Calendar)7 RexInputRef (org.apache.calcite.rex.RexInputRef)7 Pair (org.apache.calcite.util.Pair)7 TimestampString (org.apache.calcite.util.TimestampString)7