Search in sources :

Example 1 with JSONRecordReader

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

the class TestUtilities method getJsonReadersFromBatchString.

/**
   * Create JSONRecordReader from input strings.
   * @param jsonBatches : list of input strings, each element represent a batch. Each string could either
   *                    be in the form of "[{...}, {...}, ..., {...}]", or in the form of "{...}".
   * @param fragContext : fragment context
   * @param columnsToRead : list of schema pathes to read from JSON reader.
   * @return
   */
public static Iterator<RecordReader> getJsonReadersFromBatchString(List<String> jsonBatches, FragmentContext fragContext, List<SchemaPath> columnsToRead) {
    ObjectMapper mapper = new ObjectMapper();
    List<RecordReader> readers = new ArrayList<>();
    for (String batchJason : jsonBatches) {
        JsonNode records;
        try {
            records = mapper.readTree(batchJason);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        readers.add(new JSONRecordReader(fragContext, records, null, columnsToRead));
    }
    return readers.iterator();
}
Also used : JSONRecordReader(org.apache.drill.exec.store.easy.json.JSONRecordReader) JSONRecordReader(org.apache.drill.exec.store.easy.json.JSONRecordReader) RecordReader(org.apache.drill.exec.store.RecordReader) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 RecordReader (org.apache.drill.exec.store.RecordReader)1 JSONRecordReader (org.apache.drill.exec.store.easy.json.JSONRecordReader)1