Search in sources :

Example 1 with ColumnAccessEvalFactory

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

the class SecondaryIndexOperationsHelper method createCastOp.

protected AlgebricksMetaOperatorDescriptor createCastOp(JobSpecification spec, DatasetType dsType) {
    CastTypeDescriptor castFuncDesc = (CastTypeDescriptor) CastTypeDescriptor.FACTORY.createFunctionDescriptor();
    castFuncDesc.setImmutableStates(enforcedItemType, itemType);
    int[] outColumns = new int[1];
    int[] projectionList = new int[(dataset.hasMetaPart() ? 2 : 1) + numPrimaryKeys];
    int recordIdx;
    //external datascan operator returns a record as the first field, instead of the last in internal case
    if (dsType == DatasetType.EXTERNAL) {
        recordIdx = 0;
        outColumns[0] = 0;
    } else {
        recordIdx = numPrimaryKeys;
        outColumns[0] = numPrimaryKeys;
    }
    for (int i = 0; i <= numPrimaryKeys; i++) {
        projectionList[i] = i;
    }
    if (dataset.hasMetaPart()) {
        projectionList[numPrimaryKeys + 1] = numPrimaryKeys + 1;
    }
    IScalarEvaluatorFactory[] castEvalFact = new IScalarEvaluatorFactory[] { new ColumnAccessEvalFactory(recordIdx) };
    IScalarEvaluatorFactory[] sefs = new IScalarEvaluatorFactory[1];
    sefs[0] = castFuncDesc.createEvaluatorFactory(castEvalFact);
    AssignRuntimeFactory castAssign = new AssignRuntimeFactory(outColumns, sefs, projectionList);
    return new AlgebricksMetaOperatorDescriptor(spec, 1, 1, new IPushRuntimeFactory[] { castAssign }, new RecordDescriptor[] { enforcedRecDesc });
}
Also used : CastTypeDescriptor(org.apache.asterix.runtime.evaluators.functions.CastTypeDescriptor) AlgebricksMetaOperatorDescriptor(org.apache.hyracks.algebricks.runtime.operators.meta.AlgebricksMetaOperatorDescriptor) ColumnAccessEvalFactory(org.apache.hyracks.algebricks.runtime.evaluators.ColumnAccessEvalFactory) AssignRuntimeFactory(org.apache.hyracks.algebricks.runtime.operators.std.AssignRuntimeFactory) AlgebricksPartitionConstraint(org.apache.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)

Example 2 with ColumnAccessEvalFactory

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

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

the class AbstractScalarAggregateDescriptor method createEvaluatorFactory.

@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) throws AlgebricksException {
    // The aggregate function will get a SingleFieldFrameTupleReference that points to the result of the ScanCollection.
    // The list-item will always reside in the first field (column) of the SingleFieldFrameTupleReference.
    IScalarEvaluatorFactory[] aggFuncArgs = new IScalarEvaluatorFactory[1];
    aggFuncArgs[0] = new ColumnAccessEvalFactory(0);
    // Create aggregate function from this scalar version.
    FunctionIdentifier fid = BuiltinFunctions.getAggregateFunction(getIdentifier());
    IFunctionManager mgr = FunctionManagerHolder.getFunctionManager();
    IFunctionDescriptor fd = mgr.lookupFunction(fid);
    AbstractAggregateFunctionDynamicDescriptor aggFuncDesc = (AbstractAggregateFunctionDynamicDescriptor) fd;
    final IAggregateEvaluatorFactory aggFuncFactory = aggFuncDesc.createAggregateEvaluatorFactory(aggFuncArgs);
    return new IScalarEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
            // Use ScanCollection to iterate over list items.
            ScanCollectionUnnestingFunctionFactory scanCollectionFactory = new ScanCollectionUnnestingFunctionFactory(args[0]);
            return new GenericScalarAggregateFunction(aggFuncFactory.createAggregateEvaluator(ctx), scanCollectionFactory, ctx);
        }
    };
}
Also used : FunctionIdentifier(org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier) IFunctionDescriptor(org.apache.asterix.om.functions.IFunctionDescriptor) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) ScanCollectionUnnestingFunctionFactory(org.apache.asterix.runtime.unnestingfunctions.std.ScanCollectionDescriptor.ScanCollectionUnnestingFunctionFactory) ColumnAccessEvalFactory(org.apache.hyracks.algebricks.runtime.evaluators.ColumnAccessEvalFactory) AbstractAggregateFunctionDynamicDescriptor(org.apache.asterix.runtime.aggregates.base.AbstractAggregateFunctionDynamicDescriptor) IAggregateEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluatorFactory) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) IFunctionManager(org.apache.asterix.om.functions.IFunctionManager)

