Search in sources :

Example 1 with ElementParser

use of org.apache.drill.exec.store.easy.json.parser.ElementParser in project drill by apache.

the class BaseFieldFactory method buildOuterArrays.

/**
 * Create layers of repeated list listeners around the type-specific
 * array. If the JSON has three array levels, the outer two are repeated
 * lists, the inner is type-specific: say an array of {@code BIGINT} or
 * a map array.
 */
public ElementParser buildOuterArrays(ObjectWriter writer, int dims, Function<ObjectWriter, ElementParser> innerCreator) {
    ObjectWriter[] writers = new ObjectWriter[dims];
    writers[0] = writer;
    for (int i = 1; i < dims; i++) {
        writers[i] = writers[i - 1].array().entry();
    }
    ElementParser prevElementParser = innerCreator.apply(writers[dims - 1]);
    for (int i = dims - 2; i >= 0; i--) {
        prevElementParser = parserFactory().arrayValueParser(new StructureArrayListener(writers[i].array()), prevElementParser);
    }
    return prevElementParser;
}
Also used : StructureArrayListener(org.apache.drill.exec.store.easy.json.loader.SimpleArrayListener.StructureArrayListener) ObjectWriter(org.apache.drill.exec.vector.accessor.ObjectWriter) ElementParser(org.apache.drill.exec.store.easy.json.parser.ElementParser)

Example 2 with ElementParser

use of org.apache.drill.exec.store.easy.json.parser.ElementParser in project drill by apache.

the class ExtendedTypeFieldFactory method buildExtendedTypeParser.

private ElementParser buildExtendedTypeParser(FieldDefn fieldDefn) {
    // Extended types are objects: { "$type": ... }
    // Extended arrays are [ { "$type": ...
    TokenIterator tokenizer = fieldDefn.tokenizer();
    JsonToken token = tokenizer.requireNext();
    ElementParser parser;
    switch(token) {
        case START_OBJECT:
            parser = extendedTypeParserFor(fieldDefn, false);
            break;
        case START_ARRAY:
            parser = arrayParserFor(fieldDefn);
            break;
        default:
            parser = null;
    }
    tokenizer.unget(token);
    return parser;
}
Also used : TokenIterator(org.apache.drill.exec.store.easy.json.parser.TokenIterator) JsonToken(com.fasterxml.jackson.core.JsonToken) ElementParser(org.apache.drill.exec.store.easy.json.parser.ElementParser)

Aggregations

ElementParser (org.apache.drill.exec.store.easy.json.parser.ElementParser)2 JsonToken (com.fasterxml.jackson.core.JsonToken)1 StructureArrayListener (org.apache.drill.exec.store.easy.json.loader.SimpleArrayListener.StructureArrayListener)1 TokenIterator (org.apache.drill.exec.store.easy.json.parser.TokenIterator)1 ObjectWriter (org.apache.drill.exec.vector.accessor.ObjectWriter)1