Search in sources :

Example 36 with RelDataTypeField

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.

the class SqlDotOperator method deriveType.

@Override
public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call) {
    RelDataType nodeType = validator.deriveType(scope, call.getOperandList().get(0));
    assert nodeType != null;
    final String fieldName = call.getOperandList().get(1).toString();
    RelDataTypeField field = nodeType.getField(fieldName, false, false);
    if (field == null) {
        throw SqlUtil.newContextException(SqlParserPos.ZERO, Static.RESOURCE.unknownField(fieldName));
    }
    RelDataType type = field.getType();
    // Validate and determine coercibility and resulting collation
    // name of binary operator if needed.
    type = adjustType(validator, call, type);
    SqlValidatorUtil.checkCharsetAndCollateConsistentIfCharType(type);
    return type;
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 37 with RelDataTypeField

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.

the class MockCatalogReader method deduceMonotonicity.

private static List<RelCollation> deduceMonotonicity(Prepare.PreparingTable table) {
    final List<RelCollation> collationList = Lists.newArrayList();
    // Deduce which fields the table is sorted on.
    int i = -1;
    for (RelDataTypeField field : table.getRowType().getFieldList()) {
        ++i;
        final SqlMonotonicity monotonicity = table.getMonotonicity(field.getName());
        if (monotonicity != SqlMonotonicity.NOT_MONOTONIC) {
            final RelFieldCollation.Direction direction = monotonicity.isDecreasing() ? RelFieldCollation.Direction.DESCENDING : RelFieldCollation.Direction.ASCENDING;
            collationList.add(RelCollations.of(new RelFieldCollation(i, direction)));
        }
    }
    return collationList;
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) SqlMonotonicity(org.apache.calcite.sql.validate.SqlMonotonicity) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) RelReferentialConstraint(org.apache.calcite.rel.RelReferentialConstraint)

Example 38 with RelDataTypeField

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.

the class RelBuilderTest method testAlias.

@Test
public void testAlias() {
    // Equivalent SQL:
    // SELECT *
    // FROM emp AS e, dept
    // WHERE e.deptno = dept.deptno
    final RelBuilder builder = RelBuilder.create(config().build());
    RelNode root = builder.scan("EMP").as("e").scan("DEPT").join(JoinRelType.LEFT).filter(builder.equals(builder.field("e", "DEPTNO"), builder.field("DEPT", "DEPTNO"))).project(builder.field("e", "ENAME"), builder.field("DEPT", "DNAME")).build();
    final String expected = "LogicalProject(ENAME=[$1], DNAME=[$9])\n" + "  LogicalFilter(condition=[=($7, $8)])\n" + "    LogicalJoin(condition=[true], joinType=[left])\n" + "      LogicalTableScan(table=[[scott, EMP]])\n" + "      LogicalTableScan(table=[[scott, DEPT]])\n";
    assertThat(root, hasTree(expected));
    final RelDataTypeField field = root.getRowType().getFieldList().get(1);
    assertThat(field.getName(), is("DNAME"));
    assertThat(field.getType().isNullable(), is(true));
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelBuilder(org.apache.calcite.tools.RelBuilder) RelNode(org.apache.calcite.rel.RelNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 39 with RelDataTypeField

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.

the class SqlTesterImpl method getColumnType.

public RelDataType getColumnType(String sql) {
    RelDataType rowType = getResultType(sql);
    final List<RelDataTypeField> fields = rowType.getFieldList();
    assertEquals("expected query to return 1 field", 1, fields.size());
    return fields.get(0).getType();
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 40 with RelDataTypeField

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.

the class GeodeUtils method handleJavaObjectEntry.

private static Object handleJavaObjectEntry(List<RelDataTypeField> relDataTypeFields, Object obj) {
    Class<?> clazz = obj.getClass();
    if (relDataTypeFields.size() == 1) {
        try {
            Field javaField = clazz.getDeclaredField(relDataTypeFields.get(0).getName());
            javaField.setAccessible(true);
            return javaField.get(obj);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    Object[] values = new Object[relDataTypeFields.size()];
    int index = 0;
    for (RelDataTypeField relDataTypeField : relDataTypeFields) {
        try {
            Field javaField = clazz.getDeclaredField(relDataTypeField.getName());
            javaField.setAccessible(true);
            values[index++] = javaField.get(obj);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return values;
}
Also used : Field(java.lang.reflect.Field) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) CacheClosedException(org.apache.geode.cache.CacheClosedException)

Aggregations

RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)388 RelDataType (org.apache.calcite.rel.type.RelDataType)210 RexNode (org.apache.calcite.rex.RexNode)185 ArrayList (java.util.ArrayList)179 RelNode (org.apache.calcite.rel.RelNode)130 RexBuilder (org.apache.calcite.rex.RexBuilder)76 RexInputRef (org.apache.calcite.rex.RexInputRef)72 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)65 Pair (org.apache.calcite.util.Pair)55 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)47 HashMap (java.util.HashMap)39 Map (java.util.Map)35 AggregateCall (org.apache.calcite.rel.core.AggregateCall)35 SqlNode (org.apache.calcite.sql.SqlNode)32 ImmutableList (com.google.common.collect.ImmutableList)31 RelBuilder (org.apache.calcite.tools.RelBuilder)29 RelDataTypeFieldImpl (org.apache.calcite.rel.type.RelDataTypeFieldImpl)26 List (java.util.List)23 LinkedHashSet (java.util.LinkedHashSet)22 RelOptUtil (org.apache.calcite.plan.RelOptUtil)22