Search in sources :

Example 6 with ExprTree

use of org.apache.asterix.external.classad.ExprTree in project asterixdb by apache.

the class ClassAdParser method parseNextExpression.

public ExprTree parseNextExpression() throws IOException {
    if (!lexer.wasInitialized()) {
        return null;
    } else {
        ExprTreeHolder expr = objectPool.mutableExprPool.get();
        parseExpression(expr, false);
        ExprTree innerTree = expr.getInnerTree();
        return innerTree;
    }
}
Also used : ExprTreeHolder(org.apache.asterix.external.classad.ExprTreeHolder) ExprTree(org.apache.asterix.external.classad.ExprTree)

Example 7 with ExprTree

use of org.apache.asterix.external.classad.ExprTree in project asterixdb by apache.

the class ClassAdParser method parseRecord.

private void parseRecord(ARecordType recType, ClassAd pAd, DataOutput out) throws IOException, AsterixException {
    ArrayBackedValueStorage fieldValueBuffer = getTempBuffer();
    ArrayBackedValueStorage fieldNameBuffer = getTempBuffer();
    IARecordBuilder recBuilder = getRecordBuilder();
    BitSet nulls = null;
    if (recType != null) {
        nulls = getBitSet();
        recBuilder.reset(recType);
    } else {
        recBuilder.reset(null);
    }
    recBuilder.init();
    Boolean openRecordField = false;
    int fieldId = 0;
    IAType fieldType = null;
    // new stuff
    Map<CaseInsensitiveString, ExprTree> attrs = pAd.getAttrList();
    for (Entry<CaseInsensitiveString, ExprTree> entry : attrs.entrySet()) {
        // reset buffers
        fieldNameBuffer.reset();
        fieldValueBuffer.reset();
        // take care of field name
        String fldName = entry.getKey().get();
        if (recType != null) {
            fieldId = recBuilder.getFieldId(fldName);
            if (fieldId < 0 && !recType.isOpen()) {
                throw new HyracksDataException("This record is closed, you can not add extra fields !!");
            } else if (fieldId < 0 && recType.isOpen()) {
                aStringFieldName.setValue(fldName);
                stringSerde.serialize(aStringFieldName, fieldNameBuffer.getDataOutput());
                openRecordField = true;
                fieldType = null;
            } else {
                // a closed field
                nulls.set(fieldId);
                fieldType = recType.getFieldTypes()[fieldId];
                openRecordField = false;
            }
        } else {
            aStringFieldName.setValue(fldName);
            stringSerde.serialize(aStringFieldName, fieldNameBuffer.getDataOutput());
            openRecordField = true;
            fieldType = null;
        }
        // add field value to value buffer
        writeFieldValueToBuffer(fieldType, fieldValueBuffer.getDataOutput(), fldName, entry.getValue(), pAd);
        if (openRecordField) {
            if (fieldValueBuffer.getByteArray()[0] != ATypeTag.MISSING.serialize()) {
                recBuilder.addField(fieldNameBuffer, fieldValueBuffer);
            }
        } else if (NonTaggedFormatUtil.isOptional(fieldType)) {
            if (fieldValueBuffer.getByteArray()[0] != ATypeTag.MISSING.serialize()) {
                recBuilder.addField(fieldId, fieldValueBuffer);
            }
        } else {
            recBuilder.addField(fieldId, fieldValueBuffer);
        }
    }
    if (recType != null) {
        int optionalFieldId = checkOptionalConstraints(recType, nulls);
        if (optionalFieldId != -1) {
            throw new HyracksDataException("Field: " + recType.getFieldNames()[optionalFieldId] + " can not be optional");
        }
    }
    recBuilder.write(out, true);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) BitSet(java.util.BitSet) ExprTree(org.apache.asterix.external.classad.ExprTree) CaseInsensitiveString(org.apache.asterix.external.classad.CaseInsensitiveString) AMutableCharArrayString(org.apache.asterix.external.classad.AMutableCharArrayString) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) ABoolean(org.apache.asterix.om.base.ABoolean) CaseInsensitiveString(org.apache.asterix.external.classad.CaseInsensitiveString) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IAType(org.apache.asterix.om.types.IAType)

Example 8 with ExprTree

use of org.apache.asterix.external.classad.ExprTree in project asterixdb by apache.

the class FunctionalTester method handle_eval.

/*********************************************************************
     * Function: handle_eval
     * Purpose:
     *
     * @throws IOException
     *********************************************************************/
public static void handle_eval(AMutableString line, State state, Parameters parameters, ClassAdObjectPool objectPool) throws IOException {
    AMutableString variable_name = new AMutableString("");
    ExprTree tree;
    Variable variable;
    if (get_variable_name(line, true, variable_name, state, parameters)) {
        tree = get_expr(line, state, parameters, objectPool);
        if (tree != null) {
            Value value = new Value(objectPool);
            if (!evaluate_expr(tree, value, parameters, objectPool)) {
                print_error_message("Couldn't evaluate rvalue", state);
            } else {
                variable = new Variable(variable_name.getStringValue(), value);
                variables.put(variable_name.getStringValue(), variable);
            }
        }
    }
    return;
}
Also used : Value(org.apache.asterix.external.classad.Value) AMutableString(org.apache.asterix.om.base.AMutableString) ExprTree(org.apache.asterix.external.classad.ExprTree)

Example 9 with ExprTree

use of org.apache.asterix.external.classad.ExprTree 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 10 with ExprTree

use of org.apache.asterix.external.classad.ExprTree in project asterixdb by apache.

the class FunctionalTester method handle_let.

/*********************************************************************
     * Function: handle_let
     * Purpose:
     *
     * @throws IOException
     *********************************************************************/
public static void handle_let(AMutableString line, State state, Parameters parameters, ClassAdObjectPool objectPool) throws IOException {
    AMutableString variable_name = new AMutableString(null);
    ExprTree tree;
    Variable variable;
    if (get_variable_name(line, true, variable_name, state, parameters)) {
        tree = get_expr(line, state, parameters, objectPool);
        if (tree != null) {
            variable = new Variable(variable_name.getStringValue(), tree, objectPool);
            variables.put(variable_name.getStringValue(), variable);
            if (parameters.interactive) {
                print_expr(tree, state, parameters, objectPool);
            }
        }
    }
    return;
}
Also used : AMutableString(org.apache.asterix.om.base.AMutableString) ExprTree(org.apache.asterix.external.classad.ExprTree)

Aggregations

ExprTree (org.apache.asterix.external.classad.ExprTree)12 ClassAdParser (org.apache.asterix.external.library.ClassAdParser)5 AMutableString (org.apache.asterix.om.base.AMutableString)4 AMutableCharArrayString (org.apache.asterix.external.classad.AMutableCharArrayString)3 ClassAd (org.apache.asterix.external.classad.ClassAd)3 Value (org.apache.asterix.external.classad.Value)3 IAType (org.apache.asterix.om.types.IAType)3 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)3 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)3 ArrayList (java.util.ArrayList)2 CaseInsensitiveString (org.apache.asterix.external.classad.CaseInsensitiveString)2 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)2 Path (java.nio.file.Path)1 BitSet (java.util.BitSet)1 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1 IARecordBuilder (org.apache.asterix.builders.IARecordBuilder)1 OrderedListBuilder (org.apache.asterix.builders.OrderedListBuilder)1 UnorderedListBuilder (org.apache.asterix.builders.UnorderedListBuilder)1 CharArrayLexerSource (org.apache.asterix.external.classad.CharArrayLexerSource)1