Package org.apache.drill.exec.vector.complex.reader

Examples of org.apache.drill.exec.vector.complex.reader.FieldReader


    // Iterate over the fields in the map
    Iterator<String> fieldIterator = reader.iterator();
    while (fieldIterator.hasNext()) {
      String str = fieldIterator.next();
      FieldReader fieldReader = reader.reader(str);

      // Skip the field if its null
      if (fieldReader.isSet() == false) {
        mapWriter.end();
        continue;
      }

      // Check if the value field is not repeated
      if (fieldReader.getType().getMode() == TypeProtos.DataMode.REPEATED) {
        throw new DrillRuntimeException("kvgen function does not support repeated type values");
      }

      // writing a new field, start a new map
      mapWriter.start();
View Full Code Here


  private void initFieldWriters() throws IOException {
    fieldConverters = Lists.newArrayList();
    try {
      int fieldId = 0;
      for (VectorWrapper w : batch) {
        FieldReader reader = w.getValueVector().getAccessor().getReader();
        FieldConverter converter = getConverter(recordWriter, fieldId++, w.getField().getLastName(), reader);
        fieldConverters.add(converter);
      }
    } catch(Exception e) {
      logger.error("Failed to create FieldWriter.", e);
View Full Code Here

    ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();

    ow.writeValueAsString(v.getAccessor().getObject(0));
    ow.writeValueAsString(v.getAccessor().getObject(1));
    FieldReader reader = v.get("col", MapVector.class).getAccessor().getReader();

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    JsonWriter jsonWriter = new JsonWriter(stream, true);

    reader.setPosition(0);
    jsonWriter.write(reader);
    reader.setPosition(1);
    jsonWriter.write(reader);
    System.out.print("Json Read: ");
    System.out.println(new String(stream.toByteArray(), Charsets.UTF_8));
//    System.out.println(compound);

    System.out.println("Total Records Written " + batchSizes);

    reader.setPosition(lastRecordCount - 2);
    assertEquals("goodbye", reader.reader("c").readText().toString());
    reader.setPosition(lastRecordCount - 1);
    assertEquals("red", reader.reader("c").readText().toString());
    assertEquals((repeatSize+1) * 2, total);

    writer.clear();
    buffer.release();
  }
View Full Code Here

    System.out.println("Map of Object[1]: " + ow.writeValueAsString(v.getAccessor().getObject(1)));


    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    JsonWriter jsonWriter = new JsonWriter(stream, true);
    FieldReader reader = v.get("col", MapVector.class).getAccessor().getReader();
    reader.setPosition(0);
    jsonWriter.write(reader);
    reader.setPosition(1);
    jsonWriter.write(reader);
    System.out.print("Json Read: ");
    System.out.println(new String(stream.toByteArray(), Charsets.UTF_8));

    writer.clear();
View Full Code Here

      holder.start = offsets.getAccessor().get(index);
      holder.end = offsets.getAccessor().get(index+1);
    }

    public void get(int index, ComplexHolder holder) {
      FieldReader reader = getReader();
      reader.setPosition(index);
      holder.reader = reader;
    }
View Full Code Here

    }
  }

  @Override
  public FieldReader reader(String name){
    FieldReader reader = fields.get(name);
    if(reader == null){
      ValueVector child = vector.get(name, ValueVector.class);
      if(child == null){
        reader = NullReader.INSTANCE;
      }else{
        reader = child.getAccessor().getReader();
      }
      fields.put(name, reader);
      reader.setPosition(idx());
    }
    return reader;
  }
View Full Code Here

    }
  }

  @Override
  public FieldReader reader(String name) {
    FieldReader reader = fields.get(name);
    if (reader == null) {
      ValueVector child = vector.get(name, ValueVector.class);
      if (child == null) {
        reader = NullReader.INSTANCE;
      } else {
        reader = child.getAccessor().getReader();
      }
      fields.put(name, reader);
      reader.setPosition(currentOffset);
    }
    return reader;
  }
View Full Code Here

      holder.start = offsets.getAccessor().get(index);
      holder.end = offsets.getAccessor().get(index+1);
    }

    public void get(int index, ComplexHolder holder) {
      FieldReader reader = getReader();
      reader.setPosition(index);
      holder.reader = reader;
    }
View Full Code Here

      int offset = h.start + arrayIndex;

      if (offset >= h.end) {
        holder.reader = NullReader.INSTANCE;
      } else {
        FieldReader r = vector.getAccessor().getReader();
        r.setPosition(offset);
        holder.reader = r;
      }
    }
View Full Code Here

      r.setPosition(index);
    }
  }

  public FieldReader reader(String name){
    FieldReader reader = fields.get(name);
    if(reader == null){
      ValueVector child = vector.get(name, ValueVector.class);
      if(child == null){
        reader = NullReader.INSTANCE;
      }else{
        reader = child.getAccessor().getReader();
      }
      fields.put(name, reader);
      reader.setPosition(currentOffset);
    }
    return reader;
  }
View Full Code Here

TOP

Related Classes of org.apache.drill.exec.vector.complex.reader.FieldReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.