Search in sources :

Example 86 with RelDataType

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

the class StarColumnConverter method visitScan.

@Override
public Prel visitScan(ScanPrel scanPrel, Void value) throws RuntimeException {
    if (StarColumnHelper.containsStarColumn(scanPrel.getRowType()) && prefixedForStar) {
        List<RexNode> exprs = Lists.newArrayList();
        for (RelDataTypeField field : scanPrel.getRowType().getFieldList()) {
            RexNode expr = scanPrel.getCluster().getRexBuilder().makeInputRef(field.getType(), field.getIndex());
            exprs.add(expr);
        }
        List<String> fieldNames = Lists.newArrayList();
        long tableId = tableNumber.getAndIncrement();
        for (String name : scanPrel.getRowType().getFieldNames()) {
            if (StarColumnHelper.isNonPrefixedStarColumn(name)) {
                // Add prefix to * column.
                fieldNames.add("T" + tableId + StarColumnHelper.PREFIX_DELIMITER + name);
            } else {
                // Keep regular column as it is.
                fieldNames.add(name);
            }
        }
        RelDataType rowType = RexUtil.createStructType(scanPrel.getCluster().getTypeFactory(), exprs, fieldNames);
        // insert a PAS.
        ProjectPrel proj = new ProjectPrel(scanPrel.getCluster(), scanPrel.getTraitSet(), scanPrel, exprs, rowType);
        return proj;
    } else {
        return visitPrel(scanPrel, value);
    }
}
Also used : ProjectPrel(org.apache.drill.exec.planner.physical.ProjectPrel) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelDataType(org.apache.calcite.rel.type.RelDataType) RexNode(org.apache.calcite.rex.RexNode)

Example 87 with RelDataType

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

the class StarColumnConverter method insertProjUnderScreenOrWriter.

// insert PUS or PUW: Project Under Screen/Writer, when necessary.
private Prel insertProjUnderScreenOrWriter(Prel prel, RelDataType origRowType, Prel child) {
    ProjectPrel proj = null;
    List<RelNode> children = Lists.newArrayList();
    List<RexNode> exprs = Lists.newArrayList();
    for (int i = 0; i < origRowType.getFieldCount(); i++) {
        RexNode expr = child.getCluster().getRexBuilder().makeInputRef(origRowType.getFieldList().get(i).getType(), i);
        exprs.add(expr);
    }
    RelDataType newRowType = RexUtil.createStructType(child.getCluster().getTypeFactory(), exprs, origRowType.getFieldNames());
    int fieldCount = prel.getRowType().isStruct() ? prel.getRowType().getFieldCount() : 1;
    // Insert PUS/PUW : remove the prefix and keep the original field name.
    if (fieldCount > 1) {
        // // no point in allowing duplicates if we only have one column
        proj = new ProjectAllowDupPrel(child.getCluster(), child.getTraitSet(), child, exprs, newRowType);
    } else {
        proj = new ProjectPrel(child.getCluster(), child.getTraitSet(), child, exprs, newRowType);
    }
    children.add(proj);
    return (Prel) prel.copy(prel.getTraitSet(), children);
}
Also used : ProjectPrel(org.apache.drill.exec.planner.physical.ProjectPrel) RelNode(org.apache.calcite.rel.RelNode) ProjectAllowDupPrel(org.apache.drill.exec.planner.physical.ProjectAllowDupPrel) RelDataType(org.apache.calcite.rel.type.RelDataType) RexNode(org.apache.calcite.rex.RexNode) ScanPrel(org.apache.drill.exec.planner.physical.ScanPrel) Prel(org.apache.drill.exec.planner.physical.Prel) ProjectAllowDupPrel(org.apache.drill.exec.planner.physical.ProjectAllowDupPrel) ProjectPrel(org.apache.drill.exec.planner.physical.ProjectPrel) ScreenPrel(org.apache.drill.exec.planner.physical.ScreenPrel) WriterPrel(org.apache.drill.exec.planner.physical.WriterPrel)

Example 88 with RelDataType

use of org.apache.calcite.rel.type.RelDataType in project lucene-solr by apache.

the class SolrToEnumerableConverter method implement.

public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    // Generates a call to "query" with the appropriate fields
    final BlockBuilder list = new BlockBuilder();
    final SolrRel.Implementor solrImplementor = new SolrRel.Implementor();
    solrImplementor.visitChild(0, getInput());
    final RelDataType rowType = getRowType();
    final PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), rowType, pref.prefer(JavaRowFormat.ARRAY));
    final Expression table = list.append("table", solrImplementor.table.getExpression(SolrTable.SolrQueryable.class));
    final Expression fields = list.append("fields", constantArrayList(Pair.zip(generateFields(SolrRules.solrFieldNames(rowType), solrImplementor.fieldMappings), new AbstractList<Class>() {

        @Override
        public Class get(int index) {
            return physType.fieldClass(index);
        }

        @Override
        public int size() {
            return rowType.getFieldCount();
        }
    }), Pair.class));
    final Expression query = list.append("query", Expressions.constant(solrImplementor.query, String.class));
    final Expression orders = list.append("orders", constantArrayList(solrImplementor.orders, Pair.class));
    final Expression buckets = list.append("buckets", constantArrayList(solrImplementor.buckets, String.class));
    final Expression metricPairs = list.append("metricPairs", constantArrayList(solrImplementor.metricPairs, Pair.class));
    final Expression limit = list.append("limit", Expressions.constant(solrImplementor.limitValue));
    final Expression negativeQuery = list.append("negativeQuery", Expressions.constant(Boolean.toString(solrImplementor.negativeQuery), String.class));
    final Expression havingPredicate = list.append("havingTest", Expressions.constant(solrImplementor.havingPredicate, String.class));
    Expression enumerable = list.append("enumerable", Expressions.call(table, SolrMethod.SOLR_QUERYABLE_QUERY.method, fields, query, orders, buckets, metricPairs, limit, negativeQuery, havingPredicate));
    Hook.QUERY_PLAN.run(query);
    list.add(Expressions.return_(null, enumerable));
    return implementor.result(physType, list.toBlock());
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType) MethodCallExpression(org.apache.calcite.linq4j.tree.MethodCallExpression) Expression(org.apache.calcite.linq4j.tree.Expression) BlockBuilder(org.apache.calcite.linq4j.tree.BlockBuilder) Pair(org.apache.calcite.util.Pair)

Aggregations

RelDataType (org.apache.calcite.rel.type.RelDataType)88 RexNode (org.apache.calcite.rex.RexNode)48 RexBuilder (org.apache.calcite.rex.RexBuilder)28 RelNode (org.apache.calcite.rel.RelNode)27 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)25 ArrayList (java.util.ArrayList)21 RexInputRef (org.apache.calcite.rex.RexInputRef)16 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)14 AggregateCall (org.apache.calcite.rel.core.AggregateCall)13 ImmutableList (com.google.common.collect.ImmutableList)9 BigDecimal (java.math.BigDecimal)8 CalciteSemanticException (org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException)8 SqlAggFunction (org.apache.calcite.sql.SqlAggFunction)7 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)7 RelOptCluster (org.apache.calcite.plan.RelOptCluster)6 RelBuilder (org.apache.calcite.tools.RelBuilder)6 Prel (org.apache.drill.exec.planner.physical.Prel)6 ProjectPrel (org.apache.drill.exec.planner.physical.ProjectPrel)6 Builder (com.google.common.collect.ImmutableList.Builder)5 LinkedList (java.util.LinkedList)5