Search in sources :

Example 21 with AlgebricksException

use of org.apache.hyracks.algebricks.common.exceptions.AlgebricksException in project asterixdb by apache.

the class ResultUtil method printStatus.

public static void printStatus(SessionOutput output, AbstractQueryApiServlet.ResultStatus rs) {
    try {
        final AlgebricksAppendable app = new AlgebricksAppendable(output.out());
        output.appendStatus(app, rs.str());
    } catch (AlgebricksException e) {
        LOGGER.warn("error printing status", e);
    }
}
Also used : AlgebricksAppendable(org.apache.hyracks.algebricks.core.algebra.prettyprint.AlgebricksAppendable) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)

Example 22 with AlgebricksException

use of org.apache.hyracks.algebricks.common.exceptions.AlgebricksException in project asterixdb by apache.

the class ExceptionTest method testTypeComputer.

private void testTypeComputer(Class<? extends IResultTypeComputer> c) throws Exception {
    // Mocks the type environment.
    IVariableTypeEnvironment mockTypeEnv = mock(IVariableTypeEnvironment.class);
    // Mocks the metadata provider.
    IMetadataProvider<?, ?> mockMetadataProvider = mock(IMetadataProvider.class);
    // Mocks function expression.
    AbstractFunctionCallExpression mockExpr = mock(AbstractFunctionCallExpression.class);
    FunctionIdentifier fid = mock(FunctionIdentifier.class);
    when(mockExpr.getFunctionIdentifier()).thenReturn(fid);
    when(fid.getName()).thenReturn("testFunction");
    int numCombination = (int) Math.pow(ATypeTag.values().length, 2);
    // Sets two arguments for the mocked function expression.
    for (int index = 0; index < numCombination; ++index) {
        try {
            List<Mutable<ILogicalExpression>> argRefs = new ArrayList<>();
            for (int argIndex = 0; argIndex < 2; ++argIndex) {
                int base = (int) Math.pow(ATypeTag.values().length, argIndex);
                ILogicalExpression mockArg = mock(ILogicalExpression.class);
                argRefs.add(new MutableObject<>(mockArg));
                IAType mockType = mock(IAType.class);
                when(mockTypeEnv.getType(mockArg)).thenReturn(mockType);
                int serializedTypeTag = (index / base) % ATypeTag.values().length + 1;
                ATypeTag typeTag = ATypeTag.VALUE_TYPE_MAPPING[serializedTypeTag];
                if (typeTag == null) {
                    // For some reason, type tag 39 does not exist.
                    typeTag = ATypeTag.ANY;
                }
                when(mockType.getTypeTag()).thenReturn(typeTag);
            }
            // Sets up arguments for the mocked expression.
            when(mockExpr.getArguments()).thenReturn(argRefs);
            // Sets up required/actual types of the mocked expression.
            Object[] opaqueParameters = new Object[2];
            opaqueParameters[0] = BuiltinType.ANY;
            opaqueParameters[1] = BuiltinType.ANY;
            when(mockExpr.getOpaqueParameters()).thenReturn(opaqueParameters);
            // Invokes a type computer.
            IResultTypeComputer instance = (IResultTypeComputer) c.getField("INSTANCE").get(null);
            instance.computeType(mockExpr, mockTypeEnv, mockMetadataProvider);
        } catch (AlgebricksException ae) {
            String msg = ae.getMessage();
            if (msg.startsWith("ASX")) {
                // Verifies the error code.
                int errorCode = Integer.parseInt(msg.substring(3, 7));
                Assert.assertTrue(errorCode >= 1000 && errorCode < 2000);
                continue;
            } else {
                // Any root-level compilation exceptions thrown from type computers should have an error code.
                Assert.assertTrue(!(ae instanceof AlgebricksException) || (ae.getCause() != null));
            }
        } catch (ClassCastException e) {
            continue;
        }
    }
}
Also used : IResultTypeComputer(org.apache.asterix.om.typecomputer.base.IResultTypeComputer) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ArrayList(java.util.ArrayList) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) FunctionIdentifier(org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) ATypeTag(org.apache.asterix.om.types.ATypeTag) MutableObject(org.apache.commons.lang3.mutable.MutableObject) IVariableTypeEnvironment(org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment) IAType(org.apache.asterix.om.types.IAType)

Example 23 with AlgebricksException

use of org.apache.hyracks.algebricks.common.exceptions.AlgebricksException 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 24 with AlgebricksException

use of org.apache.hyracks.algebricks.common.exceptions.AlgebricksException 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 25 with AlgebricksException

use of org.apache.hyracks.algebricks.common.exceptions.AlgebricksException in project asterixdb by apache.

the class StreamProjectPOperator method contributeRuntimeOperator.

@Override
public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema propagatedSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException {
    ProjectOperator project = (ProjectOperator) op;
    int[] projectionList = new int[project.getVariables().size()];
    int i = 0;
    for (LogicalVariable v : project.getVariables()) {
        int pos = inputSchemas[0].findVariable(v);
        if (pos < 0) {
            throw new AlgebricksException("Could not find variable " + v + ".");
        }
        projectionList[i++] = pos;
    }
    StreamProjectRuntimeFactory runtime = new StreamProjectRuntimeFactory(projectionList, flushFramesRapidly);
    RecordDescriptor recDesc = JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op), propagatedSchema, context);
    builder.contributeMicroOperator(project, runtime, recDesc);
    ILogicalOperator src = project.getInputs().get(0).getValue();
    builder.contributeGraphEdge(src, 0, project, 0);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ProjectOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.ProjectOperator) RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) StreamProjectRuntimeFactory(org.apache.hyracks.algebricks.runtime.operators.std.StreamProjectRuntimeFactory) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)

Aggregations

AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)134 MetadataException (org.apache.asterix.metadata.MetadataException)42 ArrayList (java.util.ArrayList)39 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)39 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)38 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)37 AsterixException (org.apache.asterix.common.exceptions.AsterixException)36 IOException (java.io.IOException)35 CompilationException (org.apache.asterix.common.exceptions.CompilationException)33 Dataset (org.apache.asterix.metadata.entities.Dataset)31 IAType (org.apache.asterix.om.types.IAType)31 Mutable (org.apache.commons.lang3.mutable.Mutable)30 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)30 Pair (org.apache.hyracks.algebricks.common.utils.Pair)28 Index (org.apache.asterix.metadata.entities.Index)26 RemoteException (java.rmi.RemoteException)25 ACIDException (org.apache.asterix.common.exceptions.ACIDException)24 AlgebricksPartitionConstraint (org.apache.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint)23 MetadataTransactionContext (org.apache.asterix.metadata.MetadataTransactionContext)22 AString (org.apache.asterix.om.base.AString)21