Search in sources :

Example 1 with FieldSegment

use of org.ojai.FieldSegment 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 2 with FieldSegment

use of org.ojai.FieldSegment in project drill by apache.

the class FieldPathHelper method schemaPath2FieldPath.

/**
 * Returns {@link FieldPath} equivalent of the specified {@link SchemaPath}.
 */
public static FieldPath schemaPath2FieldPath(SchemaPath column) {
    Stack<PathSegment> pathSegments = new Stack<PathSegment>();
    PathSegment seg = column.getRootSegment();
    while (seg != null) {
        pathSegments.push(seg);
        seg = seg.getChild();
    }
    FieldSegment child = null;
    while (!pathSegments.isEmpty()) {
        seg = pathSegments.pop();
        if (seg.isNamed()) {
            child = new FieldSegment.NameSegment(((PathSegment.NameSegment) seg).getPath(), child, false);
        } else {
            child = new FieldSegment.IndexSegment(((PathSegment.ArraySegment) seg).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) Stack(java.util.Stack)

Example 3 with FieldSegment

use of org.ojai.FieldSegment in project drill by axbaretto.

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 4 with FieldSegment

use of org.ojai.FieldSegment 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)

Aggregations

PathSegment (org.apache.drill.common.expression.PathSegment)4 FieldSegment (org.ojai.FieldSegment)4 FieldPath (org.ojai.FieldPath)3 Stack (java.util.Stack)2 SchemaPath (org.apache.drill.common.expression.SchemaPath)1