當前位置: 首頁>>代碼示例>>Java>>正文


Java Schema.getTypes方法代碼示例

本文整理匯總了Java中org.apache.avro.Schema.getTypes方法的典型用法代碼示例。如果您正苦於以下問題:Java Schema.getTypes方法的具體用法?Java Schema.getTypes怎麽用?Java Schema.getTypes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.avro.Schema的用法示例。


在下文中一共展示了Schema.getTypes方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getSinglePrimitiveTypeOfUnion

import org.apache.avro.Schema; //導入方法依賴的package包/類
public static PrimitiveType getSinglePrimitiveTypeOfUnion(Schema fieldSchema) {
	PrimitiveType primitiveType = null;
	List<Schema> unionTypes = fieldSchema.getTypes();
	for (Schema unionType : unionTypes) {
		if (unionType.getType() != Type.NULL) {
			if (PrimitiveType.isPrimitive(unionType)) {
				if (primitiveType == null) {
					primitiveType = PrimitiveType.getPrimitiveType(unionType);
				} else {
					primitiveType = null;
					break;
				}
			} 
		}
	}
	return primitiveType;
}
 
開發者ID:Talend,項目名稱:avro-schema-editor,代碼行數:18,代碼來源:SchemaUtil.java

示例2: nullOk

import org.apache.avro.Schema; //導入方法依賴的package包/類
/**
 * Returns whether null is allowed by the schema.
 * <p>
 * </p>
 * Copied from {@code org.kitesdk.data.spi.SchemaUtil.nullOk(Schema)}.
 *
 * @param schema a Schema
 * @return true if schema allows the value to be null
 */
private static boolean nullOk(Schema schema) {
  if (Schema.Type.NULL == schema.getType()) {
    return true;
  } else if (Schema.Type.UNION == schema.getType()) {
    for (Schema possible : schema.getTypes()) {
      if (nullOk(possible)) {
        return true;
      }
    }
  }
  return false;
}
 
開發者ID:HotelsDotCom,項目名稱:jasvorno,代碼行數:22,代碼來源:JasvornoConverter.java

示例3: internalValidate

import org.apache.avro.Schema; //導入方法依賴的package包/類
private void internalValidate(Schema schema) throws SchemaValidationException {
  if (schema.getType() == RECORD) {
    String name = schema.getFullName();
    if (recordTypeNames.contains(name)) {
      return;
    }
    recordTypeNames.add(name);
    for (Field field : schema.getFields()) {
      internalValidate(field.schema());
    }
  } else if (schema.getType() == MAP) {
    internalValidate(schema.getValueType());
  } else if (schema.getType() == ARRAY) {
    internalValidate(schema.getElementType());
  } else if (schema.getType() == UNION) {
    boolean containsBytes = false;
    boolean containsString = false;
    for (Schema unionSchema : schema.getTypes()) {
      if (unionSchema.getType() == Schema.Type.BYTES) {
        containsBytes = true;
      } else if (unionSchema.getType() == Schema.Type.STRING) {
        containsString = true;
      }
      if (containsBytes && containsString) {
        String message = "Schema contains a variant of union[bytes, string]: " + unionSchema.toString();
        throw new SchemaValidationException(message);
      }
      if (COMPOSITE_TYPES.contains(unionSchema)) {
        internalValidate(unionSchema);
      }
    }
  }
}
 
開發者ID:HotelsDotCom,項目名稱:jasvorno,代碼行數:34,代碼來源:SchemaValidator.java

示例4: AvroUnionFormatter

import org.apache.avro.Schema; //導入方法依賴的package包/類
public AvroUnionFormatter( final Schema avroSchema ){

    childContainer = new ArrayList<IAvroFormatter>();
    List<Schema> childSchemas = avroSchema.getTypes();
    for( Schema child : childSchemas ){
      childContainer.add( AvroFormatterFactory.get( child ) );
    }
  }
 
開發者ID:yahoojapan,項目名稱:dataplatform-schema-lib,代碼行數:9,代碼來源:AvroUnionFormatter.java

示例5: AvroUnionSchema

import org.apache.avro.Schema; //導入方法依賴的package包/類
public AvroUnionSchema( final Schema avroSchema ) throws IOException{
  this.avroSchema = avroSchema;
  schema = new UnionField( avroSchema.getName() );

  for( Schema childSchema : avroSchema.getTypes() ){
    IField childField = AvroSchemaFactory.getGeneralSchema( avroSchema.getName() , childSchema );
    schema.set( childField );
  }
}
 
