Package org.apache.avro.Schema

Examples of org.apache.avro.Schema.Type


    }

    try
    {
      Schema fieldSchema = SchemaHelper.unwindUnionSchema(f)// == f.schema() if f is not a union
      Type avroFieldType = fieldSchema.getType();

      if (_sDebug)
      {
        LOG.debug("Checking for type:" + avroFieldType + ", Field:" + f.name() +
                  ", Exp:" + databaseFieldValue + ", Got:" + avroField);
View Full Code Here


    for (Field avroField : fields)
    {
      int dbFieldPosition = 0;
      // this is just avroField.schema() if avroField isn't a union; else schema of first non-null subtype:
      Schema fieldSchema = SchemaHelper.unwindUnionSchema(avroField);
      Type avroFieldType = fieldSchema.getType();

      String dbFieldPositionStr = SchemaHelper.getMetaField(avroField, "dbFieldPosition");
      if (avroFieldType == Type.ARRAY)
      {
        if (null == dbFieldPositionStr || dbFieldPositionStr.isEmpty())
View Full Code Here

      for (int i = 0; iter.hasNext(); i++) {
        Field field = iter.next();
        if (!stateManager.isDirty(persistent, i)) {
          continue;
        }
        Type type = field.schema().getType();
        Object o = persistent.get(i);
        HBaseColumn hcol = mapping.getColumn(field.name());
        if (hcol == null) {
          throw new RuntimeException("HBase mapping for field ["+ persistent.getClass().getName() +
              "#"+ field.name()+"] not found. Wrong gora-hbase-mapping.xml?");
View Full Code Here

      if (value.isDirty(fieldPos)) {
        Object fieldValue = value.get(fieldPos);
       
        // check if field has a nested structure (array, map, or record)
        Schema fieldSchema = field.schema();
        Type type = fieldSchema.getType();
        switch(type) {
          case RECORD:
            PersistentBase persistent = (PersistentBase) fieldValue;
            PersistentBase newRecord = (PersistentBase) 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(K key, Field field, Object value) {
    Schema schema = field.schema();
    Type type = schema.getType();
    switch (type) {
      case STRING:
      case BOOLEAN:
      case INT:
      case LONG:
      case BYTES:
      case FLOAT:
      case DOUBLE:
      case FIXED:
        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<?>) {
                if (((GenericArray)memberValue).size() == 0) {
                  continue;
                }
              } else if (memberValue instanceof StatefulHashMap<?,?>) {
                if (((StatefulHashMap)memberValue).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<?, ?>) {
            this.cassandraClient.addStatefulHashMap(key, field.name(), (StatefulHashMap<Utf8,Object>)value);
          } else {
            LOG.info("Map not supported: " + value.toString());
          }
        }
        break;
      case ARRAY:
        if (value != null) {
          if (value instanceof GenericArray<?>) {
            this.cassandraClient.addGenericArray(key, field.name(), (GenericArray)value);
          } else {
            LOG.info("Array not supported: " + value.toString());
          }
        }
        break;
      default:
        LOG.info("Type not considered: " + type.name());     
    }
  }
View Full Code Here

        if (txnFieldType == null)
        {
          throw new Exception(
              "Unable to find field called 'txn'. Cannot proceeed\n");
        }
        Type txnType = SchemaHelper.getAnyType(txnFieldType);

        /*
         * Determine primary key of schema. This is assumed to be invariant
         * across versions
         */
 
View Full Code Here

      // Get the Avro field type information
      String schemaFieldName = field.name();
      // This is just field.schema() if field is not a union; but if it IS one,
      // this is the schema of the first non-null type within the union:
      Schema fieldSchema = SchemaHelper.unwindUnionSchema(field);
      Type avroFieldType = fieldSchema.getType();

      if (avroFieldType == Type.ARRAY)
      {
        // Process as an array.  Note that we're encoding to Avro's internal representation rather
        // than to Avro binary format, which is what allows us to directly encode one of the union's
View Full Code Here

      }
    }
    else
    {
      Schema recordSchema = SchemaHelper.unwindUnionSchema(field)// == field.schema() if not a union
      Type recordFieldType = recordSchema.getType();

      switch (recordFieldType)
      {
        case BOOLEAN:
        case BYTES:
View Full Code Here

  throws EventCreationException
  {
    // Get the field name and type from the event schema
    String schemaFieldName = field.name();
    Schema fieldSchema = SchemaHelper.unwindUnionSchema(field)// == field.schema() if not a union
    Type avroFieldType = fieldSchema.getType();

    if (databaseFieldValue == null)
    {
      // The field value was null. If the field is nullable then we do nothing. Otherwise this is an error.
      boolean isNullAllowedInSchema = SchemaHelper.isNullable(field);
View Full Code Here

   *         union is returned.
   */
  public static Schema unwindUnionSchema(Field field)
  {
    Schema schema = field.schema();
    Type fieldType = schema.getType();

    // If this is a union, check the child types and return the first non-null schema
    if (fieldType == Type.UNION)
    {
      List<Schema> unionTypes = schema.getTypes();
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.