Search in sources :

Example 46 with AString

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);
}
Also used : ArrayList(java.util.ArrayList) AUnorderedList(org.apache.asterix.om.base.AUnorderedList) AString(org.apache.asterix.om.base.AString) IACursor(org.apache.asterix.om.base.IACursor) DataInputStream(java.io.DataInputStream) DataInput(java.io.DataInput) ARecord(org.apache.asterix.om.base.ARecord) ByteArrayInputStream(java.io.ByteArrayInputStream) AString(org.apache.asterix.om.base.AString) NodeGroup(org.apache.asterix.metadata.entities.NodeGroup)

Example 47 with AString

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;
}
Also used : AString(org.apache.asterix.om.base.AString)

Example 48 with AString

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));
}
Also used : ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) AString(org.apache.asterix.om.base.AString)

Example 49 with AString

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;
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) OrderedListBuilder(org.apache.asterix.builders.OrderedListBuilder) AMutableString(org.apache.asterix.om.base.AMutableString) AString(org.apache.asterix.om.base.AString) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) UnorderedListBuilder(org.apache.asterix.builders.UnorderedListBuilder)

Example 50 with AString

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;
}
Also used : ARecord(org.apache.asterix.om.base.ARecord) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AUnorderedList(org.apache.asterix.om.base.AUnorderedList) AMutableString(org.apache.asterix.om.base.AMutableString) AString(org.apache.asterix.om.base.AString) IACursor(org.apache.asterix.om.base.IACursor)

Aggregations

AString (org.apache.asterix.om.base.AString)58 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)21 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)20 ArrayList (java.util.ArrayList)19 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)18 AMutableString (org.apache.asterix.om.base.AMutableString)16 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)16 AOrderedList (org.apache.asterix.om.base.AOrderedList)13 Mutable (org.apache.commons.lang3.mutable.Mutable)12 RecordBuilder (org.apache.asterix.builders.RecordBuilder)11 AInt32 (org.apache.asterix.om.base.AInt32)11 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)10 IARecordBuilder (org.apache.asterix.builders.IARecordBuilder)9 IACursor (org.apache.asterix.om.base.IACursor)9 IAObject (org.apache.asterix.om.base.IAObject)9 IAType (org.apache.asterix.om.types.IAType)9 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)9 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)9 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)9 ARecord (org.apache.asterix.om.base.ARecord)8