Package org.apache.avro.Schema

Examples of org.apache.avro.Schema.Type


   * @see org.apache.gora.cassandra.query.CassandraColumn#getValue()
   */
  public Object getValue() {
    Field field = getField();
    Schema fieldSchema = field.schema();
    Type type = fieldSchema.getType();
    ByteBuffer byteBuffer = hColumn.getValue();
    if (byteBuffer == null) {
      return null;
    }
    Object value = null;
View Full Code Here


  }

  public Object getValue() {
    Field field = getField();
    Schema fieldSchema = field.schema();
    Type type = fieldSchema.getType();
   
    Object value = null;
   
    switch (type) {
      case ARRAY:
View Full Code Here

   * @see org.apache.gora.cassandra.query.CassandraColumn#getValue()
   */
  public Object getValue() {
    Field field = getField();
    Schema fieldSchema = field.schema();
    Type type = fieldSchema.getType();
    String valueString = hColumn.getValue();
    Object value = null;
   
    switch (type) {
      case STRING:
        value = new Utf8(valueString);
        break;
      case BYTES:
        // convert string to bytebuffer
        value = getByteBuffer(valueString);
        break;
      case INT:
        value = Integer.parseInt(valueString);
        break;
      case LONG:
        value = Long.parseLong(valueString);
        break;
      case FLOAT:
        value = Float.parseFloat(valueString);
        break;
      case ARRAY:
        // convert string to array
        valueString = valueString.substring(1, valueString.length()-1);
        String[] elements = valueString.split(", ");
       
        Type elementType = fieldSchema.getElementType().getType();
        if (elementType == Schema.Type.STRING) {
          // the array type is String
          GenericArray<String> genericArray = new GenericData.Array<String>(elements.length, Schema.createArray(Schema.create(Schema.Type.STRING)));
          for (String element: elements) {
            genericArray.add(element);
View Full Code Here

  }

  public Object getValue() {
    Field field = getField();
    Schema fieldSchema = field.schema();
    Type type = fieldSchema.getType();
   
    Object value = null;
   
    switch (type) {
      case MAP:
        Map<Utf8, Object> map = new StatefulHashMap<Utf8, Object>();
        Type valueType = fieldSchema.getValueType().getType();
       
        for (HColumn<String, String> hColumn : this.hSuperColumn.getColumns()) {
          String memberString = hColumn.getValue();
          Object memberValue = null;
          switch (valueType) {
View Full Code Here

      if (value.isDirty(field.pos())) {
        Object fieldValue = value.get(field.pos());
       
        // check if field has a nested structure (map or record)
        Schema fieldSchema = field.schema();
        Type type = fieldSchema.getType();
        switch(type) {
          case RECORD:
            Persistent persistent = (Persistent) fieldValue;
            Persistent newRecord = persistent.newInstance(new StateManagerImpl());
            for (Field member: fieldSchema.getFields()) {
View Full Code Here

   * @param field   the Avro field representing a datum
   * @param value   the field value
   */
  private void addOrUpdateField(String key, Field field, Object value) {
    Schema schema = field.schema();
    Type type = schema.getType();
    //LOG.info(field.name() + " " + type.name());
    switch (type) {
      case STRING:
        this.cassandraClient.addColumn(key, field.name(), value);
        break;
      case INT:
        this.cassandraClient.addColumn(key, field.name(), value);
        break;
      case LONG:
        this.cassandraClient.addColumn(key, field.name(), value);
        break;
      case BYTES:
        this.cassandraClient.addColumn(key, field.name(), value);
        break;
      case FLOAT:
        this.cassandraClient.addColumn(key, field.name(), value);
        break;
      case RECORD:
        if (value != null) {
          if (value instanceof PersistentBase) {
            PersistentBase persistentBase = (PersistentBase) value;
            for (Field member: schema.getFields()) {
             
              // TODO: hack, do not store empty arrays
              Object memberValue = persistentBase.get(member.pos());
              if (memberValue instanceof GenericArray<?>) {
                GenericArray<String> array = (GenericArray<String>) memberValue;
                if (array.size() == 0) {
                  continue;
                }
              }
             
              this.cassandraClient.addSubColumn(key, field.name(), member.name(), memberValue);
            }
          } else {
            LOG.info("Record not supported: " + value.toString());
           
          }
        }
        break;
      case MAP:
        if (value != null) {
          if (value instanceof StatefulHashMap<?, ?>) {
            //TODO cast to stateful map and only write dirty keys
            Map<Utf8, Object> map = (Map<Utf8, Object>) value;
            for (Utf8 mapKey: map.keySet()) {
             
              // TODO: hack, do not store empty arrays
              Object keyValue = map.get(mapKey);
              if (keyValue instanceof GenericArray<?>) {
                GenericArray<String> array = (GenericArray<String>) keyValue;
                if (array.size() == 0) {
                  continue;
                }
              }
             
              this.cassandraClient.addSubColumn(key, field.name(), mapKey.toString(), keyValue);             
            }
          } else {
            LOG.info("Map not supported: " + value.toString());
          }
        }
        break;
      default:
        LOG.info("Type not considered: " + type.name());     
    }
  }
View Full Code Here

   */
  public Schema toAvroSchema(int sqlType, String columnName) {
    Properties mappingJava = options.getMapColumnJava();

    // Try to apply any user specified mapping
    Type targetType;
    if (columnName != null && mappingJava.containsKey(columnName)) {
        targetType = toAvroType((String)mappingJava.get(columnName));
    } else {
      targetType = toAvroType(sqlType);
    }
View Full Code Here

  //TODO temporary solution, has to be changed after implementation of saving the index of union type
  private int getResolvedUnionIndex(Schema unionScema) {
    if (unionScema.getTypes().size() == 2) {

      // schema [type0, type1]
      Type type0 = unionScema.getTypes().get(0).getType();
      Type type1 = unionScema.getTypes().get(1).getType();

      // Check if types are different and there's a "null", like ["null","type"]
      // or ["type","null"]
      if (!type0.equals(type1)
          && (type0.equals(Schema.Type.NULL) || type1.equals(Schema.Type.NULL))) {

        if (type0.equals(Schema.Type.NULL))
          return 1;
        else
          return 0;
View Full Code Here

  @SuppressWarnings("unchecked")
  public static <T> T fromBytes( byte[] val, Schema schema
      , SpecificDatumReader<T> datumReader, T object)
  throws IOException {
    Type type = schema.getType();
    switch (type) {
    case ENUM:
      String symbol = schema.getEnumSymbols().get(val[0]);
      return (T)Enum.valueOf(ReflectData.get().getClass(schema), symbol);
    case STRING:  return (T)new Utf8(toString(val));
View Full Code Here

  @SuppressWarnings("unchecked")
  public static <T> byte[] toBytes(T o, Schema schema
      , SpecificDatumWriter<T> datumWriter)
  throws IOException {
    Type type = schema.getType();
    switch (type) {
    case STRING:  return toBytes(((Utf8)o).toString()); // TODO: maybe ((Utf8)o).getBytes(); ?
    case BYTES:   return ((ByteBuffer)o).array();
    case INT:     return vintToBytes((Integer)o);
    case LONG:    return vintToBytes((Long)o);
View Full Code Here

TOP

Related Classes of org.apache.avro.Schema.Type

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.