Search in sources :

Example 1 with DirectGroupScan

use of org.apache.drill.exec.store.direct.DirectGroupScan in project drill by apache.

the class FindLimit0Visitor method getDirectScanRelIfFullySchemaed.

/**
   * If all field types of the given node are {@link #TYPES recognized types} and honored by execution, then this
   * method returns the tree: DrillDirectScanRel(field types). Otherwise, the method returns null.
   *
   * @param rel calcite logical rel tree
   * @return drill logical rel tree
   */
public static DrillRel getDirectScanRelIfFullySchemaed(RelNode rel) {
    final List<RelDataTypeField> fieldList = rel.getRowType().getFieldList();
    final List<TypeProtos.MajorType> columnTypes = Lists.newArrayList();
    for (final RelDataTypeField field : fieldList) {
        final SqlTypeName sqlTypeName = field.getType().getSqlTypeName();
        if (!TYPES.contains(sqlTypeName)) {
            return null;
        } else {
            final TypeProtos.MajorType.Builder builder = TypeProtos.MajorType.newBuilder().setMode(field.getType().isNullable() ? TypeProtos.DataMode.OPTIONAL : TypeProtos.DataMode.REQUIRED).setMinorType(TypeInferenceUtils.getDrillTypeFromCalciteType(sqlTypeName));
            if (TypeInferenceUtils.isScalarStringType(sqlTypeName)) {
                builder.setPrecision(field.getType().getPrecision());
            }
            columnTypes.add(builder.build());
        }
    }
    final RelTraitSet traits = rel.getTraitSet().plus(DrillRel.DRILL_LOGICAL);
    final RelDataTypeReader reader = new RelDataTypeReader(rel.getRowType().getFieldNames(), columnTypes);
    return new DrillDirectScanRel(rel.getCluster(), traits, new DirectGroupScan(reader, ScanStats.ZERO_RECORD_TABLE), rel.getRowType());
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) DirectGroupScan(org.apache.drill.exec.store.direct.DirectGroupScan) RelTraitSet(org.apache.calcite.plan.RelTraitSet) DrillDirectScanRel(org.apache.drill.exec.planner.logical.DrillDirectScanRel)

Example 2 with DirectGroupScan

use of org.apache.drill.exec.store.direct.DirectGroupScan in project drill by apache.

the class DirectPlan method createDirectPlan.

public static <T> PhysicalPlan createDirectPlan(DrillbitEndpoint endpoint, Iterator<T> iterator, Class<T> clazz) {
    PojoRecordReader<T> reader = new PojoRecordReader<T>(clazz, iterator);
    DirectGroupScan scan = new DirectGroupScan(reader);
    Screen screen = new Screen(scan, endpoint);
    PlanPropertiesBuilder propsBuilder = PlanProperties.builder();
    propsBuilder.type(PlanType.APACHE_DRILL_PHYSICAL);
    propsBuilder.version(1);
    propsBuilder.resultMode(ResultMode.EXEC);
    propsBuilder.generator(DirectPlan.class.getSimpleName(), "");
    return new PhysicalPlan(propsBuilder.build(), DefaultSqlHandler.getPops(screen));
}
Also used : PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) Screen(org.apache.drill.exec.physical.config.Screen) DirectGroupScan(org.apache.drill.exec.store.direct.DirectGroupScan) PlanPropertiesBuilder(org.apache.drill.common.logical.PlanProperties.PlanPropertiesBuilder) PojoRecordReader(org.apache.drill.exec.store.pojo.PojoRecordReader)

Aggregations

DirectGroupScan (org.apache.drill.exec.store.direct.DirectGroupScan)2 RelTraitSet (org.apache.calcite.plan.RelTraitSet)1 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)1 SqlTypeName (org.apache.calcite.sql.type.SqlTypeName)1 PlanPropertiesBuilder (org.apache.drill.common.logical.PlanProperties.PlanPropertiesBuilder)1 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)1 Screen (org.apache.drill.exec.physical.config.Screen)1 DrillDirectScanRel (org.apache.drill.exec.planner.logical.DrillDirectScanRel)1 PojoRecordReader (org.apache.drill.exec.store.pojo.PojoRecordReader)1