Examples of ITuple


Examples of com.datasalt.pangool.io.ITuple

      this.out = new DataOutputStream(out);
    }
  }

  public void serialize(DatumWrapper<ITuple> wrapper) throws IOException {
    ITuple tuple = wrapper.datum();
    if (isMultipleSources) {
      multipleSourcesSerialization(tuple);
    } else {
      oneSourceSerialization(tuple);
    }
View Full Code Here

Examples of com.datasalt.pangool.io.ITuple

    if(isRollup) {
      t.swapInstances();
      this.cachedTuples.swapInstances();
    }

    ITuple tuple = (multipleSources) ?
        deserializeMultipleSources() : deserializeOneSource(t.datum());
    t.datum(tuple);
   
    return t;
  }
View Full Code Here

Examples of com.datasalt.pangool.io.ITuple

    return t;
  }
 
  private ITuple deserializeMultipleSources() throws IOException {
    CachedTuples tuples = cachedTuples.datum();
    ITuple commonTuple =tuples.commonTuple;
   
    readFields(commonTuple,in,serInfo.getCommonSchemaDeserializers());
    int schemaId = WritableUtils.readVInt(in);
    ITuple specificTuple = tuples.specificTuples.get(schemaId);
    readFields(specificTuple,in,serInfo.getSpecificSchemaDeserializers().get(schemaId));
    ITuple result = tuples.resultTuples.get(schemaId);
    mixIntermediateIntoResult(commonTuple,specificTuple,result,schemaId);
    return result;
  }
View Full Code Here

Examples of com.datasalt.pangool.io.ITuple

    }
  }
 
  private ITuple deserializeOneSource(ITuple reuse) throws IOException {
    CachedTuples tuples = cachedTuples.datum();
    ITuple commonTuple = tuples.commonTuple;
    readFields(commonTuple,in,serInfo.getCommonSchemaDeserializers());
    if (reuse == null){
      reuse = tuples.resultTuples.get(0);
    }
    int[] commonTranslation = serInfo.getCommonSchemaIndexTranslation(0); //just one common schema
    for (int i =0 ; i < commonTranslation.length ; i++){
      int destPos = commonTranslation[i];
      reuse.set(destPos,commonTuple.get(i));
    }
    return reuse;
  }
View Full Code Here

