Search in sources :

Example 6 with FieldPath

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;
}
Also used : FieldProjector(org.ojai.util.FieldProjector) ImmutableSet(org.apache.drill.shaded.guava.com.google.common.collect.ImmutableSet) SchemaPath(org.apache.drill.common.expression.SchemaPath) FieldPath(org.ojai.FieldPath)

Example 7 with FieldPath

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);
}
Also used : FieldSegment(org.ojai.FieldSegment) FieldPath(org.ojai.FieldPath) PathSegment(org.apache.drill.common.expression.PathSegment) Stack(java.util.Stack)

Example 8 with FieldPath

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);
}
Also used : FieldSegment(org.ojai.FieldSegment) FieldPath(org.ojai.FieldPath) PathSegment(org.apache.drill.common.expression.PathSegment)

Example 9 with FieldPath

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;
}
Also used : SchemaPath(org.apache.drill.common.expression.SchemaPath) FieldPath(org.ojai.FieldPath)

Example 10 with FieldPath

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);
}
Also used : FieldSegment(org.ojai.FieldSegment) FieldPath(org.ojai.FieldPath) PathSegment(org.apache.drill.common.expression.PathSegment) Stack(java.util.Stack)

Aggregations

FieldPath (org.ojai.FieldPath)12 PathSegment (org.apache.drill.common.expression.PathSegment)5 FieldSegment (org.ojai.FieldSegment)5 Argument (graphql.language.Argument)3 ArrayValue (graphql.language.ArrayValue)3 BooleanValue (graphql.language.BooleanValue)3 EnumValue (graphql.language.EnumValue)3 FloatValue (graphql.language.FloatValue)3 IntValue (graphql.language.IntValue)3 NullValue (graphql.language.NullValue)3 ObjectField (graphql.language.ObjectField)3 ObjectValue (graphql.language.ObjectValue)3 StringValue (graphql.language.StringValue)3 Value (graphql.language.Value)3 GraphQLArgument (graphql.schema.GraphQLArgument)3 HValue (io.hdocdb.HValue)3 ConditionLeaf (io.hdocdb.store.ConditionLeaf)3 ConditionNode (io.hdocdb.store.ConditionNode)3 ConditionParent (io.hdocdb.store.ConditionParent)3 Iterables (com.google.common.collect.Iterables)2