当前位置: 首页>>代码示例>>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;未经允许,请勿转载。