use of org.apache.asterix.builders.OrderedListBuilder in project asterixdb by apache.
the class ExternalDatasetDetails method writeDatasetDetailsRecordType.
@SuppressWarnings("unchecked")
@Override
public void writeDatasetDetailsRecordType(DataOutput out) throws HyracksDataException {
IARecordBuilder externalRecordBuilder = new RecordBuilder();
OrderedListBuilder listBuilder = new OrderedListBuilder();
ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
ArrayBackedValueStorage itemValue = new ArrayBackedValueStorage();
externalRecordBuilder.reset(MetadataRecordTypes.EXTERNAL_DETAILS_RECORDTYPE);
AMutableString aString = new AMutableString("");
ISerializerDeserializer<AString> stringSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING);
ISerializerDeserializer<ADateTime> dateTimeSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATETIME);
ISerializerDeserializer<AInt32> intSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
// write field 0
fieldValue.reset();
aString.setValue(this.getAdapter());
stringSerde.serialize(aString, fieldValue.getDataOutput());
externalRecordBuilder.addField(MetadataRecordTypes.EXTERNAL_DETAILS_ARECORD_DATASOURCE_ADAPTER_FIELD_INDEX, fieldValue);
// write field 1
listBuilder.reset((AOrderedListType) MetadataRecordTypes.EXTERNAL_DETAILS_RECORDTYPE.getFieldTypes()[1]);
for (Map.Entry<String, String> property : this.properties.entrySet()) {
String name = property.getKey();
String value = property.getValue();
itemValue.reset();
DatasetUtil.writePropertyTypeRecord(name, value, itemValue.getDataOutput(), MetadataRecordTypes.DATASOURCE_ADAPTER_PROPERTIES_RECORDTYPE);
listBuilder.addItem(itemValue);
}
fieldValue.reset();
listBuilder.write(fieldValue.getDataOutput(), true);
externalRecordBuilder.addField(MetadataRecordTypes.EXTERNAL_DETAILS_ARECORD_PROPERTIES_FIELD_INDEX, fieldValue);
// write field 2
fieldValue.reset();
dateTimeSerde.serialize(new ADateTime(lastRefreshTime.getTime()), fieldValue.getDataOutput());
externalRecordBuilder.addField(MetadataRecordTypes.EXTERNAL_DETAILS_ARECORD_LAST_REFRESH_TIME_FIELD_INDEX, fieldValue);
// write field 3
fieldValue.reset();
intSerde.serialize(new AInt32(state.ordinal()), fieldValue.getDataOutput());
externalRecordBuilder.addField(MetadataRecordTypes.EXTERNAL_DETAILS_ARECORD_TRANSACTION_STATE_FIELD_INDEX, fieldValue);
externalRecordBuilder.write(out, true);
}
use of org.apache.asterix.builders.OrderedListBuilder in project asterixdb by apache.
the class FunctionTupleTranslator method getTupleFromMetadataEntity.
@Override
public ITupleReference getTupleFromMetadataEntity(Function function) throws HyracksDataException, MetadataException {
// write the key in the first 2 fields of the tuple
tupleBuilder.reset();
aString.setValue(function.getDataverseName());
stringSerde.serialize(aString, tupleBuilder.getDataOutput());
tupleBuilder.addFieldEndOffset();
aString.setValue(function.getName());
stringSerde.serialize(aString, tupleBuilder.getDataOutput());
tupleBuilder.addFieldEndOffset();
aString.setValue(function.getArity() + "");
stringSerde.serialize(aString, tupleBuilder.getDataOutput());
tupleBuilder.addFieldEndOffset();
// write the pay-load in the fourth field of the tuple
recordBuilder.reset(MetadataRecordTypes.FUNCTION_RECORDTYPE);
// write field 0
fieldValue.reset();
aString.setValue(function.getDataverseName());
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_DATAVERSENAME_FIELD_INDEX, fieldValue);
// write field 1
fieldValue.reset();
aString.setValue(function.getName());
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTIONNAME_FIELD_INDEX, fieldValue);
// write field 2
fieldValue.reset();
aString.setValue(function.getArity() + "");
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_ARITY_FIELD_INDEX, fieldValue);
// write field 3
OrderedListBuilder listBuilder = new OrderedListBuilder();
ArrayBackedValueStorage itemValue = new ArrayBackedValueStorage();
listBuilder.reset((AOrderedListType) MetadataRecordTypes.FUNCTION_RECORDTYPE.getFieldTypes()[MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_PARAM_LIST_FIELD_INDEX]);
for (String param : function.getParams()) {
itemValue.reset();
aString.setValue(param);
stringSerde.serialize(aString, itemValue.getDataOutput());
listBuilder.addItem(itemValue);
}
fieldValue.reset();
listBuilder.write(fieldValue.getDataOutput(), true);
recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_PARAM_LIST_FIELD_INDEX, fieldValue);
// write field 4
fieldValue.reset();
aString.setValue(function.getReturnType());
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_RETURN_TYPE_FIELD_INDEX, fieldValue);
// write field 5
fieldValue.reset();
aString.setValue(function.getFunctionBody());
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_DEFINITION_FIELD_INDEX, fieldValue);
// write field 6
fieldValue.reset();
aString.setValue(function.getLanguage());
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_LANGUAGE_FIELD_INDEX, fieldValue);
// write field 7
fieldValue.reset();
aString.setValue(function.getKind());
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_KIND_FIELD_INDEX, fieldValue);
// write field 8
fieldValue.reset();
aString.setValue(Integer.toString(function.getReferenceCount()));
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_REFERENCE_COUNT_INDEX, fieldValue);
// write record
recordBuilder.write(tupleBuilder.getDataOutput(), true);
tupleBuilder.addFieldEndOffset();
tuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray());
return tuple;
}
use of org.apache.asterix.builders.OrderedListBuilder in project asterixdb by apache.
the class ListifyAggregateFunctionEvalFactory method createAggregateEvaluator.
@Override
public IAggregateEvaluator createAggregateEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new IAggregateEvaluator() {
private IPointable inputVal = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private OrderedListBuilder builder = new OrderedListBuilder();
@Override
public void init() throws HyracksDataException {
builder.reset(orderedlistType);
}
@Override
public void step(IFrameTupleReference tuple) throws HyracksDataException {
try {
eval.evaluate(tuple, inputVal);
builder.addItem(inputVal);
} catch (IOException e) {
throw new HyracksDataException(e);
}
}
@Override
public void finish(IPointable result) throws HyracksDataException {
resultStorage.reset();
try {
builder.write(resultStorage.getDataOutput(), true);
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
@Override
public void finishPartial(IPointable result) throws HyracksDataException {
finish(result);
}
};
}
use of org.apache.asterix.builders.OrderedListBuilder in project asterixdb by apache.
the class LangRecordParseUtil method parseList.
private static void parseList(ListConstructor valueExpr, ArrayBackedValueStorage serialized) throws HyracksDataException {
if (valueExpr.getType() != ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR) {
throw new HyracksDataException(ErrorCode.ASTERIX, ErrorCode.PARSE_ERROR, "JSON List can't be of type %1$s", valueExpr.getType());
}
ArrayBackedValueStorage serializedValue = new ArrayBackedValueStorage();
OrderedListBuilder listBuilder = new OrderedListBuilder();
listBuilder.reset(null);
for (Expression expr : valueExpr.getExprList()) {
serializedValue.reset();
parseExpression(expr, serializedValue);
listBuilder.addItem(serializedValue);
}
listBuilder.write(serialized.getDataOutput(), true);
}
use of org.apache.asterix.builders.OrderedListBuilder in project asterixdb by apache.
the class AOrderedListSerializerDeserializer method serialize.
@SuppressWarnings("unchecked")
@Override
public void serialize(AOrderedList instance, DataOutput out) throws HyracksDataException {
// TODO: schemaless ordered list serializer
OrderedListBuilder listBuilder = new OrderedListBuilder();
listBuilder.reset(orderedlistType);
ArrayBackedValueStorage itemValue = new ArrayBackedValueStorage();
for (int i = 0; i < instance.size(); i++) {
itemValue.reset();
serializer.serialize(instance.getItem(i), itemValue.getDataOutput());
listBuilder.addItem(itemValue);
}
listBuilder.write(out, false);
}
Aggregations