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);
}
}
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;
}
}
}
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;
}
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()));
}
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);
}
Aggregations