Search in sources :

Example 1 with IACollection

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

the class InvertedIndexAccessMethod method isEditDistanceFuncSelectOptimizable.

private boolean isEditDistanceFuncSelectOptimizable(Index index, IOptimizableFuncExpr optFuncExpr) throws AlgebricksException {
    // Check for panic in selection query.
    // TODO: Panic also depends on prePost which is currently hardcoded to be true.
    AsterixConstantValue listOrStrConstVal = (AsterixConstantValue) ((ConstantExpression) optFuncExpr.getConstantExpr(0)).getValue();
    IAObject listOrStrObj = listOrStrConstVal.getObject();
    ATypeTag typeTag = listOrStrObj.getType().getTypeTag();
    if (!isEditDistanceFuncCompatible(typeTag, index.getIndexType())) {
        return false;
    }
    AsterixConstantValue intConstVal = (AsterixConstantValue) ((ConstantExpression) optFuncExpr.getConstantExpr(1)).getValue();
    IAObject intObj = intConstVal.getObject();
    AInt32 edThresh = null;
    // Apply type casting based on numeric types of the input to INTEGER type.
    try {
        edThresh = (AInt32) ATypeHierarchy.convertNumericTypeObject(intObj, ATypeTag.INTEGER);
    } catch (HyracksDataException e) {
        throw new AlgebricksException(e);
    }
    int mergeThreshold = 0;
    if (typeTag == ATypeTag.STRING) {
        AString astr = (AString) listOrStrObj;
        // Compute merge threshold depending on the query grams contain pre- and postfixing
        if (optFuncExpr.containsPartialField()) {
            mergeThreshold = (astr.getStringValue().length() - index.getGramLength() + 1) - edThresh.getIntegerValue() * index.getGramLength();
        } else {
            mergeThreshold = (astr.getStringValue().length() + index.getGramLength() - 1) - edThresh.getIntegerValue() * index.getGramLength();
        }
    }
    if ((typeTag == ATypeTag.ARRAY) && (index.getIndexType() == IndexType.SINGLE_PARTITION_WORD_INVIX || index.getIndexType() == IndexType.LENGTH_PARTITIONED_WORD_INVIX)) {
        IACollection alist = (IACollection) listOrStrObj;
        // Compute merge threshold.
        mergeThreshold = alist.size() - edThresh.getIntegerValue();
    }
    if (mergeThreshold <= 0) {
        // We cannot use index to optimize expr.
        return false;
    }
    return true;
}
Also used : AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) ATypeTag(org.apache.asterix.om.types.ATypeTag) IAObject(org.apache.asterix.om.base.IAObject) IACollection(org.apache.asterix.om.base.IACollection) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) AString(org.apache.asterix.om.base.AString) AInt32(org.apache.asterix.om.base.AInt32) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

AInt32 (org.apache.asterix.om.base.AInt32)1 AString (org.apache.asterix.om.base.AString)1 IACollection (org.apache.asterix.om.base.IACollection)1 IAObject (org.apache.asterix.om.base.IAObject)1 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)1 ATypeTag (org.apache.asterix.om.types.ATypeTag)1 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1