use of org.apache.asterix.om.base.AString in project asterixdb by apache.
the class NodeGroupTupleTranslator method getMetadataEntityFromTuple.
@Override
public NodeGroup getMetadataEntityFromTuple(ITupleReference frameTuple) throws HyracksDataException {
byte[] serRecord = frameTuple.getFieldData(NODEGROUP_PAYLOAD_TUPLE_FIELD_INDEX);
int recordStartOffset = frameTuple.getFieldStart(NODEGROUP_PAYLOAD_TUPLE_FIELD_INDEX);
int recordLength = frameTuple.getFieldLength(NODEGROUP_PAYLOAD_TUPLE_FIELD_INDEX);
ByteArrayInputStream stream = new ByteArrayInputStream(serRecord, recordStartOffset, recordLength);
DataInput in = new DataInputStream(stream);
ARecord nodeGroupRecord = recordSerDes.deserialize(in);
String gpName = ((AString) nodeGroupRecord.getValueByPos(MetadataRecordTypes.NODEGROUP_ARECORD_GROUPNAME_FIELD_INDEX)).getStringValue();
IACursor cursor = ((AUnorderedList) nodeGroupRecord.getValueByPos(MetadataRecordTypes.NODEGROUP_ARECORD_NODENAMES_FIELD_INDEX)).getCursor();
List<String> nodeNames = new ArrayList<>();
while (cursor.next()) {
nodeNames.add(((AString) cursor.get()).getStringValue());
}
return new NodeGroup(gpName, nodeNames);
}
use of org.apache.asterix.om.base.AString in project asterixdb by apache.
the class NodeGroupTupleTranslator method getTupleFromMetadataEntity.
@Override
public ITupleReference getTupleFromMetadataEntity(NodeGroup instance) throws HyracksDataException, MetadataException {
// write the key in the first field of the tuple
tupleBuilder.reset();
aString.setValue(instance.getNodeGroupName());
stringSerde.serialize(aString, tupleBuilder.getDataOutput());
tupleBuilder.addFieldEndOffset();
// write the payload in the second field of the tuple
recordBuilder.reset(MetadataRecordTypes.NODEGROUP_RECORDTYPE);
// write field 0
fieldValue.reset();
aString.setValue(instance.getNodeGroupName());
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.NODEGROUP_ARECORD_GROUPNAME_FIELD_INDEX, fieldValue);
// write field 1
listBuilder.reset((AUnorderedListType) MetadataRecordTypes.NODEGROUP_RECORDTYPE.getFieldTypes()[MetadataRecordTypes.NODEGROUP_ARECORD_NODENAMES_FIELD_INDEX]);
List<String> nodeNames = instance.getNodeNames();
for (String nodeName : nodeNames) {
itemValue.reset();
aString.setValue(nodeName);
stringSerde.serialize(aString, itemValue.getDataOutput());
listBuilder.addItem(itemValue);
}
fieldValue.reset();
listBuilder.write(fieldValue.getDataOutput(), true);
recordBuilder.addField(MetadataRecordTypes.NODEGROUP_ARECORD_NODENAMES_FIELD_INDEX, fieldValue);
// write field 2
fieldValue.reset();
aString.setValue(Calendar.getInstance().getTime().toString());
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(MetadataRecordTypes.NODEGROUP_ARECORD_TIMESTAMP_FIELD_INDEX, fieldValue);
recordBuilder.write(tupleBuilder.getDataOutput(), true);
tupleBuilder.addFieldEndOffset();
tuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray());
return tuple;
}
use of org.apache.asterix.om.base.AString in project asterixdb by apache.
the class FullTextContainsParameterCheckRule method setDefaultValueForThirdParameter.
/**
* Sets the default option value(s) when a user doesn't provide any option.
*/
void setDefaultValueForThirdParameter(List<Mutable<ILogicalExpression>> newArgs) throws AlgebricksException {
// Sets the search mode option: the default option is conjunctive search.
ILogicalExpression searchModeOptionExpr = new ConstantExpression(new AsterixConstantValue(new AString(FullTextContainsDescriptor.SEARCH_MODE_OPTION)));
ILogicalExpression searchModeValExpr = new ConstantExpression(new AsterixConstantValue(new AString(FullTextContainsDescriptor.CONJUNCTIVE_SEARCH_MODE_OPTION)));
// Add this option as arguments to the ftcontains().
newArgs.add(new MutableObject<ILogicalExpression>(searchModeOptionExpr));
newArgs.add(new MutableObject<ILogicalExpression>(searchModeValExpr));
}
use of org.apache.asterix.om.base.AString 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;
}
use of org.apache.asterix.om.base.AString in project asterixdb by apache.
the class DatasetTupleTranslator method getDatasetHints.
protected Map<String, String> getDatasetHints(ARecord datasetRecord) {
Map<String, String> hints = new HashMap<>();
String key;
String value;
AUnorderedList list = (AUnorderedList) datasetRecord.getValueByPos(MetadataRecordTypes.DATASET_ARECORD_HINTS_FIELD_INDEX);
IACursor cursor = list.getCursor();
while (cursor.next()) {
ARecord field = (ARecord) cursor.get();
key = ((AString) field.getValueByPos(MetadataRecordTypes.PROPERTIES_NAME_FIELD_INDEX)).getStringValue();
value = ((AString) field.getValueByPos(MetadataRecordTypes.PROPERTIES_VALUE_FIELD_INDEX)).getStringValue();
hints.put(key, value);
}
return hints;
}
Aggregations