Example 4 with ColumnAccessEvalFactory

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

the class NonTaggedDataFormat method getFieldAccessEvaluatorFactory.

@SuppressWarnings("unchecked")
@Override
public IScalarEvaluatorFactory getFieldAccessEvaluatorFactory(ARecordType recType, List<String> fldName, int recordColumn) throws AlgebricksException {
    String[] names = recType.getFieldNames();
    int n = names.length;
    boolean fieldFound = false;
    IScalarEvaluatorFactory recordEvalFactory = new ColumnAccessEvalFactory(recordColumn);
    ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
    DataOutput dos = abvs.getDataOutput();
    IScalarEvaluatorFactory evalFactory = null;
    if (fldName.size() == 1) {
        for (int i = 0; i < n; i++) {
            if (names[i].equals(fldName.get(0))) {
                fieldFound = true;
                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()));
                evalFactory = new FieldAccessByIndexEvalFactory(recordEvalFactory, fldIndexEvalFactory, recType);
                return evalFactory;
            }
        }
    }
    if (fldName.size() > 1 || (!fieldFound && recType.isOpen())) {
        if (fldName.size() == 1) {
            AString as = new AString(fldName.get(0));
            try {
                SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(as.getType()).serialize(as, dos);
            } catch (HyracksDataException e) {
                throw new AlgebricksException(e);
            }
        } else {
            AOrderedList as = new AOrderedList(fldName);
            try {
                SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(as.getType()).serialize(as, dos);
            } catch (HyracksDataException e) {
                throw new AlgebricksException(e);
            }
        }
        IScalarEvaluatorFactory[] factories = new IScalarEvaluatorFactory[2];
        factories[0] = recordEvalFactory;
        if (fldName.size() > 1) {
            evalFactory = new FieldAccessNestedEvalFactory(recordEvalFactory, recType, fldName);
        } else {
            evalFactory = FieldAccessByNameDescriptor.FACTORY.createFunctionDescriptor().createEvaluatorFactory(factories);
        }
        return evalFactory;
    } else {
        throw new AlgebricksException("Could not find field " + fldName + " in the schema.");
    }
}
Also used : DataOutput(java.io.DataOutput) ConstantEvalFactory(org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory) 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) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) AOrderedList(org.apache.asterix.om.base.AOrderedList) ColumnAccessEvalFactory(org.apache.hyracks.algebricks.runtime.evaluators.ColumnAccessEvalFactory) FieldAccessByIndexEvalFactory(org.apache.asterix.runtime.evaluators.functions.records.FieldAccessByIndexEvalFactory) AString(org.apache.asterix.om.base.AString) FieldAccessNestedEvalFactory(org.apache.asterix.runtime.evaluators.functions.records.FieldAccessNestedEvalFactory)

Example 5 with ColumnAccessEvalFactory

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

the class SecondaryIndexOperationsHelper method createFilterNullsSelectOp.

