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


Java Schema.Type方法代碼示例

本文整理匯總了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();
  }
}
 
開發者ID:yahoojapan,項目名稱:dataplatform-schema-lib,代碼行數:21,代碼來源:AvroObjectToParser.java

示例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;
  }
}
 
開發者ID:yahoojapan,項目名稱:dataplatform-schema-lib,代碼行數:19,代碼來源:AvroObjectToParser.java

示例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;
}
 
開發者ID:atlascon,項目名稱:avro-diff,代碼行數:35,代碼來源:AvroDiffPrimitive.java

示例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;
}
 
開發者ID:HotelsDotCom,項目名稱:jasvorno,代碼行數:29,代碼來源:JasvornoConverter.java

示例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;
}
 
開發者ID:HotelsDotCom,項目名稱:jasvorno,代碼行數:31,代碼來源:JasvornoConverter.java

示例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;
}
 
開發者ID:HotelsDotCom,項目名稱:jasvorno,代碼行數:9,代碼來源:JasvornoConverter.java

示例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);
    }
  }
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:13,代碼來源:AvroRecordReader.java

示例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();
  }
}
 
開發者ID:yahoojapan,項目名稱:dataplatform-schema-lib,代碼行數:33,代碼來源:PrimitiveObjectToAvroObject.java

示例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() );
  }
}
 
開發者ID:yahoojapan,項目名稱:dataplatform-schema-lib,代碼行數:37,代碼來源:AvroObjectToPrimitiveObject.java

示例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);
    }
  }
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:13,代碼來源:AvroRecordReader.java

示例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();
  }
}
 
開發者ID:yahoojapan,項目名稱:dataplatform-schema-lib,代碼行數:44,代碼來源:AvroFormatterFactory.java

示例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 );
  }
}
 
開發者ID:yahoojapan,項目名稱:dataplatform-schema-lib,代碼行數:55,代碼來源:AvroSchemaFactory.java

示例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);
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:4,代碼來源:TestParquetExport.java

示例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);
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:4,代碼來源:TestAvroExport.java

示例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()));
    }
}
 
開發者ID:joker1007,項目名稱:embulk-formatter-avro,代碼行數:42,代碼來源:AvroValueConverterFactory.java


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