Search in sources :

Example 1 with IAObject

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

the class LangRecordParseUtil method aOrderedListToString.

private static String aOrderedListToString(AOrderedList ol) throws AlgebricksException {
    StringBuilder delimitedList = new StringBuilder();
    IACursor cursor = ol.getCursor();
    if (cursor.next()) {
        IAObject next = cursor.get();
        delimitedList.append(aObjToString(next));
    }
    while (cursor.next()) {
        IAObject next = cursor.get();
        delimitedList.append(",");
        delimitedList.append(aObjToString(next));
    }
    return delimitedList.toString();
}
Also used : IAObject(org.apache.asterix.om.base.IAObject) IACursor(org.apache.asterix.om.base.IACursor)

Example 2 with IAObject

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

the class PlanTranslationUtil method createFieldAccessExpression.

private static ScalarFunctionCallExpression createFieldAccessExpression(ILogicalExpression target, List<String> field) {
    FunctionIdentifier functionIdentifier;
    IAObject value;
    if (field.size() > 1) {
        functionIdentifier = BuiltinFunctions.FIELD_ACCESS_NESTED;
        value = new AOrderedList(field);
    } else {
        functionIdentifier = BuiltinFunctions.FIELD_ACCESS_BY_NAME;
        value = new AString(field.get(0));
    }
    IFunctionInfo finfoAccess = FunctionUtil.getFunctionInfo(functionIdentifier);
    return new ScalarFunctionCallExpression(finfoAccess, new MutableObject<>(target), new MutableObject<>(new ConstantExpression(new AsterixConstantValue(value))));
}
Also used : FunctionIdentifier(org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier) AOrderedList(org.apache.asterix.om.base.AOrderedList) IFunctionInfo(org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) 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 3 with IAObject

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

the class IDataParser method writeRecord.

/*
     * The following two static methods are expensive. right now, they are used by RSSFeeds and
     * Twitter feed
     * TODO: Get rid of them
     */
public static void writeRecord(AMutableRecord record, DataOutput dataOutput, IARecordBuilder recordBuilder) throws HyracksDataException {
    ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
    int numFields = record.getType().getFieldNames().length;
    for (int pos = 0; pos < numFields; pos++) {
        fieldValue.reset();
        IAObject obj = record.getValueByPos(pos);
        IDataParser.writeObject(obj, fieldValue.getDataOutput());
        recordBuilder.addField(pos, fieldValue);
    }
    recordBuilder.write(dataOutput, true);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IAObject(org.apache.asterix.om.base.IAObject)

Example 4 with IAObject

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

the class NonTaggedDataFormat method getConstantEvalFactory.

@SuppressWarnings("unchecked")
@Override
public IScalarEvaluatorFactory getConstantEvalFactory(IAlgebricksConstantValue value) throws AlgebricksException {
    IAObject obj = null;
    if (value.isMissing()) {
        obj = AMissing.MISSING;
    } else if (value.isTrue()) {
        obj = ABoolean.TRUE;
    } else if (value.isFalse()) {
        obj = ABoolean.FALSE;
    } else {
        AsterixConstantValue acv = (AsterixConstantValue) value;
        obj = acv.getObject();
    }
    ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
    DataOutput dos = abvs.getDataOutput();
    try {
        SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(obj.getType()).serialize(obj, dos);
    } catch (HyracksDataException e) {
        throw new AlgebricksException(e);
    }
    return new ConstantEvalFactory(Arrays.copyOf(abvs.getByteArray(), abvs.getLength()));
}
Also used : DataOutput(java.io.DataOutput) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) IAObject(org.apache.asterix.om.base.IAObject) ConstantEvalFactory(org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 5 with IAObject

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

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