public AlgebricksMetaOperatorDescriptor createFilterNullsSelectOp(JobSpecification spec, int numSecondaryKeyFields, RecordDescriptor secondaryRecDesc) throws AlgebricksException {
    IScalarEvaluatorFactory[] andArgsEvalFactories = new IScalarEvaluatorFactory[numSecondaryKeyFields];
    NotDescriptor notDesc = new NotDescriptor();
    IsUnknownDescriptor isUnknownDesc = new IsUnknownDescriptor();
    for (int i = 0; i < numSecondaryKeyFields; i++) {
        // Access column i, and apply 'is not null'.
        ColumnAccessEvalFactory columnAccessEvalFactory = new ColumnAccessEvalFactory(i);
        IScalarEvaluatorFactory isUnknownEvalFactory = isUnknownDesc.createEvaluatorFactory(new IScalarEvaluatorFactory[] { columnAccessEvalFactory });
        IScalarEvaluatorFactory notEvalFactory = notDesc.createEvaluatorFactory(new IScalarEvaluatorFactory[] { isUnknownEvalFactory });
        andArgsEvalFactories[i] = notEvalFactory;
    }
    IScalarEvaluatorFactory selectCond;
    if (numSecondaryKeyFields > 1) {
        // Create conjunctive condition where all secondary index keys must
        // satisfy 'is not null'.
        AndDescriptor andDesc = new AndDescriptor();
        selectCond = andDesc.createEvaluatorFactory(andArgsEvalFactories);
    } else {
        selectCond = andArgsEvalFactories[0];
    }
    StreamSelectRuntimeFactory select = new StreamSelectRuntimeFactory(selectCond, null, BinaryBooleanInspector.FACTORY, false, -1, null);
    AlgebricksMetaOperatorDescriptor asterixSelectOp = new AlgebricksMetaOperatorDescriptor(spec, 1, 1, new IPushRuntimeFactory[] { select }, new RecordDescriptor[] { secondaryRecDesc });
    AlgebricksPartitionConstraintHelper.setPartitionConstraintInJobSpec(spec, asterixSelectOp, primaryPartitionConstraint);
    return asterixSelectOp;
}
Also used : AndDescriptor(org.apache.asterix.runtime.evaluators.functions.AndDescriptor) StreamSelectRuntimeFactory(org.apache.hyracks.algebricks.runtime.operators.std.StreamSelectRuntimeFactory) NotDescriptor(org.apache.asterix.runtime.evaluators.functions.NotDescriptor) AlgebricksMetaOperatorDescriptor(org.apache.hyracks.algebricks.runtime.operators.meta.AlgebricksMetaOperatorDescriptor) ColumnAccessEvalFactory(org.apache.hyracks.algebricks.runtime.evaluators.ColumnAccessEvalFactory) IsUnknownDescriptor(org.apache.asterix.runtime.evaluators.functions.IsUnknownDescriptor) AlgebricksPartitionConstraint(org.apache.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)

Aggregations

IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)5 ColumnAccessEvalFactory (org.apache.hyracks.algebricks.runtime.evaluators.ColumnAccessEvalFactory)5 DataOutput (java.io.DataOutput)2 AInt32 (org.apache.asterix.om.base.AInt32)2 AOrderedList (org.apache.asterix.om.base.AOrderedList)2 AString (org.apache.asterix.om.base.AString)2 FieldAccessByIndexEvalFactory (org.apache.asterix.runtime.evaluators.functions.records.FieldAccessByIndexEvalFactory)2 FieldAccessNestedEvalFactory (org.apache.asterix.runtime.evaluators.functions.records.FieldAccessNestedEvalFactory)2 AlgebricksPartitionConstraint (org.apache.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint)2 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)2 ConstantEvalFactory (org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory)2 AlgebricksMetaOperatorDescriptor (org.apache.hyracks.algebricks.runtime.operators.meta.AlgebricksMetaOperatorDescriptor)2 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)2 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)2 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)1 IFunctionDescriptor (org.apache.asterix.om.functions.IFunctionDescriptor)1 IFunctionManager (org.apache.asterix.om.functions.IFunctionManager)1 AbstractAggregateFunctionDynamicDescriptor (org.apache.asterix.runtime.aggregates.base.AbstractAggregateFunctionDynamicDescriptor)1 AndDescriptor (org.apache.asterix.runtime.evaluators.functions.AndDescriptor)1 CastTypeDescriptor (org.apache.asterix.runtime.evaluators.functions.CastTypeDescriptor)1