Search in sources :

Example 11 with FieldPath

use of org.ojai.FieldPath 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 12 with FieldPath

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

the class TestFieldPathHelper method simeTests.

@Test
public void simeTests() {
    String[] pathStrs = { "a", "a.b", "a.b.c", "a[1].b[2].c", "a[0][1][2][3].b" };
    FieldPath[] fieldPaths = new FieldPath[pathStrs.length];
    SchemaPath[] schemaPaths = new SchemaPath[pathStrs.length];
    // build
    for (int i = 0; i < pathStrs.length; i++) {
        String path = pathStrs[i];
        fieldPaths[i] = FieldPath.parseFrom(path);
        schemaPaths[i] = SchemaPath.parseFromString(path);
    }
    // verify
    for (int i = 0; i < pathStrs.length; i++) {
        FieldPath fp = FieldPathHelper.schemaPath2FieldPath(schemaPaths[i]);
        assertEquals(fieldPaths[i], fp);
        SchemaPath sp = FieldPathHelper.fieldPath2SchemaPath(fieldPaths[i]);
        assertEquals(schemaPaths[i], sp);
    }
}
Also used : SchemaPath(org.apache.drill.common.expression.SchemaPath) FieldPath(org.ojai.FieldPath) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

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