Search in sources :

Example 21 with PathSegment

use of org.apache.drill.common.expression.PathSegment in project drill by apache.

the class FieldPathHelper method fieldPath2SchemaPath.

/**
 * Returns {@link SchemaPath} equivalent of the specified {@link FieldPath}.
 */
public static SchemaPath fieldPath2SchemaPath(FieldPath fieldPath) {
    Stack<FieldSegment> fieldSegments = new Stack<FieldSegment>();
    FieldSegment seg = fieldPath.getRootSegment();
    while (seg != null) {
        fieldSegments.push(seg);
        seg = seg.getChild();
    }
    PathSegment child = null;
    while (!fieldSegments.isEmpty()) {
        seg = fieldSegments.pop();
        if (seg.isNamed()) {
            child = new PathSegment.NameSegment(((FieldSegment.NameSegment) seg).getName(), child);
        } else {
            child = new PathSegment.ArraySegment(((FieldSegment.IndexSegment) seg).getIndex(), child);
        }
    }
    return new SchemaPath((PathSegment.NameSegment) child);
}
Also used : FieldSegment(org.ojai.FieldSegment) SchemaPath(org.apache.drill.common.expression.SchemaPath) PathSegment(org.apache.drill.common.expression.PathSegment) Stack(java.util.Stack)

Example 22 with PathSegment

use of org.apache.drill.common.expression.PathSegment in project drill by apache.

the class ConvertMetadataAggregateToDirectScanRule method containsArrayColumn.

/**
 * Checks whether schema path contains array segment.
 *
 * @param schema tuple schema
 * @param schemaPath schema path
 * @return {@code true} if any segment in the schema path is an array, {@code false} otherwise
 */
private static boolean containsArrayColumn(TupleMetadata schema, SchemaPath schemaPath) {
    PathSegment currentPath = schemaPath.getRootSegment();
    ColumnMetadata columnMetadata = schema.metadata(currentPath.getNameSegment().getPath());
    while (columnMetadata != null) {
        if (columnMetadata.isArray()) {
            return true;
        } else if (columnMetadata.isMap()) {
            currentPath = currentPath.getChild();
            columnMetadata = columnMetadata.tupleSchema().metadata(currentPath.getNameSegment().getPath());
        } else if (columnMetadata.isDict()) {
            currentPath = currentPath.getChild();
            columnMetadata = ((DictColumnMetadata) columnMetadata).valueColumnMetadata();
        } else {
            return false;
        }
    }
    return false;
}
Also used : DictColumnMetadata(org.apache.drill.exec.record.metadata.DictColumnMetadata) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) PathSegment(org.apache.drill.common.expression.PathSegment)

Example 23 with PathSegment

use of org.apache.drill.common.expression.PathSegment in project drill by apache.

the class HBaseRecordReader method transformColumns.

/**
 * Provides the projected columns information to the Hbase Scan instance. If the
 * projected columns list contains a column family and also a column in the
 * column family, only the column family is passed to the Scan instance.
 *
 * For example, if the projection list is {cf1, cf1.col1, cf2.col1} then we only
 * pass {cf1, cf2.col1} to the Scan instance.
 *
 * @param columns collection of projected columns
 * @return collection of projected column family names
 */
