use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.
the class OperatorDeepCopyVisitor method visitTokenizeOperator.
@Override
public ILogicalOperator visitTokenizeOperator(TokenizeOperator op, Void arg) throws AlgebricksException {
List<Mutable<ILogicalExpression>> newPrimaryKeyExpressions = new ArrayList<>();
deepCopyExpressionRefs(newPrimaryKeyExpressions, op.getPrimaryKeyExpressions());
List<Mutable<ILogicalExpression>> newSecondaryKeyExpressions = new ArrayList<>();
deepCopyExpressionRefs(newSecondaryKeyExpressions, op.getSecondaryKeyExpressions());
List<LogicalVariable> newTokenizeVars = new ArrayList<>();
deepCopyVars(newTokenizeVars, op.getTokenizeVars());
Mutable<ILogicalExpression> newFilterExpression = new MutableObject<>(((AbstractLogicalExpression) op.getFilterExpression()).cloneExpression());
List<Object> newTokenizeVarTypes = new ArrayList<>();
deepCopyObjects(newTokenizeVarTypes, op.getTokenizeVarTypes());
TokenizeOperator tokenizeOp = new TokenizeOperator(op.getDataSourceIndex(), newPrimaryKeyExpressions, newSecondaryKeyExpressions, newTokenizeVars, newFilterExpression, op.getOperation(), op.isBulkload(), op.isPartitioned(), newTokenizeVarTypes);
return tokenizeOp;
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.
the class IsomorphismVariableMappingVisitor method mapVariablesForAbstractAssign.
private void mapVariablesForAbstractAssign(List<LogicalVariable> variablesLeft, List<Mutable<ILogicalExpression>> exprsLeft, List<LogicalVariable> variablesRight, List<Mutable<ILogicalExpression>> exprsRight) {
if (variablesLeft.size() != variablesRight.size()) {
return;
}
int size = variablesLeft.size();
// Keeps track of already matched right side variables.
Set<LogicalVariable> matchedRightVars = new HashSet<>();
for (int i = 0; i < size; i++) {
ILogicalExpression exprLeft = exprsLeft.get(i).getValue();
LogicalVariable left = variablesLeft.get(i);
for (int j = 0; j < size; j++) {
ILogicalExpression exprRight = copyExpressionAndSubtituteVars(exprsRight.get(j)).getValue();
LogicalVariable right = variablesRight.get(j);
if (exprLeft.equals(exprRight) && !matchedRightVars.contains(right)) {
variableMapping.put(right, left);
// The added variable will not be considered in next rounds.
matchedRightVars.add(right);
break;
}
}
}
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.
the class IsomorphismVariableMappingVisitor method mapVarExprPairList.
private void mapVarExprPairList(List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> leftPairs, List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> rightPairs) {
if (leftPairs.size() != rightPairs.size()) {
return;
}
for (int i = 0; i < leftPairs.size(); i++) {
ILogicalExpression exprLeft = leftPairs.get(i).second.getValue();
LogicalVariable leftVar = leftPairs.get(i).first;
for (int j = 0; j < leftPairs.size(); j++) {
ILogicalExpression exprRight = copyExpressionAndSubtituteVars(rightPairs.get(j).second).getValue();
if (exprLeft.equals(exprRight)) {
LogicalVariable rightVar = rightPairs.get(j).first;
if (rightVar != null && leftVar != null) {
variableMapping.put(rightVar, leftVar);
}
break;
}
}
}
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.
the class IsomorphismVariableMappingVisitor method mapVariablesForGroupBy.
private void mapVariablesForGroupBy(ILogicalOperator left, ILogicalOperator right) throws AlgebricksException {
if (left.getOperatorTag() != right.getOperatorTag()) {
return;
}
GroupByOperator leftOp = (GroupByOperator) left;
GroupByOperator rightOp = (GroupByOperator) right;
List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> leftPairs = leftOp.getGroupByList();
List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> rightPairs = rightOp.getGroupByList();
mapVarExprPairList(leftPairs, rightPairs);
leftPairs = leftOp.getDecorList();
rightPairs = rightOp.getDecorList();
mapVarExprPairList(leftPairs, rightPairs);
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression 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;
}
}
}
Aggregations