本文整理匯總了Java中org.apache.avro.Schema.Type.equals方法的典型用法代碼示例。如果您正苦於以下問題:Java Type.equals方法的具體用法?Java Type.equals怎麽用?Java Type.equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.avro.Schema.Type
的用法示例。
在下文中一共展示了Type.equals方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getResolvedUnionIndex
import org.apache.avro.Schema.Type; //導入方法依賴的package包/類
private int getResolvedUnionIndex(Schema unionScema) {
if (unionScema.getTypes().size() == 2) {
// schema [type0, type1]
Type type0 = unionScema.getTypes().get(0).getType();
Type type1 = unionScema.getTypes().get(1).getType();
// Check if types are different and there's a "null", like ["null","type"]
// or ["type","null"]
if (!type0.equals(type1)
&& (type0.equals(Schema.Type.NULL) || type1.equals(Schema.Type.NULL))) {
if (type0.equals(Schema.Type.NULL))
return 1;
else
return 0;
}
}
return 2;
}
示例2: getFieldValue
import org.apache.avro.Schema.Type; //導入方法依賴的package包/類
private Object getFieldValue(Type type, Schema fieldSchema, ByteBuffer byteBuffer){
Object value = null;
if (type.equals(Type.ARRAY)) {
ListSerializer<?> serializer = ListSerializer.get(fieldSchema.getElementType());
List<?> genericArray = serializer.fromByteBuffer(byteBuffer);
value = genericArray;
} else if (type.equals(Type.MAP)) {
// MapSerializer<?> serializer = MapSerializer.get(fieldSchema.getValueType());
// Map<?, ?> map = serializer.fromByteBuffer(byteBuffer);
// value = map;
value = fromByteBuffer(fieldSchema, byteBuffer);
} else if (type.equals(Type.RECORD)){
value = fromByteBuffer(fieldSchema, byteBuffer);
} else if (type.equals(Type.UNION)){
// the selected union schema is obtained
Schema unionFieldSchema = getUnionSchema(super.getUnionType(), fieldSchema);
Type unionFieldType = unionFieldSchema.getType();
// we use the selected union schema to deserialize our actual value
//value = fromByteBuffer(unionFieldSchema, byteBuffer);
value = getFieldValue(unionFieldType, unionFieldSchema, byteBuffer);
} else {
value = fromByteBuffer(fieldSchema, byteBuffer);
}
return value;
}
示例3: fromMongoUnion
import org.apache.avro.Schema.Type; //導入方法依賴的package包/類
private Object fromMongoUnion(final Schema fieldSchema,
final DocumentFieldType storeType, final Field field, final String docf,
final BSONDecorator easybson) {
Object result;// schema [type0, type1]
Type type0 = fieldSchema.getTypes().get(0).getType();
Type type1 = fieldSchema.getTypes().get(1).getType();
// Check if types are different and there's a "null", like ["null","type"]
// or ["type","null"]
if (!type0.equals(type1)
&& (type0.equals(Type.NULL) || type1.equals(Type.NULL))) {
Schema innerSchema = fieldSchema.getTypes().get(1);
LOG.debug(
"Load from DBObject (UNION), schemaType:{}, docField:{}, storeType:{}",
new Object[] { innerSchema.getType(), docf, storeType });
// Deserialize as if schema was ["type"]
result = fromDBObject(innerSchema, storeType, field, docf, easybson);
} else {
throw new IllegalStateException(
"MongoStore doesn't support 3 types union field yet. Please update your mapping");
}
return result;
}
示例4: unionToMongo
import org.apache.avro.Schema.Type; //導入方法依賴的package包/類
private Object unionToMongo(final String docf, final Schema fieldSchema,
final DocumentFieldType storeType, final Object value) {
Object result;// schema [type0, type1]
Type type0 = fieldSchema.getTypes().get(0).getType();
Type type1 = fieldSchema.getTypes().get(1).getType();
// Check if types are different and there's a "null", like ["null","type"]
// or ["type","null"]
if (!type0.equals(type1)
&& (type0.equals(Type.NULL) || type1.equals(Type.NULL))) {
Schema innerSchema = fieldSchema.getTypes().get(1);
LOG.debug(
"Transform value to DBObject (UNION), schemaType:{}, type1:{}, storeType:{}",
new Object[] { innerSchema.getType(), type1, storeType });
// Deserialize as if schema was ["type"]
result = toDBObject(docf, innerSchema, type1, storeType, value);
} else {
throw new IllegalStateException(
"MongoStore doesn't support 3 types union field yet. Please update your mapping");
}
return result;
}
示例5: rowForRecord
import org.apache.avro.Schema.Type; //導入方法依賴的package包/類
private static Row rowForRecord(GenericRecord record) {
List<Object> values = Lists.newArrayList();
for (Field field : record.getSchema().getFields()) {
Object value = record.get(field.name());
Type fieldType = field.schema().getType();
if (fieldType.equals(Type.UNION)) {
fieldType = field.schema().getTypes().get(1).getType();
}
// Avro returns Utf8s for strings, which Spark SQL doesn't know how to use
if (fieldType.equals(Type.STRING) && value != null) {
value = value.toString();
}
values.add(value);
}
return RowFactory.create(values.toArray());
}
示例6: convertNullableField
import org.apache.avro.Schema.Type; //導入方法依賴的package包/類
@Nullable
private static Object convertNullableField(
Schema avroSchema, TableFieldSchema fieldSchema, Object v) {
// NULLABLE fields are represented as an Avro Union of the corresponding type and "null".
verify(
avroSchema.getType() == Type.UNION,
"Expected Avro schema type UNION, not %s, for BigQuery NULLABLE field %s",
avroSchema.getType(),
fieldSchema.getName());
List<Schema> unionTypes = avroSchema.getTypes();
verify(
unionTypes.size() == 2,
"BigQuery NULLABLE field %s should be an Avro UNION of NULL and another type, not %s",
fieldSchema.getName(),
unionTypes);
if (v == null) {
return null;
}
Type firstType = unionTypes.get(0).getType();
if (!firstType.equals(Type.NULL)) {
return convertRequiredField(firstType, fieldSchema, v);
}
return convertRequiredField(unionTypes.get(1).getType(), fieldSchema, v);
}
示例7: getUnionSchema
import org.apache.avro.Schema.Type; //導入方法依賴的package包/類
/**
* Given an object and the object schema this function obtains, from within
* the UNION schema, the position of the type used. If no data type can be
* inferred then we return a default value of position 0.
*
* @param pValue
* @param pUnionSchema
* @return the unionSchemaPosition.
*/
private int getUnionSchema(Object pValue, Schema pUnionSchema) {
int unionSchemaPos = 0;
for (Schema currentSchema : pUnionSchema.getTypes()) {
Type schemaType = currentSchema.getType();
if (pValue instanceof Utf8 && schemaType.equals(Type.STRING))
return unionSchemaPos;
else if (pValue instanceof ByteBuffer && schemaType.equals(Type.BYTES))
return unionSchemaPos;
else if (pValue instanceof Integer && schemaType.equals(Type.INT))
return unionSchemaPos;
else if (pValue instanceof Long && schemaType.equals(Type.LONG))
return unionSchemaPos;
else if (pValue instanceof Double && schemaType.equals(Type.DOUBLE))
return unionSchemaPos;
else if (pValue instanceof Float && schemaType.equals(Type.FLOAT))
return unionSchemaPos;
else if (pValue instanceof Boolean && schemaType.equals(Type.BOOLEAN))
return unionSchemaPos;
else if (pValue instanceof Map && schemaType.equals(Type.MAP))
return unionSchemaPos;
else if (pValue instanceof List && schemaType.equals(Type.ARRAY))
return unionSchemaPos;
else if (pValue instanceof Persistent && schemaType.equals(Type.RECORD))
return unionSchemaPos;
unionSchemaPos++;
}
// if we weren't able to determine which data type it is, then we return the
// default
return DEFAULT_UNION_SCHEMA;
}
示例8: getSerializer
import org.apache.avro.Schema.Type; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> Serializer<T> getSerializer(Schema schema) {
Serializer serializer = null;
Type type = schema.getType();
if (type.equals(Type.STRING)) {
serializer = CharSequenceSerializer.get();
} else if (type.equals(Type.BOOLEAN)) {
serializer = BooleanSerializer.get();
} else if (type.equals(Type.BYTES)) {
serializer = ByteBufferSerializer.get();
} else if (type.equals(Type.DOUBLE)) {
serializer = DoubleSerializer.get();
} else if (type.equals(Type.FLOAT)) {
serializer = FloatSerializer.get();
} else if (type.equals(Type.INT)) {
serializer = IntegerSerializer.get();
} else if (type.equals(Type.LONG)) {
serializer = LongSerializer.get();
} else if (type.equals(Type.FIXED)) {
Class clazz = TypeUtils.getClass(schema);
serializer = SpecificFixedSerializer.get(clazz);
// serializer = SpecificFixedSerializer.get(schema);
} else if (type.equals(Type.ARRAY)) {
serializer = ListSerializer.get(schema.getElementType());
} else if (type.equals(Type.MAP)) {
serializer = MapSerializer.get(schema.getValueType());
} else if (type.equals(Type.UNION)){
serializer = ByteBufferSerializer.get();
} else if (type.equals(Type.RECORD)){
serializer = BytesArraySerializer.get();
} else {
serializer = null;
}
return serializer;
}
示例9: getUnionSchema
import org.apache.avro.Schema.Type; //導入方法依賴的package包/類
/**
* Given an object and the object schema this function obtains,
* from within the UNION schema, the position of the type used.
* If no data type can be inferred then we return a default value
* of position 0.
* @param pValue
* @param pUnionSchema
* @return the unionSchemaPosition.
*/
private int getUnionSchema(Object pValue, Schema pUnionSchema){
int unionSchemaPos = 0;
// String valueType = pValue.getClass().getSimpleName();
for (Schema currentSchema : pUnionSchema.getTypes()) {
Type schemaType = currentSchema.getType();
if (pValue instanceof CharSequence && schemaType.equals(Type.STRING))
return unionSchemaPos;
else if (pValue instanceof ByteBuffer && schemaType.equals(Type.BYTES))
return unionSchemaPos;
else if (pValue instanceof Integer && schemaType.equals(Type.INT))
return unionSchemaPos;
else if (pValue instanceof Long && schemaType.equals(Type.LONG))
return unionSchemaPos;
else if (pValue instanceof Double && schemaType.equals(Type.DOUBLE))
return unionSchemaPos;
else if (pValue instanceof Float && schemaType.equals(Type.FLOAT))
return unionSchemaPos;
else if (pValue instanceof Boolean && schemaType.equals(Type.BOOLEAN))
return unionSchemaPos;
else if (pValue instanceof Map && schemaType.equals(Type.MAP))
return unionSchemaPos;
else if (pValue instanceof List && schemaType.equals(Type.ARRAY))
return unionSchemaPos;
else if (pValue instanceof Persistent && schemaType.equals(Type.RECORD))
return unionSchemaPos;
unionSchemaPos++;
}
// if we weren't able to determine which data type it is, then we return the default
return DEFAULT_UNION_SCHEMA;
}
示例10: createDiff
import org.apache.avro.Schema.Type; //導入方法依賴的package包/類
public static RecordDiff createDiff(GenericRecord avroObj1, GenericRecord avroObj2, Schema schema) throws IOException {
if (avroObj1 != null) {
Preconditions.checkArgument(avroObj1.getSchema().equals(avroObj2.getSchema()), "Schemas of Avro objects must match.");
}
Preconditions.checkArgument(schema.equals(avroObj2.getSchema()), "Scheme and Avro object's scheme must match.");
Map<String, Object> diffField = Maps.newHashMap();
List<Schema.Field> fields = schema.getFields();
for (Schema.Field field : fields) {
Type fieldTypeAvroObj1 = field.schema().getType();
Type fieldTypeAvroObj2 = field.schema().getType();
if (fieldTypeAvroObj2.equals(Type.UNION)) {
fieldTypeAvroObj2 = getUsedTypeFromUnion(avroObj2.get(field.pos()));
if (avroObj1 != null) {
fieldTypeAvroObj1 = getUsedTypeFromUnion(avroObj1.get(field.pos()));
} else {
fieldTypeAvroObj1 = null;
}
}
Object avroObj1Field = null;
if (avroObj1 != null) {
avroObj1Field = avroObj1.get(field.pos());
}
Object avroObj2Field = avroObj2.get(field.pos());
if (avroObj1Field == null || !avroObj1Field.equals(avroObj2Field)) {
if (fieldTypeAvroObj2.equals(Type.STRING) || fieldTypeAvroObj2.equals(Type.BOOLEAN) || fieldTypeAvroObj2.equals(Type.BYTES) ||
fieldTypeAvroObj2.equals(Type.DOUBLE) || fieldTypeAvroObj2.equals(Type.FLOAT) || fieldTypeAvroObj2.equals(Type.INT) ||
fieldTypeAvroObj2.equals(Type.LONG) || fieldTypeAvroObj2.equals(Type.ENUM)) {
PrimitiveDiff primitiveDiff = AvroDiffPrimitive.createPrimitiveDiff(avroObj1Field, avroObj2Field, fieldTypeAvroObj1, fieldTypeAvroObj2);
diffField.put(field.name(), primitiveDiff);
} else if (fieldTypeAvroObj2.equals(Type.MAP)) {
MapDiff mapDiff = AvroDiffMap.createMapDiff(avroObj1Field, avroObj2Field);
diffField.put(field.name(), mapDiff);
} else if (fieldTypeAvroObj2.equals(Type.ARRAY)) {
ArrayDiff arrayDiff = AvroDiffArray.createArrayDiff(avroObj1Field, avroObj2Field);
diffField.put(field.name(), arrayDiff);
} else if (fieldTypeAvroObj2.equals(Type.RECORD)) {
RecordDiff diff = createDiff((GenericRecord) avroObj1Field, (GenericRecord) avroObj2Field, ((GenericRecord) avroObj2Field).getSchema());
diffField.put(field.name(), diff);
} else {
LOGGER.error("Schema field has unknown type.");
}
}
}
return new RecordDiff(diffField);
}
示例11: updatePersistent
import org.apache.avro.Schema.Type; //導入方法依賴的package包/類
/**
* Load key/value pair from Cassandra row to Avro record.
* @throws IOException
*/
private void updatePersistent() throws IOException {
CassandraRow<K> cassandraRow = this.cassandraResultSet.get(this.rowNumber);
// load key
this.key = cassandraRow.getKey();
// load value
Schema schema = this.persistent.getSchema();
List<Field> fields = schema.getFields();
for (CassandraColumn cassandraColumn: cassandraRow) {
// get field name
String family = cassandraColumn.getFamily();
String fieldName = this.reverseMap.get(family + ":" + StringSerializer.get().fromByteBuffer(cassandraColumn.getName().duplicate()));
if (fieldName != null) {
// get field
if (!fieldName.contains(CassandraStore.UNION_COL_SUFIX)) {
int pos = this.persistent.getSchema().getField(fieldName).pos();
Field field = fields.get(pos);
Type fieldType = field.schema().getType();
if (fieldType.equals(Type.UNION)) {
//getting UNION stored type
CassandraColumn cc = getUnionTypeColumn(fieldName
+ CassandraStore.UNION_COL_SUFIX, cassandraRow.toArray());
//creating temporary UNION Field
Field unionField = new Field(fieldName
+ CassandraStore.UNION_COL_SUFIX, Schema.create(Type.INT),
null, null);
// get value of UNION stored type
cc.setField(unionField);
Object val = cc.getValue();
cassandraColumn.setUnionType(Integer.parseInt(val.toString()));
}
// get value
cassandraColumn.setField(field);
Object value = cassandraColumn.getValue();
this.persistent.put(pos, value);
// this field does not need to be written back to the store
this.persistent.clearDirty(pos);
}
} else
LOG.debug("FieldName was null while iterating CassandraRow and using Avro Union type");
}
}