開發者ID:yahoojapan,項目名稱:dataplatform-schema-lib,代碼行數:10,代碼來源:AvroUnionSchema.java

示例6: unionHasTypedChild

import org.apache.avro.Schema; //導入方法依賴的package包/類
public static boolean unionHasTypedChild(Schema unionSchema, Type type) {
	List<Schema> unionTypes = unionSchema.getTypes();
	for (Schema unionType : unionTypes) {
		if (unionType.getType() == type) {
			return true;
		}
	}
	return false;
}
 
開發者ID:Talend,項目名稱:avro-schema-editor,代碼行數:10,代碼來源:SchemaUtil.java

示例7: isMultiChoiceUnion

import org.apache.avro.Schema; //導入方法依賴的package包/類
public static boolean isMultiChoiceUnion(Schema unionSchema) {
	List<Schema> unionTypes = unionSchema.getTypes();
	int nbrOfNoNullChild = 0;
	for (Schema unionType : unionTypes) {
		if (unionType.getType() != Type.NULL) {
			nbrOfNoNullChild++;
		}
	}
	return nbrOfNoNullChild > 1;
}
 
開發者ID:Talend,項目名稱:avro-schema-editor,代碼行數:11,代碼來源:SchemaUtil.java

示例8: parseUnionSchema

import org.apache.avro.Schema; //導入方法依賴的package包/類
protected UnionNode parseUnionSchema(Schema schema, AvroNode parentNode) {
	UnionNode unionNode = new UnionNode(context);
	// init
	schemaAttributeInitializer.setSchema(schema);
	unionNode.init(schemaAttributeInitializer);
	linkNodes(parentNode, unionNode);
	// register
	registerNode(unionNode);
	// create children
	List<Schema> types = schema.getTypes();
	for (Schema type : types) {
		parseSchema(type, unionNode);			
	}
	return unionNode;
}
 
開發者ID:Talend,項目名稱:avro-schema-editor,代碼行數:16,代碼來源:AvroSchemaParserImpl.java

示例9: getGeneralSchema

import org.apache.avro.Schema; //導入方法依賴的package包/類
public static IField getGeneralSchema( final String fieldName , final Schema avroSchema ) throws IOException{
  Schema.Type schemaType = avroSchema.getType();

  if( schemaType == Schema.Type.ARRAY ){
    return new AvroArraySchema( fieldName, avroSchema ).getGeneralSchema();
  }
  else if( schemaType == Schema.Type.MAP ){
    return new AvroMapSchema( fieldName, avroSchema ).getGeneralSchema();
  }
  else if( schemaType == Schema.Type.RECORD ){
    return new AvroRecordSchema( avroSchema ).getGeneralSchema();
  }
  else if( schemaType == Schema.Type.UNION ){
    List<Schema> childSchemas = avroSchema.getTypes();
    if( childSchemas.size() == 2 ){
      Schema childSchema0 = childSchemas.get(0);
      Schema childSchema1 = childSchemas.get(1);
      if( childSchema0.getType() == Schema.Type.NULL && childSchema1.getType() != Schema.Type.NULL ){
        return getGeneralSchema( fieldName , childSchema1 );
      }
      else if( childSchema0.getType() != Schema.Type.NULL && childSchema1.getType() == Schema.Type.NULL ){
        return getGeneralSchema( fieldName , childSchema0 );
      }
    }
    return new AvroUnionSchema( avroSchema ).getGeneralSchema();
  }
  else if( schemaType == Schema.Type.BOOLEAN ){
    return new BooleanField( fieldName );
  }
  else if( schemaType == Schema.Type.BYTES ){
    return new BytesField( fieldName );
  }
  else if( schemaType == Schema.Type.DOUBLE ){
    return new DoubleField( fieldName );
  }
  else if( schemaType == Schema.Type.FLOAT ){
    return new FloatField( fieldName );
  }
  else if( schemaType == Schema.Type.INT ){
    return new IntegerField( fieldName );
  }
  else if( schemaType == Schema.Type.LONG ){
    return new LongField( fieldName );
  }
  else if( schemaType == Schema.Type.STRING ){
    return new StringField( fieldName );
  }
  else if( schemaType == Schema.Type.NULL ){
    return new NullField( fieldName );
  }
  else{
    return new NullField( fieldName );
  }
}
 
開發者ID:yahoojapan,項目名稱:dataplatform-schema-lib,代碼行數:55,代碼來源:AvroSchemaFactory.java

