Search in sources :

Example 11 with IAObject

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

the class ConstantExpressionUtil method getConstantIaObject.

public static IAObject getConstantIaObject(ILogicalExpression expr, ATypeTag typeTag) {
    if (expr.getExpressionTag() != LogicalExpressionTag.CONSTANT) {
        return null;
    }
    final IAlgebricksConstantValue acv = ((ConstantExpression) expr).getValue();
    if (!(acv instanceof AsterixConstantValue)) {
        return null;
    }
    final IAObject iaObject = ((AsterixConstantValue) acv).getObject();
    if (typeTag != null) {
        return iaObject.getType().getTypeTag() == typeTag ? iaObject : null;
    } else {
        return iaObject;
    }
}
Also used : AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) IAObject(org.apache.asterix.om.base.IAObject) IAlgebricksConstantValue(org.apache.hyracks.algebricks.core.algebra.expressions.IAlgebricksConstantValue)

Example 12 with IAObject

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

the class RecordRemoveFieldsTypeComputer method getPathFromConstantExpression.

private void getPathFromConstantExpression(String funcName, ILogicalExpression expression, Set<String> fieldNameSet, List<List<String>> pathList) throws AlgebricksException {
    ConstantExpression ce = (ConstantExpression) expression;
    if (!(ce.getValue() instanceof AsterixConstantValue)) {
        throw new InvalidExpressionException(funcName, 1, ce, LogicalExpressionTag.CONSTANT);
    }
    IAObject item = ((AsterixConstantValue) ce.getValue()).getObject();
    ATypeTag type = item.getType().getTypeTag();
    switch(type) {
        case STRING:
            String fn = ((AString) item).getStringValue();
            fieldNameSet.add(fn);
            break;
        case ARRAY:
            AOrderedList pathOrdereList = (AOrderedList) item;
            String fieldName = ((AString) pathOrdereList.getItem(0)).getStringValue();
            fieldNameSet.add(fieldName);
            List<String> path = new ArrayList<>();
            for (int i = 0; i < pathOrdereList.size(); i++) {
                path.add(((AString) pathOrdereList.getItem(i)).getStringValue());
            }
            pathList.add(path);
            break;
        default:
            throw new UnsupportedTypeException(funcName, type);
    }
}
Also used : AOrderedList(org.apache.asterix.om.base.AOrderedList) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) ATypeTag(org.apache.asterix.om.types.ATypeTag) InvalidExpressionException(org.apache.asterix.om.exceptions.InvalidExpressionException) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) IAObject(org.apache.asterix.om.base.IAObject) ArrayList(java.util.ArrayList) UnsupportedTypeException(org.apache.asterix.om.exceptions.UnsupportedTypeException) AString(org.apache.asterix.om.base.AString) AString(org.apache.asterix.om.base.AString)

Example 13 with IAObject

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

the class FuzzyEqRule method expandFuzzyEq.

private boolean expandFuzzyEq(Mutable<ILogicalExpression> expRef, IOptimizationContext context, IVariableTypeEnvironment env, MetadataProvider metadataProvider) throws AlgebricksException {
    ILogicalExpression exp = expRef.getValue();
    if (exp.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
        return false;
    }
    boolean expanded = false;
    AbstractFunctionCallExpression funcExp = (AbstractFunctionCallExpression) exp;
    FunctionIdentifier fi = funcExp.getFunctionIdentifier();
    if (fi.equals(BuiltinFunctions.FUZZY_EQ)) {
        List<Mutable<ILogicalExpression>> inputExps = funcExp.getArguments();
        String simFuncName = FuzzyUtils.getSimFunction(metadataProvider);
        ArrayList<Mutable<ILogicalExpression>> similarityArgs = new ArrayList<Mutable<ILogicalExpression>>();
        for (int i = 0; i < inputExps.size(); ++i) {
            Mutable<ILogicalExpression> inputExpRef = inputExps.get(i);
            similarityArgs.add(inputExpRef);
        }
        FunctionIdentifier simFunctionIdentifier = FuzzyUtils.getFunctionIdentifier(simFuncName);
        ScalarFunctionCallExpression similarityExp = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(simFunctionIdentifier), similarityArgs);
        // Add annotations from the original fuzzy-eq function.
        similarityExp.getAnnotations().putAll(funcExp.getAnnotations());
        ArrayList<Mutable<ILogicalExpression>> cmpArgs = new ArrayList<Mutable<ILogicalExpression>>();
        cmpArgs.add(new MutableObject<ILogicalExpression>(similarityExp));
        IAObject simThreshold = FuzzyUtils.getSimThreshold(metadataProvider, simFuncName);
        cmpArgs.add(new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(simThreshold))));
        ScalarFunctionCallExpression cmpExpr = FuzzyUtils.getComparisonExpr(simFuncName, cmpArgs);
        expRef.setValue(cmpExpr);
        return true;
    } else if (fi.equals(AlgebricksBuiltinFunctions.AND) || fi.equals(AlgebricksBuiltinFunctions.OR)) {
        for (int i = 0; i < 2; i++) {
            if (expandFuzzyEq(funcExp.getArguments().get(i), context, env, metadataProvider)) {
                expanded = true;
            }
        }
    }
    return expanded;
}
Also used : AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) IAObject(org.apache.asterix.om.base.IAObject) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) ArrayList(java.util.ArrayList) FunctionIdentifier(org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)