@Override
protected Collection<SchemaPath> transformColumns(Collection<SchemaPath> columns) {
    Set<SchemaPath> transformed = Sets.newLinkedHashSet();
    completeFamilies = Sets.newHashSet();
    rowKeyOnly = true;
    if (!isStarQuery()) {
        for (SchemaPath column : columns) {
            if (column.getRootSegment().getPath().equalsIgnoreCase(ROW_KEY)) {
                transformed.add(ROW_KEY_PATH);
                continue;
            }
            rowKeyOnly = false;
            NameSegment root = column.getRootSegment();
            byte[] family = root.getPath().getBytes();
            transformed.add(SchemaPath.getSimplePath(root.getPath()));
            PathSegment child = root.getChild();
            if (child != null && child.isNamed()) {
                byte[] qualifier = child.getNameSegment().getPath().getBytes();
                hbaseScanColumnsOnly.addColumn(family, qualifier);
                if (!completeFamilies.contains(root.getPath())) {
                    hbaseScan.addColumn(family, qualifier);
                }
            } else {
                hbaseScan.addFamily(family);
                completeFamilies.add(root.getPath());
            }
        }
        /* if only the row key was requested, add a FirstKeyOnlyFilter to the scan
       * to fetch only one KV from each row. If a filter is already part of this
       * scan, add the FirstKeyOnlyFilter as the LAST filter of a MUST_PASS_ALL
       * FilterList.
       */
        if (rowKeyOnly) {
            hbaseScan.setFilter(HBaseUtils.andFilterAtIndex(hbaseScan.getFilter(), HBaseUtils.LAST_FILTER, new FirstKeyOnlyFilter()));
        }
    } else {
        rowKeyOnly = false;
        transformed.add(ROW_KEY_PATH);
    }
    return transformed;
}
Also used : NameSegment(org.apache.drill.common.expression.PathSegment.NameSegment) SchemaPath(org.apache.drill.common.expression.SchemaPath) FirstKeyOnlyFilter(org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter) PathSegment(org.apache.drill.common.expression.PathSegment)

Example 24 with PathSegment

use of org.apache.drill.common.expression.PathSegment in project drill by apache.

the class DrillRelOptUtil method getFieldsInformation.

public static ProjectPushInfo getFieldsInformation(RelDataType rowType, List<RexNode> projects) {
    ProjectFieldsVisitor fieldsVisitor = new ProjectFieldsVisitor(rowType);
    for (RexNode exp : projects) {
        PathSegment segment = exp.accept(fieldsVisitor);
        fieldsVisitor.addField(segment);
    }
    return fieldsVisitor.getInfo();
}
Also used : PathSegment(org.apache.drill.common.expression.PathSegment) RexNode(org.apache.calcite.rex.RexNode)

Example 25 with PathSegment

use of org.apache.drill.common.expression.PathSegment in project drill by apache.

the class ExprToRex method visitSchemaPath.

@Override
public RexNode visitSchemaPath(SchemaPath path, Void value) throws RuntimeException {
    PathSegment pathSegment = path.getRootSegment();
    RelDataTypeField field = findField(pathSegment.getNameSegment().getPath(), newRowType);
    RexNode rexNode = field == null ? null : builder.makeInputRef(field.getType(), field.getIndex());
    while (!pathSegment.isLastPath()) {
        pathSegment = pathSegment.getChild();
        RexNode ref;
        if (pathSegment.isNamed()) {
            ref = builder.makeLiteral(pathSegment.getNameSegment().getPath());
        } else {
            ref = builder.makeBigintLiteral(BigDecimal.valueOf(pathSegment.getArraySegment().getIndex()));
        }
        rexNode = builder.makeCall(SqlStdOperatorTable.ITEM, rexNode, ref);
    }
    return rexNode;
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) PathSegment(org.apache.drill.common.expression.PathSegment) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

PathSegment (org.apache.drill.common.expression.PathSegment)32 SchemaPath (org.apache.drill.common.expression.SchemaPath)14 BaseWriter (org.apache.drill.exec.vector.complex.writer.BaseWriter)6 FieldSegment (org.ojai.FieldSegment)6 ArrayList (java.util.ArrayList)5 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)5 GroupType (org.apache.parquet.schema.GroupType)5 Type (org.apache.parquet.schema.Type)5 FieldPath (org.ojai.FieldPath)5 Stack (java.util.Stack)4 RexNode (org.apache.calcite.rex.RexNode)4 MessageType (org.apache.parquet.schema.MessageType)4 BitSet (java.util.BitSet)3 ValueVector (org.apache.drill.exec.vector.ValueVector)3 NameSegment (org.apache.drill.common.expression.PathSegment.NameSegment)2 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)2 TypedFieldId (org.apache.drill.exec.record.TypedFieldId)2 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)2 ListWriter (org.apache.drill.exec.vector.complex.writer.BaseWriter.ListWriter)2 MapWriter (org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter)2