use of org.ojai.FieldPath in project drill by apache.
the class MaprDBJsonRecordReader method transformColumns.
@Override
protected Collection<SchemaPath> transformColumns(Collection<SchemaPath> columns) {
Set<SchemaPath> transformed = Sets.newLinkedHashSet();
Set<SchemaPath> encodedSchemaPathSet = Sets.newLinkedHashSet();
if (disablePushdown) {
transformed.add(SchemaPath.STAR_COLUMN);
includeId = true;
} else {
if (isStarQuery()) {
transformed.add(SchemaPath.STAR_COLUMN);
includeId = true;
if (isSkipQuery() && !disableCountOptimization) {
// `SELECT COUNT(*)` query
idOnly = true;
scannedFields = ID_ONLY_PROJECTION;
}
} else {
Set<FieldPath> scannedFieldsSet = Sets.newTreeSet();
Set<FieldPath> projectedFieldsSet = null;
for (SchemaPath column : columns) {
if (EncodedSchemaPathSet.isEncodedSchemaPath(column)) {
encodedSchemaPathSet.add(column);
} else {
transformed.add(column);
if (!DOCUMENT_SCHEMA_PATH.equals(column)) {
FieldPath fp = getFieldPathForProjection(column);
scannedFieldsSet.add(fp);
} else {
projectWholeDocument = true;
}
}
}
if (projectWholeDocument) {
// we do not want to project the fields from the encoded field path list
// hence make a copy of the scannedFieldsSet here for projection.
projectedFieldsSet = new ImmutableSet.Builder<FieldPath>().addAll(scannedFieldsSet).build();
}
if (encodedSchemaPathSet.size() > 0) {
Collection<SchemaPath> decodedSchemaPaths = EncodedSchemaPathSet.decode(encodedSchemaPathSet);
// add them to scanned set or clear the scanned set if all fields were requested.
for (SchemaPath column : decodedSchemaPaths) {
if (column.equals(SchemaPath.STAR_COLUMN)) {
includeId = true;
scannedFieldsSet.clear();
break;
}
scannedFieldsSet.add(getFieldPathForProjection(column));
}
}
if (scannedFieldsSet.size() > 0) {
if (includesIdField(scannedFieldsSet)) {
includeId = true;
}
scannedFields = scannedFieldsSet.toArray(new FieldPath[scannedFieldsSet.size()]);
}
if (disableCountOptimization) {
idOnly = (scannedFields == null);
}
if (projectWholeDocument) {
projector = new FieldProjector(projectedFieldsSet);
}
}
}
return transformed;
}
use of org.ojai.FieldPath in project drill by apache.
the class MaprDBJsonRecordReader method getFieldPathForProjection.
/*
* Extracts contiguous named segments from the SchemaPath, starting from the
* root segment and build the FieldPath from it for projection.
*
* This is due to bug 22726 and 22727, which cause DB's DocumentReaders to
* behave incorrectly for sparse lists, hence we avoid projecting beyond the
* first encountered ARRAY field and let Drill handle the projection.
*/
private static FieldPath getFieldPathForProjection(SchemaPath column) {
Stack<PathSegment.NameSegment> pathSegments = new Stack<>();
PathSegment seg = column.getRootSegment();
while (seg != null && seg.isNamed()) {
pathSegments.push((PathSegment.NameSegment) seg);
seg = seg.getChild();
}
FieldSegment.NameSegment child = null;
while (!pathSegments.isEmpty()) {
child = new FieldSegment.NameSegment(pathSegments.pop().getPath(), child, false);
}
return new FieldPath(child);
}
use of org.ojai.FieldPath in project drill by apache.
the class FieldPathHelper method schemaPathToFieldPath.
/**
* Returns {@link FieldPath} equivalent of the specified {@link SchemaPath}.
*
* @param schemaPath {@link SchemaPath} instance that should be converted
* @return {@link FieldPath} equivalent of the specified {@link SchemaPath}.
*/
public static FieldPath schemaPathToFieldPath(SchemaPath schemaPath) {
Deque<PathSegment> pathSegments = Queues.newArrayDeque();
PathSegment pathSegment = schemaPath.getRootSegment();
while (pathSegment != null) {
pathSegments.push(pathSegment);
pathSegment = pathSegment.getChild();
}
FieldSegment child = null;
while (!pathSegments.isEmpty()) {
pathSegment = pathSegments.pop();
if (pathSegment.isNamed()) {
child = new FieldSegment.NameSegment(((PathSegment.NameSegment) pathSegment).getPath(), child, false);
} else {
child = new FieldSegment.IndexSegment(String.valueOf(((PathSegment.ArraySegment) pathSegment).getIndex()), child);
}
}
return new FieldPath((FieldSegment.NameSegment) child);
}
use of org.ojai.FieldPath in project drill by axbaretto.
the class MaprDBJsonRecordReader method transformColumns.
@Override
protected Collection<SchemaPath> transformColumns(Collection<SchemaPath> columns) {
Set<SchemaPath> transformed = Sets.newLinkedHashSet();
if (disablePushdown) {
transformed.add(SchemaPath.STAR_COLUMN);
includeId = true;
return transformed;
}
if (isStarQuery()) {
transformed.add(SchemaPath.STAR_COLUMN);
includeId = true;
if (isSkipQuery()) {
// `SELECT COUNT(*)` query
if (!disableCountOptimization) {
projectedFields = new FieldPath[1];
projectedFields[0] = ID_FIELD;
}
}
return transformed;
}
Set<FieldPath> projectedFieldsSet = Sets.newTreeSet();
for (SchemaPath column : columns) {
if (column.getRootSegment().getPath().equalsIgnoreCase(ID_KEY)) {
includeId = true;
if (!disableCountOptimization) {
projectedFieldsSet.add(ID_FIELD);
}
} else {
projectedFieldsSet.add(getFieldPathForProjection(column));
}
transformed.add(column);
}
if (projectedFieldsSet.size() > 0) {
projectedFields = projectedFieldsSet.toArray(new FieldPath[projectedFieldsSet.size()]);
}
if (disableCountOptimization) {
idOnly = (projectedFields == null);
}
return transformed;
}
use of org.ojai.FieldPath in project drill by axbaretto.
the class MaprDBJsonRecordReader method getFieldPathForProjection.
/*
* Extracts contiguous named segments from the SchemaPath, starting from the
* root segment and build the FieldPath from it for projection.
*
* This is due to bug 22726 and 22727, which cause DB's DocumentReaders to
* behave incorrectly for sparse lists, hence we avoid projecting beyond the
* first encountered ARRAY field and let Drill handle the projection.
*/
private static FieldPath getFieldPathForProjection(SchemaPath column) {
Stack<PathSegment.NameSegment> pathSegments = new Stack<PathSegment.NameSegment>();
PathSegment seg = column.getRootSegment();
while (seg != null && seg.isNamed()) {
pathSegments.push((PathSegment.NameSegment) seg);
seg = seg.getChild();
}
FieldSegment.NameSegment child = null;
while (!pathSegments.isEmpty()) {
child = new FieldSegment.NameSegment(pathSegments.pop().getPath(), child, false);
}
return new FieldPath(child);
}
Aggregations