Example 14 with IAObject

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

the class IntroduceSecondaryIndexInsertDeleteRule method getOpenOrNestedFieldAccessFunction.

private static AbstractFunctionCallExpression getOpenOrNestedFieldAccessFunction(Mutable<ILogicalExpression> varRef, List<String> fields) {
    ScalarFunctionCallExpression func;
    if (fields.size() > 1) {
        IAObject fieldList = stringListToAOrderedList(fields);
        Mutable<ILogicalExpression> fieldRef = constantToMutableLogicalExpression(fieldList);
        // Create an expression for the nested case
        func = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_NESTED), varRef, fieldRef);
    } else {
        IAObject fieldList = new AString(fields.get(0));
        Mutable<ILogicalExpression> fieldRef = constantToMutableLogicalExpression(fieldList);
        // Create an expression for the open field case (By name)
        func = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_NAME), varRef, fieldRef);
    }
    return func;
}
Also used : ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) IAObject(org.apache.asterix.om.base.IAObject) AString(org.apache.asterix.om.base.AString) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)

Example 15 with IAObject

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

the class AccessMethodUtils method checkFTSearchConstantExpression.

// Checks whether a proper constant expression is in place for the full-text search.
// A proper constant expression in the full-text search should be among string, string type (Un)ordered list.
public static void checkFTSearchConstantExpression(ILogicalExpression constExpression) throws AlgebricksException {
    IAObject objectFromExpr = ConstantExpressionUtil.getConstantIaObject(constExpression, null);
    String arg2Value;
    IACursor oListCursor;
    switch(objectFromExpr.getType().getTypeTag()) {
        case STRING:
            arg2Value = ConstantExpressionUtil.getStringConstant(objectFromExpr);
            checkAndGenerateFTSearchExceptionForStringPhrase(arg2Value);
            break;
        case ARRAY:
            oListCursor = ConstantExpressionUtil.getOrderedListConstant(objectFromExpr).getCursor();
            checkEachElementInFTSearchListPredicate(oListCursor);
            break;
        case MULTISET:
            oListCursor = ConstantExpressionUtil.getUnorderedListConstant(objectFromExpr).getCursor();
            checkEachElementInFTSearchListPredicate(oListCursor);
            break;
        default:
            throw new CompilationException(ErrorCode.COMPILATION_TYPE_UNSUPPORTED, BuiltinFunctions.FULLTEXT_CONTAINS.getName(), objectFromExpr.getType().getTypeTag());
    }
}
Also used : CompilationException(org.apache.asterix.common.exceptions.CompilationException) IAObject(org.apache.asterix.om.base.IAObject) AString(org.apache.asterix.om.base.AString) IACursor(org.apache.asterix.om.base.IACursor)

Aggregations

IAObject (org.apache.asterix.om.base.IAObject)27 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)16 AString (org.apache.asterix.om.base.AString)12 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)10 ATypeTag (org.apache.asterix.om.types.ATypeTag)9 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)8 ArrayList (java.util.ArrayList)7 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)7 AOrderedList (org.apache.asterix.om.base.AOrderedList)5 IAType (org.apache.asterix.om.types.IAType)5 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)5 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)5 AInt32 (org.apache.asterix.om.base.AInt32)4 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)4 DataOutput (java.io.DataOutput)3 ARecordType (org.apache.asterix.om.types.ARecordType)3 Mutable (org.apache.commons.lang3.mutable.Mutable)3 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)3 DataInput (java.io.DataInput)2 IOException (java.io.IOException)2