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);
}
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;
}
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;
}
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();
}
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;
}
Aggregations