本文整理匯總了Java中org.apache.avro.Schema.Type方法的典型用法代碼示例。如果您正苦於以下問題:Java Schema.Type方法的具體用法?Java Schema.Type怎麽用?Java Schema.Type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.avro.Schema
的用法示例。
在下文中一共展示了Schema.Type方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: get
import org.apache.avro.Schema; //導入方法依賴的package包/類
public static IParser get( final Object obj ) throws IOException{
Schema.Type schemaType;
try{
schemaType = genericUtil.induce( obj ).getType();
}catch( AvroTypeException e ){
return new AvroNullParser();
}
switch( schemaType ){
case ARRAY:
return new AvroArrayParser( (GenericArray)obj );
case MAP:
return new AvroMapParser( (Map<Object,Object>)obj );
case RECORD:
return new AvroRecordParser( (GenericRecord)obj );
case UNION :
default:
return new AvroNullParser();
}
}
示例2: hasParser
import org.apache.avro.Schema; //導入方法依賴的package包/類
public static boolean hasParser( final Object obj ) throws IOException{
Schema.Type schemaType;
try{
schemaType = genericUtil.induce( obj ).getType();
}catch( AvroTypeException e ){
return false;
}
switch( schemaType ){
case ARRAY:
case MAP:
case RECORD:
return true;
case UNION :
default:
return false;
}
}
示例3: createPrimitiveDiff
import org.apache.avro.Schema; //導入方法依賴的package包/類
public static PrimitiveDiff createPrimitiveDiff(Object avroObj1Field, Object avroObj2Field, Schema.Type fieldTypeAvroObj1, Schema.Type fieldTypeAvroObj2) throws IOException {
PrimitiveDiff primitiveDiff = new PrimitiveDiff();
byte[] avroObj1FieldBytes = null, avroObj2FieldBytes;
if (fieldTypeAvroObj2.equals(fieldTypeAvroObj1) || fieldTypeAvroObj1 == null) {
if (fieldTypeAvroObj2.equals(Schema.Type.BYTES) || fieldTypeAvroObj2.equals(Schema.Type.STRING)) {
if (fieldTypeAvroObj2.equals(Schema.Type.BYTES)) {
if (avroObj1Field != null) {
avroObj1FieldBytes = ((ByteBuffer) avroObj1Field).array();
}
avroObj2FieldBytes = ((ByteBuffer) avroObj2Field).array();
} else {
if (avroObj1Field != null) {
avroObj1FieldBytes = ((String) avroObj1Field).getBytes(StandardCharsets.UTF_8);
}
avroObj2FieldBytes = ((String) avroObj2Field).getBytes(StandardCharsets.UTF_8);
}
byte[] diff = avroObj1FieldBytes == null ? avroObj2FieldBytes : new Delta().compute(avroObj1FieldBytes, avroObj2FieldBytes);
if (diff.length >= avroObj2FieldBytes.length) {
primitiveDiff.setNewValue(avroObj2Field);
} else {
primitiveDiff.setDiffValue(ByteBuffer.wrap(diff));
}
} else {
primitiveDiff.setNewValue(avroObj2Field);
}
} else {
primitiveDiff.setNewValue(avroObj2Field);
}
return primitiveDiff;
}
示例4: resolveUnion
import org.apache.avro.Schema; //導入方法依賴的package包/類
@VisibleForTesting
UnionResolution resolveUnion(JsonNode datum, Collection<Schema> unionSchemas) {
if (log.isDebugEnabled()) {
log.debug("Resolving union of types: {}",
unionSchemas.stream().map(Schema::getName).collect(Collectors.joining(",")));
}
Set<Schema.Type> primitives = Sets.newHashSet();
List<Schema> others = Lists.newArrayList();
for (Schema unionBranchSchema : unionSchemas) {
if (PRIMITIVES.containsKey(unionBranchSchema.getType())) {
primitives.add(unionBranchSchema.getType());
} else {
others.add(unionBranchSchema);
}
}
UnionResolution primitiveMatch = identifyPrimitiveMatch(datum, primitives);
if (primitiveMatch != null) {
return primitiveMatch;
}
UnionResolution otherMatch = identifyOtherMatch(datum, others);
if (otherMatch != null) {
return otherMatch;
}
return UnionResolution.NONE;
}
示例5: identifyPrimitiveMatch
import org.apache.avro.Schema; //導入方法依賴的package包/類
private static UnionResolution identifyPrimitiveMatch(JsonNode datum, Set<Schema.Type> primitives) {
// Try to identify specific primitive types
Schema primitiveSchema = null;
if (datum == null || datum.isNull()) {
primitiveSchema = closestPrimitive(primitives, Schema.Type.NULL);
} else if (datum.isShort() || datum.isInt()) {
primitiveSchema = closestPrimitive(primitives, Schema.Type.INT, Schema.Type.LONG, Schema.Type.FLOAT,
Schema.Type.DOUBLE);
} else if (datum.isLong()) {
primitiveSchema = closestPrimitive(primitives, Schema.Type.LONG, Schema.Type.DOUBLE);
} else if (datum.isFloat()) {
primitiveSchema = closestPrimitive(primitives, Schema.Type.FLOAT, Schema.Type.DOUBLE);
} else if (datum.isDouble()) {
primitiveSchema = closestPrimitive(primitives, Schema.Type.DOUBLE);
} else if (datum.isBoolean()) {
primitiveSchema = closestPrimitive(primitives, Schema.Type.BOOLEAN);
}
if (primitiveSchema == null
&& ((datum.isDouble() && datum.doubleValue() >= -Float.MAX_VALUE && datum.doubleValue() <= Float.MAX_VALUE)
|| (datum.isLong()
&& datum.longValue() >= (long) -Float.MAX_VALUE
&& datum.longValue() <= (long) Float.MAX_VALUE))) {
primitiveSchema = closestPrimitive(primitives, Schema.Type.FLOAT, Schema.Type.DOUBLE);
}
if (primitiveSchema != null) {
return new UnionResolution(primitiveSchema, MatchType.FULL);
}
return null;
}
示例6: closestPrimitive
import org.apache.avro.Schema; //導入方法依賴的package包/類
private static Schema closestPrimitive(Set<Schema.Type> possible, Schema.Type... types) {
for (Schema.Type type : types) {
if (possible.contains(type) && PRIMITIVES.containsKey(type)) {
return PRIMITIVES.get(type);
}
}
return null;
}
示例7: processRecord
import org.apache.avro.Schema; //導入方法依賴的package包/類
private void processRecord(final GenericContainer container, final Schema schema) {
final Schema.Type type = schema.getType();
switch (type) {
case RECORD:
process(container, schema, null, new MapOrListWriter(writer.rootAsMap()));
break;
default:
throw new DrillRuntimeException("Root object must be record type. Found: " + type);
}
}
示例8: get
import org.apache.avro.Schema; //導入方法依賴的package包/類
public static Object get( final Schema.Type schemaType , final PrimitiveObject obj ) throws IOException{
if( schemaType == Schema.Type.BOOLEAN ){
return obj.getBoolean();
}
else if( schemaType == Schema.Type.BYTES ){
byte[] bytes = obj.getBytes();
ByteBuffer byteBuffer = ByteBuffer.allocate(bytes.length);
byteBuffer.put(bytes, 0, bytes.length);
return byteBuffer;
}
else if( schemaType == Schema.Type.DOUBLE ){
return obj.getDouble();
}
else if( schemaType == Schema.Type.FLOAT ){
return obj.getFloat();
}
else if( schemaType == Schema.Type.INT ){
return obj.getInt();
}
else if( schemaType == Schema.Type.LONG ){
return obj.getLong();
}
else if( schemaType == Schema.Type.STRING ){
return obj.getString();
}
else if( schemaType == Schema.Type.NULL ){
return null;
}
else{
return obj.getString();
}
}
示例9: get
import org.apache.avro.Schema; //導入方法依賴的package包/類
public static PrimitiveObject get( final Object obj ) throws IOException{
Schema.Type schemaType = null;
try{
schemaType = genericUtil.induce( obj ).getType();
}catch( AvroTypeException e ){
return new StringObj( obj.toString() );
}
if( schemaType == Schema.Type.BOOLEAN ){
return new BooleanObj( (Boolean)obj );
}
else if( schemaType == Schema.Type.BYTES ){
return new BytesObj( ((ByteBuffer)obj).array() );
}
else if( schemaType == Schema.Type.DOUBLE ){
return new DoubleObj( (Double)obj );
}
else if( schemaType == Schema.Type.FLOAT ){
return new FloatObj( (Float)obj );
}
else if( schemaType == Schema.Type.INT ){
return new IntegerObj( (Integer)obj );
}
else if( schemaType == Schema.Type.LONG ){
return new LongObj( (Long)obj );
}
else if( schemaType == Schema.Type.STRING ){
return new StringObj( obj.toString() );
}
else if( schemaType == Schema.Type.NULL ){
return NullObj.getInstance();
}
else{
return new StringObj( obj.toString() );
}
}
示例10: processRecord
import org.apache.avro.Schema; //導入方法依賴的package包/類
private void processRecord(final GenericContainer container, final Schema schema) {
final Schema.Type type = schema.getType();
switch (type) {
case RECORD:
process(container, schema, null, new MapOrListWriterImpl(writer.rootAsMap()), fieldSelection);
break;
default:
throw new RuntimeException("Root object must be record type. Found: " + type);
}
}
示例11: get
import org.apache.avro.Schema; //導入方法依賴的package包/類
public static IAvroFormatter get( final Schema avroSchema ){
Schema.Type schemaType = avroSchema.getType();
if( schemaType == Schema.Type.ARRAY ){
return new AvroArrayFormatter( avroSchema );
}
else if( schemaType == Schema.Type.MAP ){
return new AvroMapFormatter( avroSchema );
}
else if( schemaType == Schema.Type.RECORD ){
return new AvroRecordFormatter( avroSchema );
}
else if( schemaType == Schema.Type.UNION ){
return new AvroUnionFormatter( avroSchema );
}
else if( schemaType == Schema.Type.BOOLEAN ){
return new AvroBooleanFormatter();
}
else if( schemaType == Schema.Type.BYTES ){
return new AvroBytesFormatter();
}
else if( schemaType == Schema.Type.DOUBLE ){
return new AvroDoubleFormatter();
}
else if( schemaType == Schema.Type.FLOAT ){
return new AvroFloatFormatter();
}
else if( schemaType == Schema.Type.INT ){
return new AvroIntegerFormatter();
}
else if( schemaType == Schema.Type.LONG ){
return new AvroLongFormatter();
}
else if( schemaType == Schema.Type.STRING ){
return new AvroStringFormatter();
}
else if( schemaType == Schema.Type.NULL ){
return new AvroNullFormatter();
}
else{
return new AvroNullFormatter();
}
}
示例12: 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 );
}
}
示例13: buildField
import org.apache.avro.Schema; //導入方法依賴的package包/類
private Field buildField(String name, Schema.Type type) {
return new Field(name, Schema.create(type), null, null);
}
示例14: buildAvroField
import org.apache.avro.Schema; //導入方法依賴的package包/類
private Field buildAvroField(String name, Schema.Type type) {
return new Field(name, Schema.create(type), null, null);
}
示例15: 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()));
}
}