Examples of com.datasalt.pangool.io.ITuple

 
  /**
   * Moves data between a Record and a Tuple
   */
  public ITuple toTuple(Record record, ITuple reuse) throws IOException {
    ITuple tuple = reuse;
    if (tuple == null){
      tuple = new Tuple(pangoolSchema);
    }
   
    Schema pangoolSchema = tuple.getSchema();
    for(org.apache.avro.Schema.Field avroField : avroSchema.getFields()) {
      int pos = avroField.pos();
      Object objRecord = record.get(pos);
      Field pangoolField = pangoolSchema.getField(pos);
      switch(pangoolField.getType()){
      case INT:
      case LONG:
      case BOOLEAN:
      case FLOAT:
      case DOUBLE:
        tuple.set(pos,objRecord); //very optimistic
        break;
      case STRING:{
        if (!(tuple.get(pos) instanceof Utf8)){
          tuple.set(pos,new com.datasalt.pangool.io.Utf8());
        }
        com.datasalt.pangool.io.Utf8 utf8=(com.datasalt.pangool.io.Utf8)tuple.get(pos);
        if (objRecord instanceof String){
          utf8.set((String)objRecord);
        } else if (objRecord instanceof Utf8){
          Utf8 avroUtf8 = (Utf8)objRecord;
          utf8.set(avroUtf8.getBytes(),0,avroUtf8.getByteLength());
        } else {
          throw new IOException("Not supported avro field " +
              org.apache.avro.Schema.Type.STRING + " with instance " + objRecord.getClass().getName());
        }
        break;}
      case ENUM:{
          Class clazz = pangoolField.getObjectClass();
          Enum e = Enum.valueOf(clazz,objRecord.toString());
          tuple.set(pos,e);
        break;
      }
      case BYTES:
        tuple.set(pos,objRecord); //TODO FIXME this should copy bytes really, not reference!
        break;
      case OBJECT:
        FieldDeserializer customDeser = customDeserializers[pos];
        if (objRecord instanceof byte[]){
          inputBuffer.reset((byte[])objRecord,((byte[])objRecord).length);
        } else if (objRecord instanceof ByteBuffer){
          ByteBuffer buffer = (ByteBuffer)objRecord;
          int offset = buffer.arrayOffset()+buffer.position();
          int length = buffer.limit()- buffer.position();
          inputBuffer.reset(buffer.array(),offset,length);
        } else {
          throw new PangoolRuntimeException("Can't convert to OBJECT from instance " + objRecord.getClass());
        }
        if (customDeser != null){
          customDeser.open(inputBuffer);
          tuple.set(pos,customDeser.deserialize(tuple.get(pos))); //TODO FIXME avro deserializer shouldn't reuse objects sometimes (UNION ?)
          customDeser.close(); //TODO is this ok ?
         
        } else {
            //no custom deser , then use Hadoop serializers registered in "io.serializations"
          Class clazz = pangoolField.getObjectClass();
          if(tuple.get(pos) == null || tuple.get(pos).getClass() != clazz) {
            tuple.set(pos, ReflectionUtils.newInstance(clazz, conf));
          }
          hadoopSer.deser(tuple.get(pos),inputBuffer);
        }
        break;
      default:
        throw new IOException("Not supported avro type : " + avroField.schema().getType());
      }
View Full Code Here

Examples of com.datasalt.pangool.io.ITuple

  public void open(OutputStream out) {
    tupleSerializer.open(out);
  }

  public void serialize(DatumWrapper<ITuple> wrapper) throws IOException {
    ITuple tuple = wrapper.datum();
    if (isMultipleSources) {
      multipleSourcesSerialization(tuple);
    } else {
      oneSourceSerialization(tuple);
    }
View Full Code Here

Examples of com.datasalt.pangool.io.ITuple

   */
  public static void readTuples(Path file, Configuration conf, TupleVisitor iterator) throws IOException, InterruptedException {
    TupleInputReader reader = new TupleInputReader(conf);
    reader.initialize(new Path(file + ""), conf);
    while(reader.nextKeyValueNoSync()) {
      ITuple tuple = reader.getCurrentKey();
      iterator.onTuple(tuple);
    }
    reader.close();
  }
View Full Code Here

Examples of com.datasalt.pangool.io.ITuple

  public int getPartition(DatumWrapper<ITuple> key, NullWritable value, int numPartitions) {
    if(numPartitions == 1) {
      // in this case the schema is not checked if it's valid
      return 0;
    } else {
      ITuple tuple = key.datum();
      String sourceName = tuple.getSchema().getName();
      Integer schemaId = tupleMRConfig.getSchemaIdByName(sourceName);
      if(schemaId == null) {
        throw new RuntimeException("Schema name '" + sourceName
            + "' is unknown. Known schemas are : "
            + tupleMRConfig.getIntermediateSchemaNames());
View Full Code Here

Examples of com.datasalt.pangool.io.ITuple

    @Override
    public void reduce(ITuple group, Iterable<ITuple> tuples, TupleMRContext context, Collector collector)
        throws IOException, InterruptedException, TupleMRException {

      int count = 0;
      ITuple outputTuple = null;
      Record outputRecord=null;
      for(ITuple tuple : tuples) {
        Record record = (Record)tuple.get("my_avro");
        count += (Integer) record.get("count");
        outputTuple = tuple;
        outputRecord = record;
      }
      outputRecord.put("count",count);
      outputTuple.set("my_avro",outputRecord);
      collector.write(outputTuple, NullWritable.get());
    }
View Full Code Here

Examples of com.datasalt.pangool.io.ITuple

    @Override
    public void reduce(ITuple group, Iterable<ITuple> tuples, TupleMRContext context, Collector collector)
        throws IOException, InterruptedException, TupleMRException {

      int count = 0;
      ITuple outputTuple = null;
      Record outputRecord = null;
      for(ITuple tuple : tuples) {
        Record record = (Record) tuple.get("my_avro");
        count += (Integer) record.get("count");
        outputTuple = tuple;
        outputRecord = record;
      }
      outputRecord.put("count", count);
      outputTuple.set("my_avro", outputRecord);
      collector.write(outputTuple, NullWritable.get());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.