use of org.apache.avro.util.Utf8 in project gora by apache.
the class MapFieldValueFilter method readFields.
@Override
public void readFields(DataInput in) throws IOException {
fieldName = Text.readString(in);
mapKey = new Utf8(Text.readString(in));
filterOp = WritableUtils.readEnum(in, FilterOp.class);
operands.clear();
int operandsSize = WritableUtils.readVInt(in);
for (int i = 0; i < operandsSize; i++) {
Object operand = ObjectWritable.readObject(in, conf);
if (operand instanceof String) {
operand = new Utf8((String) operand);
}
operands.add(operand);
}
filterIfMissing = in.readBoolean();
}
use of org.apache.avro.util.Utf8 in project gora by apache.
the class SingleFieldValueFilter method readFields.
@Override
public void readFields(DataInput in) throws IOException {
fieldName = Text.readString(in);
filterOp = WritableUtils.readEnum(in, FilterOp.class);
operands.clear();
int operandsSize = WritableUtils.readVInt(in);
for (int i = 0; i < operandsSize; i++) {
Object operand = ObjectWritable.readObject(in, conf);
if (operand instanceof String) {
operand = new Utf8((String) operand);
}
operands.add(operand);
}
filterIfMissing = in.readBoolean();
}
use of org.apache.avro.util.Utf8 in project gora by apache.
the class MongoStore method fromMongoString.
private Object fromMongoString(final DocumentFieldType storeType, final String docf, final BSONDecorator easybson) {
Object result;
if (storeType == DocumentFieldType.OBJECTID) {
// Try auto-conversion of BSON data to ObjectId
// It will work if data is stored as String or as ObjectId
Object bin = easybson.get(docf);
if (bin instanceof String) {
ObjectId id = new ObjectId((String) bin);
result = new Utf8(id.toString());
} else {
result = new Utf8(bin.toString());
}
} else if (storeType == DocumentFieldType.DATE) {
Object bin = easybson.get(docf);
if (bin instanceof Date) {
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.getDefault());
calendar.setTime((Date) bin);
result = new Utf8(DatatypeConverter.printDateTime(calendar));
} else {
result = new Utf8(bin.toString());
}
} else {
result = easybson.getUtf8String(docf);
}
return result;
}
use of org.apache.avro.util.Utf8 in project gora by apache.
the class MongoStore method fromMongoMap.
/* pp */
Object fromMongoMap(final String docf, final Schema fieldSchema, final BSONDecorator easybson, final Field f) {
BasicDBObject map = easybson.getDBObject(docf);
Map<Utf8, Object> rmap = new HashMap<>();
if (map == null) {
return new DirtyMapWrapper(rmap);
}
for (Entry<String, Object> e : map.entrySet()) {
String mapKey = e.getKey();
String decodedMapKey = decodeFieldKey(mapKey);
DocumentFieldType storeType = mapping.getDocumentFieldType(docf);
Object o = fromDBObject(fieldSchema.getValueType(), storeType, f, mapKey, new BSONDecorator(map));
rmap.put(new Utf8(decodedMapKey), o);
}
return new DirtyMapWrapper<>(rmap);
}
use of org.apache.avro.util.Utf8 in project gora by apache.
the class HBaseStore method setField.
private void setField(Result result, T persistent, HBaseColumn col, Field field, Schema fieldSchema) throws IOException {
switch(fieldSchema.getType()) {
case UNION:
int index = getResolvedUnionIndex(fieldSchema);
if (index > 1) {
//if more than 2 type in union, deserialize directly for now
byte[] val = result.getValue(col.getFamily(), col.getQualifier());
if (val == null) {
return;
}
setField(persistent, field, val);
} else {
Schema resolvedSchema = fieldSchema.getTypes().get(index);
setField(result, persistent, col, field, resolvedSchema);
}
break;
case MAP:
NavigableMap<byte[], byte[]> qualMap = result.getNoVersionMap().get(col.getFamily());
if (qualMap == null) {
return;
}
Schema valueSchema = fieldSchema.getValueType();
Map<Utf8, Object> map = new HashMap<>();
for (Entry<byte[], byte[]> e : qualMap.entrySet()) {
map.put(new Utf8(Bytes.toString(e.getKey())), fromBytes(valueSchema, e.getValue()));
}
setField(persistent, field, map);
break;
case ARRAY:
qualMap = result.getFamilyMap(col.getFamily());
if (qualMap == null) {
return;
}
valueSchema = fieldSchema.getElementType();
ArrayList<Object> arrayList = new ArrayList<>();
DirtyListWrapper<Object> dirtyListWrapper = new DirtyListWrapper<>(arrayList);
for (Entry<byte[], byte[]> e : qualMap.entrySet()) {
dirtyListWrapper.add(fromBytes(valueSchema, e.getValue()));
}
setField(persistent, field, arrayList);
break;
default:
byte[] val = result.getValue(col.getFamily(), col.getQualifier());
if (val == null) {
return;
}
setField(persistent, field, val);
break;
}
}
Aggregations