Ejemplo n.º 1
0
  public byte[] getNext() throws Exception {

    if (!m_rr.hasNext()) {
      return null;
    }

    OrcStruct lv_row = (OrcStruct) m_rr.next(null);
    Object lv_field_val = null;
    ByteBuffer lv_row_buffer;

    byte[] lv_row_ba = new byte[4096];
    lv_row_buffer = ByteBuffer.wrap(lv_row_ba);
    for (int i = 0; i < m_fields.size(); i++) {
      lv_field_val = lv_row.getFieldValue(i);
      if (lv_field_val == null) {
        lv_row_buffer.putInt(0);
        continue;
      }
      String lv_field_val_str = lv_field_val.toString();
      lv_row_buffer.putInt(lv_field_val_str.length());
      if (lv_field_val != null) {
        lv_row_buffer.put(lv_field_val_str.getBytes());
      }
    }

    System.out.println(lv_row_buffer);
    return lv_row_buffer.array();
  }
Ejemplo n.º 2
0
  // Dumps the contents of the file as ByteBuffer.
  public void readFile_ByteBuffer() throws Exception {

    OrcStruct lv_row = null;
    Object lv_field_val = null;
    ByteBuffer lv_row_buffer;
    while (m_rr.hasNext()) {
      byte[] lv_row_ba = new byte[4096];
      lv_row_buffer = ByteBuffer.wrap(lv_row_ba);
      lv_row = (OrcStruct) m_rr.next(lv_row);
      for (int i = 0; i < m_fields.size(); i++) {
        lv_field_val = lv_row.getFieldValue(i);
        if (lv_field_val == null) {
          lv_row_buffer.putInt(0);
          continue;
        }
        String lv_field_val_str = lv_field_val.toString();
        lv_row_buffer.putInt(lv_field_val_str.length());
        if (lv_field_val != null) {
          lv_row_buffer.put(lv_field_val_str.getBytes());
        }
      }
      System.out.println(lv_row_buffer);
      //	    System.out.println(new String(lv_row_buffer.array()));
    }
  }
Ejemplo n.º 3
0
  private void handle(final Reader in, final Writer out, final RecordProcessor processor)
      throws Exception {
    final RecordReader reader = new RecordReader(in);
    final OutputStreamOutput output = new OutputStreamOutput(out);

    try {
      while (reader.hasNext()) {
        processor.processNext(reader, output);
      }
    } finally {
      try {
        output.close();
      } finally {
        reader.close();
      }
    }
  }
Ejemplo n.º 4
0
  // Dumps the content of the file. The columns are '|' separated.
  public void readFile_String() throws Exception {

    OrcStruct lv_row = null;
    Object lv_field_val = null;
    StringBuilder lv_row_string = new StringBuilder(1024);
    while (m_rr.hasNext()) {
      lv_row = (OrcStruct) m_rr.next(lv_row);
      lv_row_string.setLength(0);
      for (int i = 0; i < m_fields.size(); i++) {
        lv_field_val = lv_row.getFieldValue(i);
        if (lv_field_val != null) {
          lv_row_string.append(lv_field_val);
        }
        lv_row_string.append('|');
      }
      System.out.println(lv_row_string);
    }
  }
Ejemplo n.º 5
0
    void next(OrcStruct next) throws IOException {
      if (recordReader.hasNext()) {
        nextRecord = (OrcStruct) recordReader.next(next);
        // set the key
        key.setValues(
            OrcRecordUpdater.getOriginalTransaction(nextRecord),
            OrcRecordUpdater.getBucket(nextRecord),
            OrcRecordUpdater.getRowId(nextRecord),
            OrcRecordUpdater.getCurrentTransaction(nextRecord));

        // if this record is larger than maxKey, we need to stop
        if (maxKey != null && key.compareRow(maxKey) > 0) {
          LOG.debug("key " + key + " > maxkey " + maxKey);
          nextRecord = null;
          recordReader.close();
        }
      } else {
        nextRecord = null;
        recordReader.close();
      }
    }
Ejemplo n.º 6
0
 @Override
 public boolean hasNext() {
   return (reader.hasNext() && key.equals(reader.peek()[0]));
 }
Ejemplo n.º 7
0
  // This method is just for experimentation.
  public void testRead() throws Exception {

    m_reader = OrcFile.createReader(m_file_path, OrcFile.readerOptions(m_conf));

    System.out.println("Reader: " + m_reader);

    System.out.println("# Rows: " + m_reader.getNumberOfRows());
    m_types = m_reader.getTypes();
    System.out.println("# Types in the file: " + m_types.size());

    for (int i = 0; i < m_types.size(); i++) {
      System.out.println("Type " + i + ": " + m_types.get(i).getKind());
    }

    System.out.println("Compression: " + m_reader.getCompression());
    if (m_reader.getCompression() != CompressionKind.NONE) {
      System.out.println("Compression size: " + m_reader.getCompressionSize());
    }

    StructObjectInspector m_oi = (StructObjectInspector) m_reader.getObjectInspector();

    System.out.println("object inspector type category: " + m_oi.getCategory());
    System.out.println("object inspector type name    : " + m_oi.getTypeName());

    m_fields = m_oi.getAllStructFieldRefs();
    System.out.println("Number of columns in the table: " + m_fields.size());

    RecordReader m_rr = m_reader.rows();

    // Print the type info:
    for (int i = 0; i < m_fields.size(); i++) {
      System.out.println("Column " + i + " name: " + m_fields.get(i).getFieldName());
      ObjectInspector lv_foi = m_fields.get(i).getFieldObjectInspector();
      System.out.println("Column " + i + " type category: " + lv_foi.getCategory());
      System.out.println("Column " + i + " type name: " + lv_foi.getTypeName());
      //		Object lv_column_val = m_oi.getStructFieldData(lv_row, m_fields.get(i));
      // System.out.print("Column " + i + " value: " + lv_row.getFieldValue(i));
    }

    OrcStruct lv_row = null;
    Object lv_field_val = null;
    StringBuilder lv_row_string = new StringBuilder(1024);
    while (m_rr.hasNext()) {
      lv_row = (OrcStruct) m_rr.next(lv_row);
      lv_row_string.setLength(0);
      for (int i = 0; i < m_fields.size(); i++) {
        lv_field_val = lv_row.getFieldValue(i);
        if (lv_field_val != null) {
          lv_row_string.append(lv_field_val);
        }
        lv_row_string.append('|');
      }
      System.out.println(lv_row_string);
    }

    /**
     * Typecasting to appropriate type based on the 'kind' if (OrcProto.Type.Kind.INT ==
     * m_types.get(1).getKind()) { IntWritable lvf_1_val = (IntWritable) lv_row.getFieldValue(0);
     * System.out.println("Column 1 value: " + lvf_1_val); }
     */
  }