use of org.apache.asterix.builders.OrderedListBuilder in project asterixdb by apache.
the class ADMDataParser method parseOrderedList.
private void parseOrderedList(AOrderedListType oltype, DataOutput out) throws IOException {
ArrayBackedValueStorage itemBuffer = getTempBuffer();
OrderedListBuilder orderedListBuilder = (OrderedListBuilder) getOrderedListBuilder();
IAType itemType = null;
if (oltype != null) {
itemType = oltype.getItemType();
}
orderedListBuilder.reset(oltype);
int token;
boolean inList = true;
boolean expectingListItem = false;
boolean first = true;
do {
token = admLexer.next();
if (token == AdmLexer.TOKEN_END_ORDERED_LIST) {
if (expectingListItem) {
throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_LIST_FOUND_END_COLLECTION);
}
inList = false;
} else if (token == AdmLexer.TOKEN_COMMA) {
if (first) {
throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_LIST_FOUND_COMMA_BEFORE_LIST);
}
if (expectingListItem) {
throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_LIST_FOUND_COMMA_EXPECTING_ITEM);
}
expectingListItem = true;
} else {
expectingListItem = false;
itemBuffer.reset();
admFromLexerStream(token, itemType, itemBuffer.getDataOutput());
orderedListBuilder.addItem(itemBuffer);
}
first = false;
} while (inList);
orderedListBuilder.write(out, true);
}
use of org.apache.asterix.builders.OrderedListBuilder in project asterixdb by apache.
the class InternalDatasetDetails method writeDatasetDetailsRecordType.
@Override
public void writeDatasetDetailsRecordType(DataOutput out) throws HyracksDataException {
IARecordBuilder internalRecordBuilder = new RecordBuilder();
OrderedListBuilder listBuilder = new OrderedListBuilder();
ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
ArrayBackedValueStorage itemValue = new ArrayBackedValueStorage();
OrderedListBuilder primaryKeyListBuilder = new OrderedListBuilder();
AOrderedListType stringList = new AOrderedListType(BuiltinType.ASTRING, null);
AOrderedListType int8List = new AOrderedListType(BuiltinType.AINT8, null);
AOrderedListType heterogeneousList = new AOrderedListType(BuiltinType.ANY, null);
internalRecordBuilder.reset(MetadataRecordTypes.INTERNAL_DETAILS_RECORDTYPE);
AMutableString aString = new AMutableString("");
AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
@SuppressWarnings("unchecked") ISerializerDeserializer<ABoolean> booleanSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ABOOLEAN);
@SuppressWarnings("unchecked") ISerializerDeserializer<AString> stringSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING);
@SuppressWarnings("unchecked") ISerializerDeserializer<AInt8> int8Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT8);
// write field 0
fieldValue.reset();
aString.setValue(getFileStructure().toString());
stringSerde.serialize(aString, fieldValue.getDataOutput());
internalRecordBuilder.addField(MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_FILESTRUCTURE_FIELD_INDEX, fieldValue);
// write field 1
fieldValue.reset();
aString.setValue(getPartitioningStrategy().toString());
stringSerde.serialize(aString, fieldValue.getDataOutput());
internalRecordBuilder.addField(MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_PARTITIONSTRATEGY_FIELD_INDEX, fieldValue);
// write field 2
primaryKeyListBuilder.reset((AOrderedListType) MetadataRecordTypes.INTERNAL_DETAILS_RECORDTYPE.getFieldTypes()[MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_PARTITIONKEY_FIELD_INDEX]);
for (List<String> field : partitioningKeys) {
listBuilder.reset(stringList);
for (String subField : field) {
itemValue.reset();
aString.setValue(subField);
stringSerde.serialize(aString, itemValue.getDataOutput());
listBuilder.addItem(itemValue);
}
itemValue.reset();
listBuilder.write(itemValue.getDataOutput(), true);
primaryKeyListBuilder.addItem(itemValue);
}
fieldValue.reset();
primaryKeyListBuilder.write(fieldValue.getDataOutput(), true);
internalRecordBuilder.addField(MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_PARTITIONKEY_FIELD_INDEX, fieldValue);
// write field 3
primaryKeyListBuilder.reset((AOrderedListType) MetadataRecordTypes.INTERNAL_DETAILS_RECORDTYPE.getFieldTypes()[MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_PRIMARYKEY_FIELD_INDEX]);
for (List<String> field : primaryKeys) {
listBuilder.reset(stringList);
for (String subField : field) {
itemValue.reset();
aString.setValue(subField);
stringSerde.serialize(aString, itemValue.getDataOutput());
listBuilder.addItem(itemValue);
}
itemValue.reset();
listBuilder.write(itemValue.getDataOutput(), true);
primaryKeyListBuilder.addItem(itemValue);
}
fieldValue.reset();
primaryKeyListBuilder.write(fieldValue.getDataOutput(), true);
internalRecordBuilder.addField(MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_PRIMARYKEY_FIELD_INDEX, fieldValue);
// write field 4
fieldValue.reset();
ABoolean b = isAutogenerated() ? ABoolean.TRUE : ABoolean.FALSE;
booleanSerde.serialize(b, fieldValue.getDataOutput());
internalRecordBuilder.addField(MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_AUTOGENERATED_FIELD_INDEX, fieldValue);
// write filter fields if any
List<String> filterField = getFilterField();
if (filterField != null) {
listBuilder.reset(heterogeneousList);
ArrayBackedValueStorage nameValue = new ArrayBackedValueStorage();
nameValue.reset();
aString.setValue(FILTER_FIELD_NAME);
stringSerde.serialize(aString, nameValue.getDataOutput());
for (String field : filterField) {
itemValue.reset();
aString.setValue(field);
stringSerde.serialize(aString, itemValue.getDataOutput());
listBuilder.addItem(itemValue);
}
fieldValue.reset();
listBuilder.write(fieldValue.getDataOutput(), true);
internalRecordBuilder.addField(nameValue, fieldValue);
}
// write key source indicators if any
List<Integer> keySourceIndicator = getKeySourceIndicator();
boolean needSerialization = false;
if (keySourceIndicator != null) {
for (int source : keySourceIndicator) {
if (source != 0) {
needSerialization = true;
break;
}
}
}
if (needSerialization) {
listBuilder.reset(int8List);
ArrayBackedValueStorage nameValue = new ArrayBackedValueStorage();
nameValue.reset();
aString.setValue(KEY_FILD_SOURCE_INDICATOR_FIELD_NAME);
stringSerde.serialize(aString, nameValue.getDataOutput());
for (int source : keySourceIndicator) {
itemValue.reset();
aInt8.setValue((byte) source);
int8Serde.serialize(aInt8, itemValue.getDataOutput());
listBuilder.addItem(itemValue);
}
fieldValue.reset();
listBuilder.write(fieldValue.getDataOutput(), true);
internalRecordBuilder.addField(nameValue, fieldValue);
}
internalRecordBuilder.write(out, true);
}
use of org.apache.asterix.builders.OrderedListBuilder in project asterixdb by apache.
the class LineRectanglePolygonAccessor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
private final IPointable argPtr = new VoidPointable();
private final IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private final OrderedListBuilder listBuilder = new OrderedListBuilder();
private final ArrayBackedValueStorage inputVal = new ArrayBackedValueStorage();
private final AOrderedListType pointListType = new AOrderedListType(BuiltinType.APOINT, null);
private final AMutablePoint aPoint = new AMutablePoint(0, 0);
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<APoint> pointSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.APOINT);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
eval.evaluate(tuple, argPtr);
byte[] bytes = argPtr.getByteArray();
int startOffset = argPtr.getStartOffset();
resultStorage.reset();
try {
if (bytes[startOffset] == ATypeTag.SERIALIZED_LINE_TYPE_TAG) {
listBuilder.reset(pointListType);
inputVal.reset();
double startX = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.X));
double startY = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.Y));
aPoint.setValue(startX, startY);
pointSerde.serialize(aPoint, inputVal.getDataOutput());
listBuilder.addItem(inputVal);
inputVal.reset();
double endX = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.X));
double endY = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.Y));
aPoint.setValue(endX, endY);
pointSerde.serialize(aPoint, inputVal.getDataOutput());
listBuilder.addItem(inputVal);
listBuilder.write(out, true);
} else if (bytes[startOffset] == ATypeTag.SERIALIZED_RECTANGLE_TYPE_TAG) {
listBuilder.reset(pointListType);
inputVal.reset();
double x1 = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ARectangleSerializerDeserializer.getBottomLeftCoordinateOffset(Coordinate.X));
double y1 = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ARectangleSerializerDeserializer.getBottomLeftCoordinateOffset(Coordinate.Y));
aPoint.setValue(x1, y1);
pointSerde.serialize(aPoint, inputVal.getDataOutput());
listBuilder.addItem(inputVal);
inputVal.reset();
double x2 = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ARectangleSerializerDeserializer.getUpperRightCoordinateOffset(Coordinate.X));
double y2 = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ARectangleSerializerDeserializer.getUpperRightCoordinateOffset(Coordinate.Y));
aPoint.setValue(x2, y2);
pointSerde.serialize(aPoint, inputVal.getDataOutput());
listBuilder.addItem(inputVal);
listBuilder.write(out, true);
} else if (bytes[startOffset] == ATypeTag.SERIALIZED_POLYGON_TYPE_TAG) {
int numOfPoints = AInt16SerializerDeserializer.getShort(bytes, startOffset + APolygonSerializerDeserializer.getNumberOfPointsOffset());
if (numOfPoints < 3) {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
}
listBuilder.reset(pointListType);
for (int i = 0; i < numOfPoints; ++i) {
inputVal.reset();
double x = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.X));
double y = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.Y));
aPoint.setValue(x, y);
pointSerde.serialize(aPoint, inputVal.getDataOutput());
listBuilder.addItem(inputVal);
}
listBuilder.write(out, true);
} else {
throw new TypeMismatchException(getIdentifier(), 0, bytes[startOffset], ATypeTag.SERIALIZED_LINE_TYPE_TAG, ATypeTag.SERIALIZED_RECTANGLE_TYPE_TAG, ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
}
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.builders.OrderedListBuilder in project asterixdb by apache.
the class ClassAdParser method parseOrderedList.
private void parseOrderedList(AOrderedListType oltype, Value listVal, DataOutput out) throws IOException, AsterixException {
ArrayBackedValueStorage itemBuffer = getTempBuffer();
OrderedListBuilder orderedListBuilder = (OrderedListBuilder) getOrderedListBuilder();
IAType itemType = null;
if (oltype != null) {
itemType = oltype.getItemType();
}
orderedListBuilder.reset(oltype);
for (ExprTree tree : listVal.getListVal().getExprList()) {
itemBuffer.reset();
writeFieldValueToBuffer(itemType, itemBuffer.getDataOutput(), null, tree, null);
orderedListBuilder.addItem(itemBuffer);
}
orderedListBuilder.write(out, true);
}
use of org.apache.asterix.builders.OrderedListBuilder in project asterixdb by apache.
the class DatasetTupleTranslator method getTupleFromMetadataEntity.
@Override
public ITupleReference getTupleFromMetadataEntity(Dataset dataset) throws HyracksDataException, MetadataException {
OrderedListBuilder listBuilder = new OrderedListBuilder();
ArrayBackedValueStorage itemValue = new ArrayBackedValueStorage();
// write the key in the first 2 fields of the tuple
tupleBuilder.reset();
aString.setValue(dataset.getDataverseName());
stringSerde.serialize(aString, tupleBuilder.getDataOutput());
tupleBuilder.addFieldEndOffset();
aString.setValue(dataset.getDatasetName());
stringSerde.serialize(aString, tupleBuilder.getDataOutput());
tupleBuilder.addFieldEndOffset();
// write the pay-load in the third field of the tuple
recordBuilder.reset(MetadataRecordTypes.DATASET_RECORDTYPE);
// write field 0
fieldValue.reset();
aString.setValue(dataset.getDataverseName());
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_DATAVERSENAME_FIELD_INDEX, fieldValue);
// write field 1
fieldValue.reset();
aString.setValue(dataset.getDatasetName());
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_DATASETNAME_FIELD_INDEX, fieldValue);
// write field 2
fieldValue.reset();
aString.setValue(dataset.getItemTypeDataverseName());
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_DATATYPEDATAVERSENAME_FIELD_INDEX, fieldValue);
// write field 3
fieldValue.reset();
aString.setValue(dataset.getItemTypeName());
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_DATATYPENAME_FIELD_INDEX, fieldValue);
// write field 4
fieldValue.reset();
aString.setValue(dataset.getDatasetType().toString());
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_DATASETTYPE_FIELD_INDEX, fieldValue);
// write field 5
fieldValue.reset();
aString.setValue(dataset.getNodeGroupName());
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_GROUPNAME_FIELD_INDEX, fieldValue);
// write field 6
fieldValue.reset();
aString.setValue(dataset.getCompactionPolicy());
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_COMPACTION_POLICY_FIELD_INDEX, fieldValue);
// write field 7
listBuilder.reset((AOrderedListType) MetadataRecordTypes.DATASET_RECORDTYPE.getFieldTypes()[MetadataRecordTypes.DATASET_ARECORD_COMPACTION_POLICY_PROPERTIES_FIELD_INDEX]);
if (dataset.getCompactionPolicyProperties() != null) {
for (Map.Entry<String, String> property : dataset.getCompactionPolicyProperties().entrySet()) {
String name = property.getKey();
String value = property.getValue();
itemValue.reset();
DatasetUtil.writePropertyTypeRecord(name, value, itemValue.getDataOutput(), MetadataRecordTypes.COMPACTION_POLICY_PROPERTIES_RECORDTYPE);
listBuilder.addItem(itemValue);
}
}
fieldValue.reset();
listBuilder.write(fieldValue.getDataOutput(), true);
recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_COMPACTION_POLICY_PROPERTIES_FIELD_INDEX, fieldValue);
// write field 8/9
fieldValue.reset();
writeDatasetDetailsRecordType(recordBuilder, dataset, fieldValue.getDataOutput());
// write field 10
UnorderedListBuilder uListBuilder = new UnorderedListBuilder();
uListBuilder.reset((AUnorderedListType) MetadataRecordTypes.DATASET_RECORDTYPE.getFieldTypes()[MetadataRecordTypes.DATASET_ARECORD_HINTS_FIELD_INDEX]);
for (Map.Entry<String, String> property : dataset.getHints().entrySet()) {
String name = property.getKey();
String value = property.getValue();
itemValue.reset();
writeDatasetHintRecord(name, value, itemValue.getDataOutput());
uListBuilder.addItem(itemValue);
}
fieldValue.reset();
uListBuilder.write(fieldValue.getDataOutput(), true);
recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_HINTS_FIELD_INDEX, fieldValue);
// write field 11
fieldValue.reset();
aString.setValue(Calendar.getInstance().getTime().toString());
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_TIMESTAMP_FIELD_INDEX, fieldValue);
// write field 12
fieldValue.reset();
aInt32.setValue(dataset.getDatasetId());
aInt32Serde.serialize(aInt32, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_DATASETID_FIELD_INDEX, fieldValue);
// write field 13
fieldValue.reset();
aInt32.setValue(dataset.getPendingOp());
aInt32Serde.serialize(aInt32, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_PENDINGOP_FIELD_INDEX, fieldValue);
// write open fields
writeOpenFields(dataset);
// write record
recordBuilder.write(tupleBuilder.getDataOutput(), true);
tupleBuilder.addFieldEndOffset();
tuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray());
return tuple;
}
Aggregations