Package org.apache.avro.Schema

Examples of org.apache.avro.Schema.Field


                if (fields == null)
                    fields = new ArrayList<Field>();

                int index = Integer.parseInt(name.substring("field".length()));
                String content = ((String) value).trim();
                Field field = null;
                if (content.equalsIgnoreCase(NOTNULL)) {
                    /* null means deriving avro schema from pig schema but not null*/
                    field = AvroStorageUtils.createUDField(index, null);
                } else if (content.startsWith("def:")) {
                    if (schemaManager == null)
View Full Code Here


                outname = FIELD_NAME + "_" + i; // field name cannot be null

            /* get doc of output */
            String desc = pigFields[i].getDescription();

            outFields.add(new Field(outname, fieldSchema, desc, null));
        }

        outSchema.setFields(outFields);
        return outSchema;

View Full Code Here

        List<Schema.Field> outFields = new ArrayList<Schema.Field>();

        for (int i = 0; i < pigFields.length; i++) {
            /* get user defined avro field schema */
            Field inputField = isPartialSchema ? AvroStorageUtils.getUDField(avroSchema, i) : inFields.get(i);

            /* get schema */
            Schema fieldSchema = null;
            if (inputField == null) {
                /* convert pig schema (nullable) */
                fieldSchema = convert(pigFields[i], true);
            } else if (inputField.schema() == null) {
                /* convert pig schema (not-null) */
                fieldSchema = convert(pigFields[i], false);
            } else {
                /* validate pigFields[i] with given avro schema */
                fieldSchema = validateAndConvert(inputField.schema(),
                                                pigFields[i]);
            }

            /* get field name of output */
            String outname = (isPartialSchema) ? pigFields[i].getName() : inputField.name();
            if (outname == null)
                outname = FIELD_NAME + "_" + i; // field name cannot be null

            /* get doc of output */
            String doc = (isPartialSchema) ? pigFields[i].getDescription() : inputField.doc();

            outFields.add(new Field(outname, fieldSchema, doc, null));
        }

        outSchema.setFields(outFields);
        return outSchema;

View Full Code Here

        return NONAME + "_" + index;
    }

    /** create  an avro field using the given schema */
    public static Field createUDField(int index, Schema s) {
        return new Field(getDummyFieldName(index), s, null, null);
    }
View Full Code Here

    assertEquals(Schema.Type.UNION, response.getType());
    assertEquals(Schema.Type.NULL, response.getTypes().get(0).getType());
    assertEquals(Schema.Type.STRING, response.getTypes().get(1).getType());
    // check request schema is union
    Schema request = message.getRequest();
    Field field = request.getField("s");
    assertNotNull("field 's' should not be null", field);
    Schema param = field.schema();
    assertEquals(Schema.Type.UNION, param.getType());
    assertEquals(Schema.Type.NULL, param.getTypes().get(0).getType());
    assertEquals(Schema.Type.STRING, param.getTypes().get(1).getType());
    // check union erasure
    assertEquals(String.class, ReflectData.get().getClass(response));
View Full Code Here

    List<Field> fields = new ArrayList<Field>();
    for (String columnName : columnNames) {
      String cleanedCol = ClassWriter.toIdentifier(columnName);
      int sqlType = columnTypes.get(cleanedCol);
      Schema avroSchema = toAvroSchema(sqlType, columnName);
      Field field = new Field(cleanedCol, avroSchema, null, null);
      field.addProp("columnName", columnName);
      field.addProp("sqlType", Integer.toString(sqlType));
      fields.add(field);
    }

    TableClassName tableClassName = new TableClassName(options);
    String shortClassName = tableClassName.getShortClassForTable(tableName);
View Full Code Here

    List<? extends StructField> allStructFieldRefs = soi.getAllStructFieldRefs();
    List<Object> structFieldsDataAsList = soi.getStructFieldsDataAsList(o);

    for(int i  = 0; i < size; i++) {
      Field field = schema.getFields().get(i);
      TypeInfo typeInfo = columnTypes.get(i);
      StructField structFieldRef = allStructFieldRefs.get(i);
      Object structFieldData = structFieldsDataAsList.get(i);
      ObjectInspector fieldOI = structFieldRef.getFieldObjectInspector();

      Object val = serialize(typeInfo, fieldOI, structFieldData, field.schema());
      record.put(field.name(), val);
    }

    if(!GenericData.get().validate(schema, record))
      throw new SerializeToAvroException(schema, record);
View Full Code Here

    List<Object> structFieldsDataAsList = ssoi.getStructFieldsDataAsList(o);
    GenericData.Record record = new GenericData.Record(schema);
    ArrayList<TypeInfo> allStructFieldTypeInfos = typeInfo.getAllStructFieldTypeInfos();

    for(int i  = 0; i < size; i++) {
      Field field = schema.getFields().get(i);
      TypeInfo colTypeInfo = allStructFieldTypeInfos.get(i);
      StructField structFieldRef = allStructFieldRefs.get(i);
      Object structFieldData = structFieldsDataAsList.get(i);
      ObjectInspector fieldOI = structFieldRef.getFieldObjectInspector();

      Object val = serialize(colTypeInfo, fieldOI, structFieldData, field.schema());
      record.put(field.name(), val);
    }
    return record;
  }
View Full Code Here

      List<Field> fields = new ArrayList<Field>();
      for (FieldDescriptor f : descriptor.getFields()) {
        Schema s = getSchema(f);
        if (f.isRepeated())
          s = Schema.createArray(s);
        fields.add(new Field(f.getName(), s, null, getDefault(f)));
      }
      result.setFields(fields);
      return result;

    } finally {
View Full Code Here

    List<Field> fields = new ArrayList<Field>();
    for (String columnName : columnNames) {
      String cleanedCol = ClassWriter.toJavaIdentifier(columnName);
      int sqlType = columnTypes.get(columnName);
      Schema avroSchema = toAvroSchema(sqlType, columnName);
      Field field = new Field(cleanedCol, avroSchema, null, null);
      field.addProp("columnName", columnName);
      field.addProp("sqlType", Integer.toString(sqlType));
      fields.add(field);
    }

    TableClassName tableClassName = new TableClassName(options);
    String shortClassName = tableClassName.getShortClassForTable(tableName);
View Full Code Here

TOP

Related Classes of org.apache.avro.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.