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;
}
}
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);
}
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;
}
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);
}
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;
}
Aggregations