Search in sources :

Example 1 with ConstantEvalFactory

use of org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory in project asterixdb by apache.

the class NonTaggedDataFormat method createMBRFactory.

@SuppressWarnings("unchecked")
@Override
public IScalarEvaluatorFactory[] createMBRFactory(ARecordType recType, List<String> fldName, int recordColumn, int dimension, List<String> filterFieldName, boolean isPointMBR) throws AlgebricksException {
    IScalarEvaluatorFactory evalFactory = getFieldAccessEvaluatorFactory(recType, fldName, recordColumn);
    int numOfFields = isPointMBR ? dimension : dimension * 2;
    IScalarEvaluatorFactory[] evalFactories = new IScalarEvaluatorFactory[numOfFields + (filterFieldName == null ? 0 : 1)];
    ArrayBackedValueStorage abvs1 = new ArrayBackedValueStorage();
    DataOutput dos1 = abvs1.getDataOutput();
    try {
        AInt32 ai = new AInt32(dimension);
        SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(ai.getType()).serialize(ai, dos1);
    } catch (HyracksDataException e) {
        throw new AlgebricksException(e);
    }
    IScalarEvaluatorFactory dimensionEvalFactory = new ConstantEvalFactory(Arrays.copyOf(abvs1.getByteArray(), abvs1.getLength()));
    for (int i = 0; i < numOfFields; i++) {
        ArrayBackedValueStorage abvs2 = new ArrayBackedValueStorage();
        DataOutput dos2 = abvs2.getDataOutput();
        try {
            AInt32 ai = new AInt32(i);
            SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(ai.getType()).serialize(ai, dos2);
        } catch (HyracksDataException e) {
            throw new AlgebricksException(e);
        }
        IScalarEvaluatorFactory coordinateEvalFactory = new ConstantEvalFactory(Arrays.copyOf(abvs2.getByteArray(), abvs2.getLength()));
        evalFactories[i] = new CreateMBREvalFactory(evalFactory, dimensionEvalFactory, coordinateEvalFactory);
    }
    if (filterFieldName != null) {
        evalFactories[numOfFields] = getFieldAccessEvaluatorFactory(recType, filterFieldName, recordColumn);
    }
    return evalFactories;
}
Also used : DataOutput(java.io.DataOutput) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) ConstantEvalFactory(org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) AInt32(org.apache.asterix.om.base.AInt32) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) CreateMBREvalFactory(org.apache.asterix.runtime.evaluators.common.CreateMBREvalFactory)

Example 2 with ConstantEvalFactory

use of org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory 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 3 with ConstantEvalFactory

use of org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory in project asterixdb by apache.

the class NonTaggedDataFormat method partitioningEvaluatorFactory.

@SuppressWarnings("unchecked")
@Override
public Triple<IScalarEvaluatorFactory, ScalarFunctionCallExpression, IAType> partitioningEvaluatorFactory(ARecordType recType, List<String> fldName) throws AlgebricksException {
    String[] names = recType.getFieldNames();
    int n = names.length;
    if (fldName.size() > 1) {
        for (int i = 0; i < n; i++) {
            if (names[i].equals(fldName.get(0))) {
                IScalarEvaluatorFactory recordEvalFactory = new ColumnAccessEvalFactory(GlobalConfig.DEFAULT_INPUT_DATA_COLUMN);
                ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
                DataOutput dos = abvs.getDataOutput();
                try {
                    AInt32 ai = new AInt32(i);
                    SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(ai.getType()).serialize(ai, dos);
                } catch (HyracksDataException e) {
                    throw new AlgebricksException(e);
                }
                IScalarEvaluatorFactory fldIndexEvalFactory = new ConstantEvalFactory(Arrays.copyOf(abvs.getByteArray(), abvs.getLength()));
                IScalarEvaluatorFactory evalFactory = new FieldAccessByIndexEvalFactory(recordEvalFactory, fldIndexEvalFactory, recType);
                IFunctionInfo finfoAccess = BuiltinFunctions.getAsterixFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_INDEX);
                ScalarFunctionCallExpression partitionFun = new ScalarFunctionCallExpression(finfoAccess, new MutableObject<ILogicalExpression>(new VariableReferenceExpression(METADATA_DUMMY_VAR)), new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(new AInt32(i)))));
                return new Triple<IScalarEvaluatorFactory, ScalarFunctionCallExpression, IAType>(evalFactory, partitionFun, recType.getFieldTypes()[i]);
            }
        }
    } else {
        IScalarEvaluatorFactory recordEvalFactory = new ColumnAccessEvalFactory(GlobalConfig.DEFAULT_INPUT_DATA_COLUMN);
        ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
        DataOutput dos = abvs.getDataOutput();
        AOrderedList as = new AOrderedList(fldName);
        try {
            SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(as.getType()).serialize(as, dos);
        } catch (HyracksDataException e) {
            throw new AlgebricksException(e);
        }
        IScalarEvaluatorFactory evalFactory = new FieldAccessNestedEvalFactory(recordEvalFactory, recType, fldName);
        IFunctionInfo finfoAccess = BuiltinFunctions.getAsterixFunctionInfo(BuiltinFunctions.FIELD_ACCESS_NESTED);
        ScalarFunctionCallExpression partitionFun = new ScalarFunctionCallExpression(finfoAccess, new MutableObject<ILogicalExpression>(new VariableReferenceExpression(METADATA_DUMMY_VAR)), new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(as))));
        return new Triple<IScalarEvaluatorFactory, ScalarFunctionCallExpression, IAType>(evalFactory, partitionFun, recType.getSubFieldType(fldName));
    }
    throw new AlgebricksException("Could not find field " + fldName + " in the schema.");
}
Also used : DataOutput(java.io.DataOutput) IFunctionInfo(org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo) ConstantEvalFactory(org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) 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) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) Triple(org.apache.hyracks.algebricks.common.utils.Triple) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) AOrderedList(org.apache.asterix.om.base.AOrderedList) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) ColumnAccessEvalFactory(org.apache.hyracks.algebricks.runtime.evaluators.ColumnAccessEvalFactory) FieldAccessByIndexEvalFactory(org.apache.asterix.runtime.evaluators.functions.records.FieldAccessByIndexEvalFactory) FieldAccessNestedEvalFactory(org.apache.asterix.runtime.evaluators.functions.records.FieldAccessNestedEvalFactory) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)

