Search in sources :

Example 1 with UnorderedListBuilder

use of org.apache.asterix.builders.UnorderedListBuilder in project asterixdb by apache.

the class ClassAdParser method parseUnorderedList.

private void parseUnorderedList(AUnorderedListType uoltype, Value listVal, DataOutput out) throws IOException, AsterixException {
    ArrayBackedValueStorage itemBuffer = getTempBuffer();
    UnorderedListBuilder unorderedListBuilder = (UnorderedListBuilder) getUnorderedListBuilder();
    IAType itemType = null;
    if (uoltype != null) {
        itemType = uoltype.getItemType();
    }
    unorderedListBuilder.reset(uoltype);
    for (ExprTree tree : listVal.getListVal().getExprList()) {
        itemBuffer.reset();
        writeFieldValueToBuffer(itemType, itemBuffer.getDataOutput(), null, tree, null);
        unorderedListBuilder.addItem(itemBuffer);
    }
    unorderedListBuilder.write(out, true);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) ExprTree(org.apache.asterix.external.classad.ExprTree) UnorderedListBuilder(org.apache.asterix.builders.UnorderedListBuilder) IAType(org.apache.asterix.om.types.IAType)

Example 2 with UnorderedListBuilder

use of org.apache.asterix.builders.UnorderedListBuilder 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 3 with UnorderedListBuilder

use of org.apache.asterix.builders.UnorderedListBuilder in project asterixdb by apache.

the class FeedConnectionTupleTranslator method writeAppliedFunctionsField.

private void writeAppliedFunctionsField(IARecordBuilder rb, FeedConnection fc, ArrayBackedValueStorage buffer) throws HyracksDataException {
    UnorderedListBuilder listBuilder = new UnorderedListBuilder();
    ArrayBackedValueStorage listEleBuffer = new ArrayBackedValueStorage();
    listBuilder.reset((AUnorderedListType) MetadataRecordTypes.FEED_CONNECTION_RECORDTYPE.getFieldTypes()[MetadataRecordTypes.FEED_CONN_APPLIED_FUNCTIONS_FIELD_INDEX]);
    if (fc.getAppliedFunctions() != null) {
        List<FunctionSignature> appliedFunctions = fc.getAppliedFunctions();
        for (FunctionSignature af : appliedFunctions) {
            listEleBuffer.reset();
            aString.setValue(af.getName());
            stringSerde.serialize(aString, listEleBuffer.getDataOutput());
            listBuilder.addItem(listEleBuffer);
        }
    }
    listBuilder.write(buffer.getDataOutput(), true);
    rb.addField(MetadataRecordTypes.FEED_CONN_APPLIED_FUNCTIONS_FIELD_INDEX, buffer);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) UnorderedListBuilder(org.apache.asterix.builders.UnorderedListBuilder) FunctionSignature(org.apache.asterix.common.functions.FunctionSignature)

Example 4 with UnorderedListBuilder

use of org.apache.asterix.builders.UnorderedListBuilder in project asterixdb by apache.

the class FeedPolicyTupleTranslator method getTupleFromMetadataEntity.

