Search in sources :

Example 36 with AString

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

the class PlanTranslationUtil method prepareMetaKeyAccessExpression.

public static void prepareMetaKeyAccessExpression(List<String> field, LogicalVariable resVar, List<Mutable<ILogicalExpression>> assignExpressions, List<LogicalVariable> vars, List<Mutable<ILogicalExpression>> varRefs, IVariableContext context) {
    IAObject value = (field.size() > 1) ? new AOrderedList(field) : new AString(field.get(0));
    ScalarFunctionCallExpression metaKeyFunction = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.META_KEY));
    metaKeyFunction.getArguments().add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(resVar)));
    metaKeyFunction.getArguments().add(new MutableObject<>(new ConstantExpression(new AsterixConstantValue(value))));
    assignExpressions.add(new MutableObject<ILogicalExpression>(metaKeyFunction));
    LogicalVariable v = context.newVar();
    vars.add(v);
    if (varRefs != null) {
        varRefs.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(v)));
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AOrderedList(org.apache.asterix.om.base.AOrderedList) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) IAObject(org.apache.asterix.om.base.IAObject) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) AString(org.apache.asterix.om.base.AString) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)

Example 37 with AString

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

the class FieldAccessNestedResultType method getResultType.

@Override
protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
    IAType firstArgType = strippedInputTypes[0];
    if (firstArgType.getTypeTag() != ATypeTag.OBJECT) {
        return BuiltinType.ANY;
    }
    AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
    ILogicalExpression arg1 = funcExpr.getArguments().get(1).getValue();
    if (arg1.getExpressionTag() != LogicalExpressionTag.CONSTANT) {
        return BuiltinType.ANY;
    }
    ConstantExpression ce = (ConstantExpression) arg1;
    IAObject v = ((AsterixConstantValue) ce.getValue()).getObject();
    List<String> fieldPath = new ArrayList<>();
    if (v.getType().getTypeTag() == ATypeTag.ARRAY) {
        for (int i = 0; i < ((AOrderedList) v).size(); i++) {
            fieldPath.add(((AString) ((AOrderedList) v).getItem(i)).getStringValue());
        }
    } else {
        fieldPath.add(((AString) v).getStringValue());
    }
    ARecordType recType = (ARecordType) firstArgType;
    IAType fieldType = recType.getSubFieldType(fieldPath);
    return fieldType == null ? BuiltinType.ANY : fieldType;
}
Also used : ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AOrderedList(org.apache.asterix.om.base.AOrderedList) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) IAObject(org.apache.asterix.om.base.IAObject) ArrayList(java.util.ArrayList) AString(org.apache.asterix.om.base.AString) ARecordType(org.apache.asterix.om.types.ARecordType) IAType(org.apache.asterix.om.types.IAType)

Example 38 with AString

use of org.apache.asterix.om.base.AString 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)

Example 39 with AString

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

the class RecordRemoveFieldsTypeComputer method getListFromExpression.

private List<String> getListFromExpression(String funcName, ILogicalExpression expression) throws AlgebricksException {
    AbstractFunctionCallExpression funcExp = (AbstractFunctionCallExpression) expression;
    List<Mutable<ILogicalExpression>> args = funcExp.getArguments();
    List<String> list = new ArrayList<>();
    for (Mutable<ILogicalExpression> arg : args) {
        // At this point all elements has to be a constant
        // Input list has only one level of nesting (list of list or list of strings)
        ConstantExpression ce = (ConstantExpression) arg.getValue();
        if (!(ce.getValue() instanceof AsterixConstantValue)) {
            throw new InvalidExpressionException(funcName, 1, ce, LogicalExpressionTag.CONSTANT);
        }
        IAObject item = ((AsterixConstantValue) ce.getValue()).getObject();
        ATypeTag type = item.getType().getTypeTag();
        if (type == ATypeTag.STRING) {
            list.add(((AString) item).getStringValue());
        } else {
            throw new UnsupportedTypeException(funcName, type);
        }
    }
    return list;
}
Also used : AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) IAObject(org.apache.asterix.om.base.IAObject) ArrayList(java.util.ArrayList) AString(org.apache.asterix.om.base.AString) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) ATypeTag(org.apache.asterix.om.types.ATypeTag) InvalidExpressionException(org.apache.asterix.om.exceptions.InvalidExpressionException) UnsupportedTypeException(org.apache.asterix.om.exceptions.UnsupportedTypeException)

Example 40 with AString

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

the class SerializerDeserializerTestUtils method generateRecords.

public static ARecord[] generateRecords(ARecordType addrRecordType, ARecordType employeeType) {
    AOrderedListType addrListType = new AOrderedListType(addrRecordType, "address_history");
    ARecord addr11 = new ARecord(addrRecordType, new IAObject[] { new AString("120 San Raman Street"), new AString("Irvine"), new AString("CA"), new AInt16((short) 95051), new AInterval(0, 100, (byte) 0) });
    ARecord addr12 = new ARecord(addrRecordType, new IAObject[] { new AString("210 University Drive"), new AString("Philadelphia"), new AString("PA"), new AInt16((short) 10086), new AInterval(100, 300, (byte) 0) });
    ARecord addr21 = new ARecord(addrRecordType, new IAObject[] { new AString("1 College Street"), new AString("Seattle"), new AString("WA"), new AInt16((short) 20012), new AInterval(400, 500, (byte) 0) });
    ARecord addr22 = new ARecord(addrRecordType, new IAObject[] { new AString("20 Lindsay Avenue"), new AString("Columbus"), new AString("OH"), new AInt16((short) 30120), new AInterval(600, 900, (byte) 0) });
    ARecord addr31 = new ARecord(addrRecordType, new IAObject[] { new AString("200 14th Avenue"), new AString("Long Island"), new AString("NY"), new AInt16((short) 95011), new AInterval(12000, 14000, (byte) 0) });
    // With nested open field addr31.
    ARecord addr32 = new ARecord(addrRecordType, new IAObject[] { new AString("51 8th Street"), new AString("Orlando"), new AString("FL"), new AInt16((short) 49045), new AInterval(190000, 200000, (byte) 0) });
    ARecord record1 = new ARecord(employeeType, new IAObject[] { new AInt64(0L), new AString("Tom"), new AOrderedList(addrListType, Arrays.asList(new IAObject[] { addr11, addr12 })) });
    ARecord record2 = new ARecord(employeeType, new IAObject[] { new AInt64(1L), new AString("John"), new AOrderedList(addrListType, Arrays.asList(new IAObject[] { addr21, addr22 })) });
    ARecord record3 = new ARecord(employeeType, new IAObject[] { new AInt64(2L), new AString("Lindsay"), new AOrderedList(addrListType, Arrays.asList(new IAObject[] { addr31, addr32 })) });
    // With nested open field addr41.
    ARecord record4 = new ARecord(employeeType, new IAObject[] { new AInt64(3L), new AString("Joshua"), new AOrderedList(addrListType, Arrays.asList(new IAObject[] {})) });
    ARecord[] records = new ARecord[] { record1, record2, record3, record4 };
    return records;
}
Also used : AInt16(org.apache.asterix.om.base.AInt16) ARecord(org.apache.asterix.om.base.ARecord) AOrderedList(org.apache.asterix.om.base.AOrderedList) AOrderedListType(org.apache.asterix.om.types.AOrderedListType) AInterval(org.apache.asterix.om.base.AInterval) AString(org.apache.asterix.om.base.AString) AInt64(org.apache.asterix.om.base.AInt64)

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