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

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


  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


      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

      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(idx());
    }
    return reader;
  }
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

      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

      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

        break;
      case MAP:
        gen.writeStartObject();
        if (reader.isSet()) {
          for(String name : reader){
            FieldReader childReader = reader.reader(name);
            if(childReader.isSet()){
              gen.writeFieldName(name);
              writeValue(childReader);
            }
          }
        }
        gen.writeEndObject();
        break;
      case NULL:
        gen.writeNull();
        break;

      case VAR16CHAR:
        gen.writeString(reader.readString());
        break;
      case VARBINARY:
        gen.writeBinary(reader.readByteArray());
        break;
      case VARCHAR:
        gen.writeString(reader.readText().toString());
        break;

      }
      break;

    case REPEATED:
      gen.writeStartArray();
      switch (mt) {
      case FLOAT4:
        for(int i = 0; i < reader.size(); i++){
          gen.writeNumber(reader.readFloat(i));
        }

        break;
      case FLOAT8:
        for(int i = 0; i < reader.size(); i++){
          gen.writeNumber(reader.readDouble(i));
        }
        break;
      case INT:
        for(int i = 0; i < reader.size(); i++){
          gen.writeNumber(reader.readInteger(i));
        }
        break;
      case SMALLINT:
        for(int i = 0; i < reader.size(); i++){
          gen.writeNumber(reader.readShort(i));
        }
        break;
      case TINYINT:
        for(int i = 0; i < reader.size(); i++){
          gen.writeNumber(reader.readByte(i));
        }
        break;
      case BIGINT:
        for(int i = 0; i < reader.size(); i++){
          gen.writeNumber(reader.readLong(i));
        }
        break;
      case BIT:
        for(int i = 0; i < reader.size(); i++){
        gen.writeBoolean(reader.readBoolean(i));
        }
        break;

      case DATE:
      case TIME:
      case TIMESTAMP:
      case TIMESTAMPTZ:
        for(int i = 0; i < reader.size(); i++){
        gen.writeString(reader.readDateTime(i).toString());
        }

      case INTERVALYEAR:
      case INTERVALDAY:
      case INTERVAL:
        for(int i = 0; i < reader.size(); i++){
        gen.writeString(reader.readPeriod(i).toString());
        }
        break;
      case DECIMAL28DENSE:
      case DECIMAL28SPARSE:
      case DECIMAL38DENSE:
      case DECIMAL38SPARSE:
      case DECIMAL9:
      case DECIMAL18:
        for(int i = 0; i < reader.size(); i++){
        gen.writeNumber(reader.readBigDecimal(i));
        }
        break;

      case LIST:
        for(int i = 0; i < reader.size(); i++){
          while(reader.next()){
            writeValue(reader.reader());
          }
        }
        break;
      case MAP:
        while(reader.next()){
          gen.writeStartObject();
          for(String name : reader){
            FieldReader mapField = reader.reader(name);
            if(mapField.isSet()){
              gen.writeFieldName(name);
              writeValue(mapField);
            }
          }
          gen.writeEndObject();
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();

  }
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

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.