@Override
public ITupleReference getTupleFromMetadataEntity(FeedPolicyEntity feedPolicy) throws HyracksDataException, MetadataException {
    // write the key in the first three fields of the tuple
    ArrayBackedValueStorage itemValue = new ArrayBackedValueStorage();
    tupleBuilder.reset();
    aString.setValue(feedPolicy.getDataverseName());
    stringSerde.serialize(aString, tupleBuilder.getDataOutput());
    tupleBuilder.addFieldEndOffset();
    aString.setValue(feedPolicy.getPolicyName());
    stringSerde.serialize(aString, tupleBuilder.getDataOutput());
    tupleBuilder.addFieldEndOffset();
    recordBuilder.reset(MetadataRecordTypes.FEED_POLICY_RECORDTYPE);
    // write field 0
    fieldValue.reset();
    aString.setValue(feedPolicy.getDataverseName());
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    recordBuilder.addField(MetadataRecordTypes.FEED_POLICY_ARECORD_DATAVERSE_NAME_FIELD_INDEX, fieldValue);
    // write field 1
    fieldValue.reset();
    aString.setValue(feedPolicy.getPolicyName());
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    recordBuilder.addField(MetadataRecordTypes.FEED_POLICY_ARECORD_POLICY_NAME_FIELD_INDEX, fieldValue);
    // write field 2
    fieldValue.reset();
    aString.setValue(feedPolicy.getDescription());
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    recordBuilder.addField(MetadataRecordTypes.FEED_POLICY_ARECORD_POLICY_NAME_FIELD_INDEX, fieldValue);
    // write field 3 (properties)
    Map<String, String> properties = feedPolicy.getProperties();
    UnorderedListBuilder listBuilder = new UnorderedListBuilder();
    listBuilder.reset((AUnorderedListType) MetadataRecordTypes.FEED_POLICY_RECORDTYPE.getFieldTypes()[MetadataRecordTypes.FEED_POLICY_ARECORD_PROPERTIES_FIELD_INDEX]);
    for (Map.Entry<String, String> property : properties.entrySet()) {
        String name = property.getKey();
        String value = property.getValue();
        itemValue.reset();
        writePropertyTypeRecord(name, value, itemValue.getDataOutput());
        listBuilder.addItem(itemValue);
    }
    fieldValue.reset();
    listBuilder.write(fieldValue.getDataOutput(), true);
    recordBuilder.addField(MetadataRecordTypes.FEED_POLICY_ARECORD_PROPERTIES_FIELD_INDEX, fieldValue);
    // 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) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) UnorderedListBuilder(org.apache.asterix.builders.UnorderedListBuilder) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with UnorderedListBuilder

use of org.apache.asterix.builders.UnorderedListBuilder in project asterixdb by apache.

the class FeedTupleTranslator method writeFeedAdaptorField.

private void writeFeedAdaptorField(IARecordBuilder recordBuilder, Feed feed, ArrayBackedValueStorage fieldValueBuffer) throws HyracksDataException {
    UnorderedListBuilder listBuilder = new UnorderedListBuilder();
    ArrayBackedValueStorage listEleBuffer = new ArrayBackedValueStorage();
    listBuilder.reset((AUnorderedListType) MetadataRecordTypes.FEED_RECORDTYPE.getFieldTypes()[MetadataRecordTypes.FEED_ARECORD_ADAPTOR_CONFIG_INDEX]);
    for (Map.Entry<String, String> property : feed.getAdapterConfiguration().entrySet()) {
        String name = property.getKey();
        String value = property.getValue();
        listEleBuffer.reset();
        writePropertyTypeRecord(name, value, listEleBuffer.getDataOutput());
        listBuilder.addItem(listEleBuffer);
    }
    listBuilder.write(fieldValueBuffer.getDataOutput(), true);
    recordBuilder.addField(MetadataRecordTypes.FEED_ARECORD_ADAPTOR_CONFIG_INDEX, fieldValueBuffer);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) UnorderedListBuilder(org.apache.asterix.builders.UnorderedListBuilder) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

UnorderedListBuilder (org.apache.asterix.builders.UnorderedListBuilder)8 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)7 HashMap (java.util.HashMap)3 Map (java.util.Map)3 AMutableString (org.apache.asterix.om.base.AMutableString)3 AString (org.apache.asterix.om.base.AString)3 IAType (org.apache.asterix.om.types.IAType)3 DataOutput (java.io.DataOutput)1 LinkedHashMap (java.util.LinkedHashMap)1 OrderedListBuilder (org.apache.asterix.builders.OrderedListBuilder)1 RuntimeDataException (org.apache.asterix.common.exceptions.RuntimeDataException)1 FunctionSignature (org.apache.asterix.common.functions.FunctionSignature)1 ExprTree (org.apache.asterix.external.classad.ExprTree)1 IACursor (org.apache.asterix.om.base.IACursor)1 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)1 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)1 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)1 BooleanObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector)1 ByteObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.ByteObjectInspector)1 DoubleObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector)1