Example 4 with ConstantEvalFactory

use of org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory in project asterixdb by apache.

the class ExceptionIT method getArgCombinations.

private Iterator<IScalarEvaluatorFactory[]> getArgCombinations(final int inputArity) {
    final int argSize = inputArity >= 0 ? inputArity : 3;
    final int numCombinations = (int) Math.pow(ATypeTag.values().length, argSize);
    return new Iterator<IScalarEvaluatorFactory[]>() {

        private int index = 0;

        @Override
        public boolean hasNext() {
            return index < numCombinations;
        }

        @Override
        public IScalarEvaluatorFactory[] next() {
            IScalarEvaluatorFactory[] scalarEvaluatorFactories = new IScalarEvaluatorFactory[argSize];
            for (int j = 0; j < argSize; ++j) {
                int base = (int) Math.pow(ATypeTag.values().length, j);
                // Enumerates through all possible type tags.
                byte serializedTypeTag = (byte) ((index / base) % ATypeTag.values().length);
                scalarEvaluatorFactories[j] = new ConstantEvalFactory(new byte[] { serializedTypeTag });
            }
            ++index;
            return scalarEvaluatorFactories;
        }
    };
}
Also used : ConstantEvalFactory(org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory) Iterator(java.util.Iterator) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)

Example 5 with ConstantEvalFactory

use of org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory in project asterixdb by apache.

the class NullMissingTest method getArgCombinations.

private Iterator<IScalarEvaluatorFactory[]> getArgCombinations(int inputArity) {
    int argSize = inputArity >= 0 ? inputArity : 3;
    final int numCombinations = 1 << argSize;
    return new Iterator<IScalarEvaluatorFactory[]>() {

        private int index = 0;

        @Override
        public boolean hasNext() {
            return index < numCombinations;
        }

        @Override
        public IScalarEvaluatorFactory[] next() {
            IScalarEvaluatorFactory[] scalarEvaluatorFactories = new IScalarEvaluatorFactory[argSize];
            for (int j = 0; j < argSize; ++j) {
                byte serializedTypeTag = (index & (1 << j)) != 0 ? ATypeTag.SERIALIZED_MISSING_TYPE_TAG : ATypeTag.SERIALIZED_NULL_TYPE_TAG;
                scalarEvaluatorFactories[j] = new ConstantEvalFactory(new byte[] { serializedTypeTag });
            }
            ++index;
            return scalarEvaluatorFactories;
        }
    };
}
Also used : ConstantEvalFactory(org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory) Iterator(java.util.Iterator) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)

Aggregations

ConstantEvalFactory (org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory)6 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)5 DataOutput (java.io.DataOutput)4 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)4 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)4 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)4 AInt32 (org.apache.asterix.om.base.AInt32)3 Iterator (java.util.Iterator)2 AOrderedList (org.apache.asterix.om.base.AOrderedList)2 AString (org.apache.asterix.om.base.AString)2 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)2 FieldAccessByIndexEvalFactory (org.apache.asterix.runtime.evaluators.functions.records.FieldAccessByIndexEvalFactory)2 FieldAccessNestedEvalFactory (org.apache.asterix.runtime.evaluators.functions.records.FieldAccessNestedEvalFactory)2 ColumnAccessEvalFactory (org.apache.hyracks.algebricks.runtime.evaluators.ColumnAccessEvalFactory)2 IAObject (org.apache.asterix.om.base.IAObject)1 CreateMBREvalFactory (org.apache.asterix.runtime.evaluators.common.CreateMBREvalFactory)1 Triple (org.apache.hyracks.algebricks.common.utils.Triple)1 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)1 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)1 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)1