Search in sources :

Example 6 with RelDataType

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

the class RelNodeCompiler method visitProject.

@Override
public Void visitProject(Project project, List<Void> inputStreams) throws Exception {
    beginStage(project);
    List<RexNode> childExps = project.getChildExps();
    RelDataType inputRowType = project.getInput(0).getRowType();
    int outputCount = project.getRowType().getFieldCount();
    pw.print("Context context = new StormContext(Processor.dataContext);\n");
    pw.print("context.values = _data.toArray();\n");
    pw.print(String.format("Object[] outputValues = new Object[%d];\n", outputCount));
    pw.write(rexCompiler.compileToBlock(childExps, inputRowType).toString());
    pw.print("    ctx.emit(new Values(outputValues));\n");
    endStage();
    return null;
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType) RexNode(org.apache.calcite.rex.RexNode)

Example 7 with RelDataType

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

the class FlinkRelDecorrelator method getNewForOldInputRef.

private RexInputRef getNewForOldInputRef(RexInputRef oldInputRef) {
    assert currentRel != null;
    int oldOrdinal = oldInputRef.getIndex();
    int newOrdinal = 0;
    // determine which input rel oldOrdinal references, and adjust
    // oldOrdinal to be relative to that input rel
    RelNode oldInput = null;
    for (RelNode oldInput0 : currentRel.getInputs()) {
        RelDataType oldInputType = oldInput0.getRowType();
        int n = oldInputType.getFieldCount();
        if (oldOrdinal < n) {
            oldInput = oldInput0;
            break;
        }
        RelNode newInput = map.get(oldInput0).r;
        newOrdinal += newInput.getRowType().getFieldCount();
        oldOrdinal -= n;
    }
    assert oldInput != null;
    final Frame frame = map.get(oldInput);
    assert frame != null;
    // now oldOrdinal is relative to oldInput
    int oldLocalOrdinal = oldOrdinal;
    // figure out the newLocalOrdinal, relative to the newInput.
    int newLocalOrdinal = oldLocalOrdinal;
    if (!frame.oldToNewOutputPos.isEmpty()) {
        newLocalOrdinal = frame.oldToNewOutputPos.get(oldLocalOrdinal);
    }
    newOrdinal += newLocalOrdinal;
    return new RexInputRef(newOrdinal, frame.r.getRowType().getFieldList().get(newLocalOrdinal).getType());
}
Also used : RelNode(org.apache.calcite.rel.RelNode) RexInputRef(org.apache.calcite.rex.RexInputRef) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 8 with RelDataType

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project druid by druid-io.

the class RowSignature method getRelDataType.

/**
   * Returns a Calcite RelDataType corresponding to this row signature.
   *
   * @param typeFactory factory for type construction
   *
   * @return Calcite row type
   */
public RelDataType getRelDataType(final RelDataTypeFactory typeFactory) {
    final RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
    for (final String columnName : columnNames) {
        final ValueType columnType = getColumnType(columnName);
        final RelDataType type;
        if (Column.TIME_COLUMN_NAME.equals(columnName)) {
            type = typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
        } else {
            switch(columnType) {
                case STRING:
                    // Note that there is no attempt here to handle multi-value in any special way. Maybe one day...
                    type = typeFactory.createTypeWithCharsetAndCollation(typeFactory.createSqlType(SqlTypeName.VARCHAR), Calcites.defaultCharset(), SqlCollation.IMPLICIT);
                    break;
                case LONG:
                    type = typeFactory.createSqlType(SqlTypeName.BIGINT);
                    break;
                case FLOAT:
                    type = typeFactory.createSqlType(SqlTypeName.FLOAT);
                    break;
                case COMPLEX:
                    // Loses information about exactly what kind of complex column this is.
                    type = typeFactory.createSqlType(SqlTypeName.OTHER);
                    break;
                default:
                    throw new ISE("WTF?! valueType[%s] not translatable?", columnType);
            }
        }
        builder.add(columnName, type);
    }
    return builder.build();
}
Also used : ValueType(io.druid.segment.column.ValueType) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) ISE(io.druid.java.util.common.ISE)

Example 9 with RelDataType

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project druid by druid-io.

the class DruidQueryBuilder method fullScan.

public static DruidQueryBuilder fullScan(final RowSignature rowSignature, final RelDataTypeFactory relDataTypeFactory) {
    final RelDataType rowType = rowSignature.getRelDataType(relDataTypeFactory);
    final List<String> rowOrder = rowSignature.getRowOrder();
    return new DruidQueryBuilder(null, null, null, null, null, rowType, rowOrder);
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 10 with RelDataType

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

the class AvroDrillTable method getRowType.

@Override
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
    List<RelDataType> typeList = Lists.newArrayList();
    List<String> fieldNameList = Lists.newArrayList();
    Schema schema = reader.getSchema();
    for (Field field : schema.getFields()) {
        fieldNameList.add(field.name());
        typeList.add(getNullableRelDataTypeFromAvroType(typeFactory, field.schema()));
    }
    return typeFactory.createStructType(typeList, fieldNameList);
}
Also used : Field(org.apache.avro.Schema.Field) Schema(org.apache.avro.Schema) RelDataType(org.apache.calcite.rel.type.RelDataType)

Aggregations

RelDataType (org.apache.calcite.rel.type.RelDataType)834 RexNode (org.apache.calcite.rex.RexNode)268 ArrayList (java.util.ArrayList)214 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)209 RelNode (org.apache.calcite.rel.RelNode)153 SqlNode (org.apache.calcite.sql.SqlNode)143 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)123 RexBuilder (org.apache.calcite.rex.RexBuilder)118 Test (org.junit.Test)62 ImmutableList (com.google.common.collect.ImmutableList)58 RexInputRef (org.apache.calcite.rex.RexInputRef)57 List (java.util.List)51 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)45 RexLiteral (org.apache.calcite.rex.RexLiteral)44 SqlNodeList (org.apache.calcite.sql.SqlNodeList)42 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)40 AggregateCall (org.apache.calcite.rel.core.AggregateCall)39 BitString (org.apache.calcite.util.BitString)38 BigDecimal (java.math.BigDecimal)35 RelBuilder (org.apache.calcite.tools.RelBuilder)34