Package com.datasalt.pangool.io.Schema

Examples of com.datasalt.pangool.io.Schema.Field


   * @throws IOException
   */
  private void write(Schema destinationSchema, ITuple tuple,
      int[] translationTable, DataOutput output) throws IOException {
    for (int i = 0; i < destinationSchema.getFields().size(); i++) {
      Field field = destinationSchema.getField(i);
      Type fieldType = field.getType();
      Object element = tuple.get(translationTable[i]);
      try {
        switch(fieldType){
        case INT:
          WritableUtils.writeVInt(output, (Integer) element); break;
View Full Code Here


  }

  public void readFields(ITuple tuple, DataInput input) throws IOException {
    Schema schema = tuple.getSchema();
    for(int index = 0; index < schema.getFields().size(); index++) {
      Field field = schema.getField(index);
      switch(field.getType()){
      case INT:  tuple.set(index,WritableUtils.readVInt(input)); break;
      case LONG: tuple.set(index,WritableUtils.readVLong(input)); break;
      case DOUBLE: tuple.set(index,input.readDouble()); break;
      case FLOAT: tuple.set(index,input.readFloat()); break;
      case STRING: readUtf8(input,tuple,index); break;
      case BOOLEAN:
        byte b = input.readByte();
        tuple.set(index,(b != 0));
        break;
      case ENUM: readEnum(input,tuple,field.getObjectClass(),index); break;
      case OBJECT: readCustomObject(input,tuple,field.getObjectClass(),index); break;
      default:
        throw new IOException("Not supported type:" + field.getType());
      }
    }
  }
View Full Code Here

      }
    }
  }

  private static Schema getPangoolTweetSchema() {
    Field tweetIdField = Field.create("tweet_id",Schema.Field.Type.INT);
    Field tweetHashTags = Fields.createAvroField("tweet_hashtags",
        getAvroStringArraySchema(),false);
    return new Schema("tweet",Arrays.asList(tweetIdField,tweetHashTags));
  }
View Full Code Here

        getAvroStringArraySchema(),false);
    return new Schema("tweet",Arrays.asList(tweetIdField,tweetHashTags));
  }
 
  private static Schema getPangoolRetweetSchema(){
    Field userId = Field.create("username",Schema.Field.Type.STRING);
    Field tweetId = Field.create("tweet_id",Schema.Field.Type.INT);
    return new Schema("retweet",Arrays.asList(userId,tweetId));
  }
View Full Code Here

  public AvroTopicalWordCount() {
    super("Usage: AvroTopicalWordCount [input_path] [output_path]");
  }

  static Schema getSchema() {
    Field avroField = Fields.createAvroField("my_avro",getAvroSchema(),false);
    return new Schema("schema",Arrays.asList(avroField));
  }
View Full Code Here

    Schema intermediateSchema = mrConfig.getIntermediateSchemas().get(0);
    Criteria commonSortCriteria = mrConfig.getCommonCriteria();
    List<Field> commonFields = new ArrayList<Field>();
    for(SortElement sortElement : commonSortCriteria.getElements()) {
      String fieldName = sortElement.getName();
      Field field = checkFieldInAllSchemas(fieldName);
      commonFields.add(Field.cloneField(field, fieldName));
    }

    // adding the rest
    for(Field field : intermediateSchema.getFields()) {
      Map<String,String> aliases = mrConfig.getFieldAliases(intermediateSchema.getName());
      if(!containsField(field.getName(),commonFields,aliases))  {
          commonFields.add(field);
      }
    }
    this.commonSchema = new Schema("common", commonFields);
  }
View Full Code Here

  private void calculateMultipleSourcesSubSchemas() throws TupleMRException {
    Criteria commonSortCriteria = mrConfig.getCommonCriteria();
    List<Field> commonFields = new ArrayList<Field>();
    for(SortElement sortElement : commonSortCriteria.getElements()) {
      String fieldName = sortElement.getName();
      Field field = checkFieldInAllSchemas(fieldName);
     
      commonFields.add(Field.cloneField(field,fieldName));
    }

    this.commonSchema = new Schema("common", commonFields);
    this.specificSchemas = new ArrayList<Schema>();
    List<List<Field>> specificFieldsBySource = new ArrayList<List<Field>>();

    for(int schemaId = 0; schemaId < mrConfig.getNumIntermediateSchemas(); schemaId++) {
      Criteria specificCriteria = mrConfig.getSpecificOrderBys().get(schemaId);
      List<Field> specificFields = new ArrayList<Field>();
      if(specificCriteria != null) {
        for(SortElement sortElement : specificCriteria.getElements()) {
          String fieldName = sortElement.getName();
          Field field = checkFieldInSchema(fieldName, schemaId);
          specificFields.add(Field.cloneField(field,fieldName));
        }
      }
      specificFieldsBySource.add(specificFields);
    }

    for(int i = 0; i < mrConfig.getNumIntermediateSchemas(); i++) {
      Schema sourceSchema = mrConfig.getIntermediateSchema(i);
      List<Field> specificFields = specificFieldsBySource.get(i);
      for(Field field : sourceSchema.getFields()) {
        Map<String,String> sourceAliases = mrConfig.getFieldAliases(sourceSchema.getName());
        if(!containsField(field.getName(),commonSchema.getFields(),sourceAliases)
            && !containsField(field.getName(), specificFields,sourceAliases)) {
          specificFields.add(field);
        }
      }
      this.specificSchemas.add(new Schema("specific", specificFields));
    }
View Full Code Here

    }
    return false;
  }

  private Field checkFieldInAllSchemas(String name) throws TupleMRException {
    Field field = null;
    for(int i = 0; i < mrConfig.getIntermediateSchemas().size(); i++) {
      Field fieldInSource = checkFieldInSchema(name, i);
      if(field == null) {
        field = fieldInSource;
      } else if(field.getType() != fieldInSource.getType() || field.getObjectClass() != fieldInSource.getObjectClass()) {
        throw new TupleMRException("The type for field '" + name
            + "' is not the same in all the sources");
      }
    }
    return field;
View Full Code Here

  }

  private Field checkFieldInSchema(String fieldName, int schemaId)
      throws TupleMRException {
    Schema schema = mrConfig.getIntermediateSchema(schemaId);
    Field field = getFieldUsingAliases(schema,fieldName);
    if(field == null) {
      throw new TupleMRException("Field '" + fieldName + "' not present in source '"
          + schema.getName() + "' " + schema);
    }
    return field;
View Full Code Here

  public static void toRecord(ITuple tuple, Record record,
      DataOutputBuffer tmpOutputBuffer, HadoopSerialization ser) throws IOException {
    Schema pangoolSchema = tuple.getSchema();
    for(int i = 0; i < pangoolSchema.getFields().size(); i++) {
      Object obj = tuple.get(i);
      Field field = pangoolSchema.getField(i);
      switch(field.getType()){
      case INT:
      case LONG:
      case FLOAT:
      case BOOLEAN:
      case DOUBLE:
        record.put(i, obj); //optimistic
        break;
      case OBJECT:
        tmpOutputBuffer.reset();
        ser.ser(obj, tmpOutputBuffer);
        ByteBuffer buffer = ByteBuffer.wrap(tmpOutputBuffer.getData(), 0, tmpOutputBuffer.getLength());
        record.put(i, buffer);
        break;
      case ENUM:
        record.put(i,obj.toString());
        break;
      case STRING:
        record.put(i,new Utf8(obj.toString())); //could be directly String ?
        break;
      default:
          throw
          new IOException("Not correspondence to Avro type from Pangool type " + field.getType());
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.datasalt.pangool.io.Schema.Field

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.