Package com.datasalt.pangool.io.Schema

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


  }

  void write(Schema destinationSchema, ITuple tuple, int[] translationTable, Serializer[] customSerializers)
      throws IOException {
    for(int i = 0; i < destinationSchema.getFields().size(); i++) {
      Field field = destinationSchema.getField(i);
      Type fieldType = field.getType();
      Object element;
      if(translationTable == null) {
        element = tuple.get(i);
      } else {
        element = tuple.get(translationTable[i]);
View Full Code Here


            }
            String currentValue = "";
            try {
              currentValue = readLine.get(index);
              if(currentValue != null) {
                Field field = schema.getFields().get(i);
                switch(field.getType()) {
                case INT:
                case LONG:
                case FLOAT:
                case DOUBLE:
                  processNumber(field.getType(), tuple, i, currentValue);
                  break;
                case ENUM:
                  Class clazz = field.getObjectClass();
                  tuple.set(i, Enum.valueOf(clazz, currentValue.trim()));
                  break;
                case STRING:
                  if (type == InputType.CSV) {
                    tuple.set(i, currentValue);
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

    Field tweetHashTags = Fields.createAvroField("tweet_hashtags", 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

    super("Usage: AvroCustomSerializationJob [input_path] [output_path]");
  }

  static Schema getSchema() {
    org.apache.avro.Schema avroSchema = getAvroSchema();
    Field avroField = Field.createObject("my_avro",AvroFieldSerializer.class,AvroFieldDeserializer.class);
    avroField.addProp("avro.schema",avroSchema.toString());
    return new Schema("schema",Arrays.asList(avroField));
  }
View Full Code Here

            }
            String currentValue = "";
            try {
              currentValue = readLine.get(index);
              if(currentValue != null) {
                Field field = schema.getFields().get(i);
                switch(field.getType()) {
                case INT:
                case LONG:
                case FLOAT:
                case DOUBLE:
                  processNumber(field.getType(), tuple, i, currentValue);
                  break;
                case ENUM:
                  Class clazz = field.getObjectClass();
                  tuple.set(i, Enum.valueOf(clazz, currentValue.trim()));
                  break;
                case STRING:
                  if (type == InputType.CSV) {
                    tuple.set(i, currentValue);
View Full Code Here

    }

    // Field by field deseralization
    for(int index = 0; index < schema.getFields().size(); index++) {
      Deserializer customDeser = customDeserializers[index];
      Field field = schema.getField(index);

      // Nulls control
      if (field.isNullable() && nullsAbsolute.flags[index]) {
        // Null field. Nothing to deserialize.
        continue;
      }

      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 BYTES:
        readBytes(input, tuple, index);
        break;
      case OBJECT:
        readCustomObject(input, tuple, field.getObjectClass(), index, customDeser);
        break;
      default:
        throw new IOException("Not supported type:" + field.getType());
      }
    }
  }
View Full Code Here

      }
      nulls.ser(out);
    }

    for (int i = 0; i < destinationSchema.getFields().size(); i++) {
      Field field = destinationSchema.getField(i);
      Type fieldType = field.getType();
      Object element = valueAt(i, tuple, translationTable);
      if (element == null) {
        if (field.isNullable()) {
          // Nullable null fields don't need serialization.
          continue;
        } else {
          raiseUnexpectedNullException(field, element);
        }
View Full Code Here

  public static String toString(ITuple tuple) {
    Schema schema = tuple.getSchema();
    StringBuilder b = new StringBuilder();
    b.append("{");
    for (int i = 0; i < schema.getFields().size(); i++) {
      Field f = schema.getField(i);
      if (i != 0) {
        b.append(",");
      }
      b.append("\"").append(f.getName()).append("\"").append(":");
      if (tuple.get(i) == null) {
        b.append("null");
        continue;
      }
      switch (f.getType()) {
        case INT:
        case LONG:
        case FLOAT:
        case DOUBLE:
        case BOOLEAN:
          b.append(tuple.get(i));
          break;
        case STRING:
        case ENUM:

          b.append("\"").append(tuple.get(i)).append("\"");
          break;
        case OBJECT:
          b.append("{").append(tuple.get(i).toString()).append("}");
          break;
        case BYTES:
          Object o = tuple.get(i);
          b.append("{\"bytes\": \"");
          byte[] bytes;
          int offset, length;
          if (o instanceof ByteBuffer) {
            ByteBuffer byteBuffer = (ByteBuffer) o;
            bytes = byteBuffer.array();
            offset = byteBuffer.arrayOffset() + byteBuffer.position();
            length = byteBuffer.limit() - byteBuffer.position();
          } else {
            //byte[]
            bytes = (byte[]) o;
            offset = 0;
            length = bytes.length;
          }
          for (int p = offset; p < offset + length; p++) {
            b.append((char) bytes[p]);
          }
          b.append("\"}");
          break;
        default:
          throw new PangoolRuntimeException("Not stringifiable type :" + f.getType());
      }
    }
    b.append("}");
    return b.toString();
  }
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.