示例10: fromAvro

import org.apache.avro.Schema; //導入方法依賴的package包/類
/**
 * Convert from Avro type to Sqoop's java representation of the SQL type
 * see SqlManager#toJavaType
 */
public static Object fromAvro(Object avroObject, Schema schema, String type) {
  if (avroObject == null) {
    return null;
  }

  switch (schema.getType()) {
    case NULL:
      return null;
    case BOOLEAN:
    case INT:
    case FLOAT:
    case DOUBLE:
      return avroObject;
    case LONG:
      if (type.equals(DATE_TYPE)) {
        return new Date((Long) avroObject);
      } else if (type.equals(TIME_TYPE)) {
        return new Time((Long) avroObject);
      } else if (type.equals(TIMESTAMP_TYPE)) {
        return new Timestamp((Long) avroObject);
      }
      return avroObject;
    case BYTES:
      ByteBuffer bb = (ByteBuffer) avroObject;
      BytesWritable bw = new BytesWritable();
      bw.set(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining());
      if (type.equals(BLOB_REF_TYPE)) {
        // TODO: Should convert BytesWritable to BlobRef properly. (SQOOP-991)
        throw new UnsupportedOperationException("BlobRef not supported");
      }
      return bw;
    case STRING:
      if (type.equals(BIG_DECIMAL_TYPE)) {
        return new BigDecimal(avroObject.toString());
      } else if (type.equals(DATE_TYPE)) {
        return Date.valueOf(avroObject.toString());
      } else if (type.equals(TIME_TYPE)) {
        return Time.valueOf(avroObject.toString());
      } else if (type.equals(TIMESTAMP_TYPE)) {
        return Timestamp.valueOf(avroObject.toString());
      }
      return avroObject.toString();
    case ENUM:
      return avroObject.toString();
    case UNION:
      List<Schema> types = schema.getTypes();
      if (types.size() != 2) {
        throw new IllegalArgumentException("Only support union with null");
      }
      Schema s1 = types.get(0);
      Schema s2 = types.get(1);
      if (s1.getType() == Schema.Type.NULL) {
        return fromAvro(avroObject, s2, type);
      } else if (s2.getType() == Schema.Type.NULL) {
        return fromAvro(avroObject, s1, type);
      } else {
        throw new IllegalArgumentException("Only support union with null");
      }
    case FIXED:
      return new BytesWritable(((GenericFixed) avroObject).bytes());
    case RECORD:
    case ARRAY:
    case MAP:
    default:
      throw new IllegalArgumentException("Cannot convert Avro type "
          + schema.getType());
  }
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:73,代碼來源:AvroUtil.java

示例11: detectConverter

import org.apache.avro.Schema; //導入方法依賴的package包/類
static private AbstractAvroValueConverter detectConverter(Schema schema) {
    Schema.Type avroType = schema.getType();
    switch (avroType) {
        case NULL:
            return new AvroNullConverter(schema);
        case BOOLEAN:
            return new AvroBooleanConverter(schema);
        case STRING:
            return new AvroStringConverter(schema);
        case INT:
            return new AvroIntConverter(schema);
        case LONG:
            return new AvroLongConverter(schema);
        case FLOAT:
            return new AvroFloatConverter(schema);
        case DOUBLE:
            return new AvroDoubleConverter(schema);
        case ENUM:
            return new AvroEnumConverter(schema, schema.getEnumSymbols());
        case FIXED:
            return new AvroFixedConverter(schema);
        case UNION:
            for (Schema s : schema.getTypes()) {
                if (s.getType() != Schema.Type.NULL)
                    return detectConverter(s);
            }
            return new AvroNullConverter(schema);
        case ARRAY:
            return new AvroArrayConverter(schema, detectConverter(schema.getElementType()));
        case MAP:
            return new AvroMapConverter(schema, detectConverter(schema.getValueType()));
        case RECORD:
            ImmutableMap.Builder<String, AbstractAvroValueConverter> builder = ImmutableMap.builder();
            for (Schema.Field f : schema.getFields()) {
                builder.put(f.name(), detectConverter(f.schema()));
            }
            return new AvroRecordConverter(schema, builder.build());
        default:
            throw new RuntimeException(String.format("%s of %s is unsupported avro type", schema.getType(), schema.getName()));
    }
}
 
開發者ID:joker1007,項目名稱:embulk-formatter-avro,代碼行數:42,代碼來源:AvroValueConverterFactory.java


注:本文中的org.apache.avro.Schema.getTypes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。