Search in sources :

Example 16 with AMutableString

use of org.apache.asterix.om.base.AMutableString in project asterixdb by apache.

the class FunctionalTester method read_line_stdin.

/*********************************************************************
     * Function: read_line_stdin
     * Purpose:
     *
     * @throws IOException
     *********************************************************************/
public static boolean read_line_stdin(AMutableString line, State state, Parameters parameters) throws IOException {
    System.out.print("> ");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String line_segment = br.readLine();
    if (line_segment.length() == 0 || line_segment.equalsIgnoreCase("q")) {
        line.setValue("");
        return false;
    }
    if (line_is_comment(line_segment)) {
        // ignore comments, should we read another line?
        line.setValue("");
        return true;
    } else {
        line.setValue(line.getStringValue() + line_segment);
        state.lineNumber++;
        return true;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) AMutableString(org.apache.asterix.om.base.AMutableString) AMutableCharArrayString(org.apache.asterix.external.classad.AMutableCharArrayString)

Example 17 with AMutableString

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

Example 18 with AMutableString

use of org.apache.asterix.om.base.AMutableString in project asterixdb by apache.

the class FeedPolicyTupleTranslator method writePropertyTypeRecord.

public void writePropertyTypeRecord(String name, String value, DataOutput out) throws HyracksDataException {
    IARecordBuilder propertyRecordBuilder = new RecordBuilder();
    ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
    propertyRecordBuilder.reset(MetadataRecordTypes.POLICY_PARAMS_RECORDTYPE);
    AMutableString aString = new AMutableString("");
    ISerializerDeserializer<AString> stringSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING);
    // write field 0
    fieldValue.reset();
    aString.setValue(name);
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    propertyRecordBuilder.addField(0, fieldValue);
    // write field 1
    fieldValue.reset();
    aString.setValue(value);
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    propertyRecordBuilder.addField(1, fieldValue);
    propertyRecordBuilder.write(out, true);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) RecordBuilder(org.apache.asterix.builders.RecordBuilder) AMutableString(org.apache.asterix.om.base.AMutableString) AString(org.apache.asterix.om.base.AString)

Example 19 with AMutableString

use of org.apache.asterix.om.base.AMutableString in project asterixdb by apache.

the class FeedTupleTranslator method writePropertyTypeRecord.

@SuppressWarnings("unchecked")
public void writePropertyTypeRecord(String name, String value, DataOutput out) throws HyracksDataException {
    IARecordBuilder propertyRecordBuilder = new RecordBuilder();
    ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
    propertyRecordBuilder.reset(MetadataRecordTypes.DATASOURCE_ADAPTER_PROPERTIES_RECORDTYPE);
    AMutableString aString = new AMutableString("");
    ISerializerDeserializer<AString> stringSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING);
    // write field 0
    fieldValue.reset();
    aString.setValue(name);
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    propertyRecordBuilder.addField(0, fieldValue);
    // write field 1
    fieldValue.reset();
    aString.setValue(value);
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    propertyRecordBuilder.addField(1, fieldValue);
    propertyRecordBuilder.write(out, true);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) RecordBuilder(org.apache.asterix.builders.RecordBuilder) AMutableString(org.apache.asterix.om.base.AMutableString) AString(org.apache.asterix.om.base.AString)

Example 20 with AMutableString

use of org.apache.asterix.om.base.AMutableString in project asterixdb by apache.

the class LangRecordParseUtil method parseRecord.

public static void parseRecord(RecordConstructor recordValue, ArrayBackedValueStorage serialized, boolean tagged, List<Pair<String, String>> defaults) throws HyracksDataException {
    AMutableString fieldNameString = new AMutableString(null);
    ArrayBackedValueStorage fieldName = new ArrayBackedValueStorage();
    ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
    RecordBuilder recordBuilder = new RecordBuilder();
    recordBuilder.reset(RecordUtil.FULLY_OPEN_RECORD_TYPE);
    recordBuilder.init();
    List<FieldBinding> fbList = recordValue.getFbList();
    HashSet<String> fieldNames = new HashSet<>();
    for (FieldBinding fb : fbList) {
        fieldName.reset();
        fieldValue.reset();
        // get key
        fieldNameString.setValue(exprToStringLiteral(fb.getLeftExpr()).getStringValue());
        if (!fieldNames.add(fieldNameString.getStringValue())) {
            throw new HyracksDataException("Field " + fieldNameString.getStringValue() + " was specified multiple times");
        }
        stringSerde.serialize(fieldNameString, fieldName.getDataOutput());
        // get value
        parseExpression(fb.getRightExpr(), fieldValue);
        recordBuilder.addField(fieldName, fieldValue);
    }
    // defaults
    for (Pair<String, String> kv : defaults) {
        if (!fieldNames.contains(kv.first)) {
            fieldName.reset();
            fieldValue.reset();
            stringSerde.serialize(new AString(kv.first), fieldName.getDataOutput());
            stringSerde.serialize(new AString(kv.second), fieldValue.getDataOutput());
            recordBuilder.addField(fieldName, fieldValue);
        }
    }
    recordBuilder.write(serialized.getDataOutput(), tagged);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) RecordBuilder(org.apache.asterix.builders.RecordBuilder) FieldBinding(org.apache.asterix.lang.common.expression.FieldBinding) AMutableString(org.apache.asterix.om.base.AMutableString) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) AString(org.apache.asterix.om.base.AString) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HashSet(java.util.HashSet)

Aggregations

AMutableString (org.apache.asterix.om.base.AMutableString)21 AString (org.apache.asterix.om.base.AString)10 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)9 RecordBuilder (org.apache.asterix.builders.RecordBuilder)8 IARecordBuilder (org.apache.asterix.builders.IARecordBuilder)7 AMutableCharArrayString (org.apache.asterix.external.classad.AMutableCharArrayString)3 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)3 OrderedListBuilder (org.apache.asterix.builders.OrderedListBuilder)2 ExprTree (org.apache.asterix.external.classad.ExprTree)2 PrettyPrint (org.apache.asterix.external.classad.PrettyPrint)2 AInt32 (org.apache.asterix.om.base.AInt32)2 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)2 ArrayTupleReference (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleReference)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 CompilationException (org.apache.asterix.common.exceptions.CompilationException)1 Value (org.apache.asterix.external.classad.Value)1