Search in sources :

Example 16 with IAObject

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

the class InvertedIndexAccessMethod method isContainsFuncSelectOptimizable.

private boolean isContainsFuncSelectOptimizable(Index index, IOptimizableFuncExpr optFuncExpr) {
    AsterixConstantValue strConstVal = (AsterixConstantValue) ((ConstantExpression) optFuncExpr.getConstantExpr(0)).getValue();
    IAObject strObj = strConstVal.getObject();
    ATypeTag typeTag = strObj.getType().getTypeTag();
    if (!isContainsFuncCompatible(typeTag, index.getIndexType())) {
        return false;
    }
    // Check that the constant search string has at least gramLength characters.
    if (strObj.getType().getTypeTag() == ATypeTag.STRING) {
        AString astr = (AString) strObj;
        if (astr.getStringValue().length() >= index.getGramLength()) {
            return true;
        }
    }
    return false;
}
Also used : AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) ATypeTag(org.apache.asterix.om.types.ATypeTag) IAObject(org.apache.asterix.om.base.IAObject) AString(org.apache.asterix.om.base.AString)

Example 17 with IAObject

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

the class InvertedIndexAccessMethod method isFullTextContainsFuncSelectOptimizable.

// Checks whether the given index is compatible with full-text search and
// the type of the constant search predicate is STRING, ARRAY, or MULTISET
private boolean isFullTextContainsFuncSelectOptimizable(Index index, IOptimizableFuncExpr optFuncExpr) {
    AsterixConstantValue strConstVal = (AsterixConstantValue) ((ConstantExpression) optFuncExpr.getConstantExpr(0)).getValue();
    IAObject strObj = strConstVal.getObject();
    ATypeTag typeTag = strObj.getType().getTypeTag();
    return isFullTextContainsFuncCompatible(typeTag, index.getIndexType());
}
Also used : AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) ATypeTag(org.apache.asterix.om.types.ATypeTag) IAObject(org.apache.asterix.om.base.IAObject)

Example 18 with IAObject

use of org.apache.asterix.om.base.IAObject 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 19 with IAObject

use of org.apache.asterix.om.base.IAObject 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 20 with IAObject

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

the class NonTaggedDataFormat method getExpressionEvalSizeComputer.

@Override
public IExpressionEvalSizeComputer getExpressionEvalSizeComputer() {
    return new IExpressionEvalSizeComputer() {

        @Override
        public int getEvalSize(ILogicalExpression expr, IVariableEvalSizeEnvironment env) throws AlgebricksException {
            switch(expr.getExpressionTag()) {
                case CONSTANT:
                    {
                        ConstantExpression c = (ConstantExpression) expr;
                        if (c == ConstantExpression.MISSING) {
                            return 1;
                        } else if (c == ConstantExpression.FALSE || c == ConstantExpression.TRUE) {
                            return 2;
                        } else {
                            AsterixConstantValue acv = (AsterixConstantValue) c.getValue();
                            IAObject o = acv.getObject();
                            switch(o.getType().getTypeTag()) {
                                case DOUBLE:
                                    return 9;
                                case FLOAT:
                                    return 5;
                                case BOOLEAN:
                                    return 2;
                                case MISSING:
                                    return 1;
                                case NULL:
                                    return 1;
                                case TINYINT:
                                    return 2;
                                case SMALLINT:
                                    return 3;
                                case INTEGER:
                                    return 5;
                                case BIGINT:
                                    return 9;
                                default:
                                    return -1;
                            }
                        }
                    }
                case FUNCTION_CALL:
                    {
                        AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expr;
                        if (f.getFunctionIdentifier().equals(BuiltinFunctions.TID)) {
                            return 5;
                        } else {
                            // TODO
                            return -1;
                        }
                    }
                default:
                    {
                        // TODO
                        return -1;
                    }
            }
        }
    };
}
Also used : IVariableEvalSizeEnvironment(org.apache.hyracks.algebricks.core.algebra.expressions.IVariableEvalSizeEnvironment) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) IAObject(org.apache.asterix.om.base.IAObject) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) IExpressionEvalSizeComputer(org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionEvalSizeComputer)

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