use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.
the class Operation method flattenSpecials.
public boolean flattenSpecials(EvalState state, Value val, ExprTreeHolder tree) throws HyracksDataException {
ExprTreeHolder fChild1 = objectPool.mutableExprPool.get();
ExprTreeHolder fChild2 = objectPool.mutableExprPool.get();
ExprTreeHolder fChild3 = objectPool.mutableExprPool.get();
Value eval1 = objectPool.valuePool.get();
Value eval2 = objectPool.valuePool.get();
Value eval3 = objectPool.valuePool.get();
switch(opKind) {
case OpKind_UNARY_PLUS_OP:
case OpKind_UNARY_MINUS_OP:
case OpKind_PARENTHESES_OP:
case OpKind_LOGICAL_NOT_OP:
case OpKind_BITWISE_NOT_OP:
if (!child1.publicFlatten(state, eval1, fChild1)) {
tree.setInnerTree(null);
return false;
}
if (fChild1.getInnerTree() != null) {
tree.setInnerTree(Operation.createOperation(opKind, fChild1, objectPool));
return (tree.getInnerTree() != null);
} else {
privateDoOperation(opKind, eval1, null, null, true, false, false, val, objectPool);
tree.setInnerTree(null);
eval1.setUndefinedValue();
return true;
}
case OpKind_TERNARY_OP:
// Flatten the selector expression
if (!child1.publicFlatten(state, eval1, fChild1)) {
tree.setInnerTree(null);
return false;
}
// check if selector expression collapsed to a non-undefined value
if (fChild1.getInnerTree() == null && !eval1.isUndefinedValue()) {
MutableBoolean b = objectPool.boolPool.get();
// if the selector is not boolean-equivalent, propagate error
if (!eval1.isBooleanValueEquiv(b)) {
val.setErrorValue();
eval1.setUndefinedValue();
tree.setInnerTree(null);
return true;
}
// eval1 is either a real or an integer
if (b.booleanValue()) {
return child2.publicFlatten(state, val, tree);
} else {
return child3.publicFlatten(state, val, tree);
}
} else {
// Flatten arms of the if expression
if (!child2.publicFlatten(state, eval2, fChild2) || !child3.publicFlatten(state, eval3, fChild3)) {
// clean up
tree.setInnerTree(null);
return false;
}
// if any arm collapsed into a value, make it a Literal
if (fChild2.getInnerTree() == null) {
fChild2.setInnerTree(Literal.createLiteral(eval2, objectPool));
}
if (fChild3.getInnerTree() == null) {
fChild3.setInnerTree(Literal.createLiteral(eval3, objectPool));
}
if (fChild2.getInnerTree() == null || fChild3.getInnerTree() == null) {
tree.setInnerTree(null);
;
return false;
}
// fChild1 may be NULL if child1 Flattened to UNDEFINED
if (fChild1.getInnerTree() == null) {
fChild1.setInnerTree(child1.copy());
}
tree.setInnerTree(Operation.createOperation(opKind, fChild1, fChild2, fChild3, objectPool));
if (tree.getInnerTree() == null) {
return false;
}
return true;
}
case OpKind_SUBSCRIPT_OP:
// Flatten both arguments
if (!child1.publicFlatten(state, eval1, fChild1) || !child2.publicFlatten(state, eval2, fChild2)) {
tree.setInnerTree(null);
return false;
}
// if both arguments Flattened to values, Evaluate now
if (fChild1.getInnerTree() == null && fChild2.getInnerTree() == null) {
privateDoOperation(opKind, eval1, eval2, null, true, true, false, val, objectPool);
tree.setInnerTree(null);
return true;
}
// otherwise convert Flattened values into literals
if (fChild1.getInnerTree() == null) {
fChild1.setInnerTree(Literal.createLiteral(eval1, objectPool));
}
if (fChild2.getInnerTree() == null) {
fChild2.setInnerTree(Literal.createLiteral(eval2, objectPool));
}
if (fChild1.getInnerTree() == null || fChild2.getInnerTree() == null) {
tree.setInnerTree(null);
return false;
}
tree.setInnerTree(Operation.createOperation(opKind, fChild1, fChild2, objectPool));
if (tree.getInnerTree() == null) {
return false;
}
return true;
default:
throw new HyracksDataException("Should not get here");
}
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.
the class ExprTree method debugFormatValue.
public void debugFormatValue(Value value, double time) throws HyracksDataException {
MutableBoolean boolValue = objectPool.boolPool.get();
AMutableInt64 intValue = objectPool.int64Pool.get();
AMutableDouble doubleValue = objectPool.doublePool.get();
AMutableCharArrayString stringValue = objectPool.strPool.get();
if (NodeKind.CLASSAD_NODE == getKind()) {
return;
}
PrettyPrint unp = objectPool.prettyPrintPool.get();
AMutableCharArrayString buffer = objectPool.strPool.get();
unp.unparse(buffer, this);
String result = "Classad debug: ";
if (time != 0) {
String buf = String.format("%5.5fms", time * 1000);
result += "[";
result += buf;
result += "] ";
}
result += buffer;
result += " --> ";
switch(value.getType()) {
case NULL_VALUE:
result += "NULL\n";
break;
case ERROR_VALUE:
if ((NodeKind.FN_CALL_NODE == getKind()) && !((FunctionCall) (this)).functionIsDefined()) {
result += "ERROR (function is not defined)\n";
} else {
result += "ERROR\n";
}
break;
case UNDEFINED_VALUE:
result += "UNDEFINED\n";
break;
case BOOLEAN_VALUE:
if (value.isBooleanValue(boolValue)) {
result += boolValue.booleanValue() ? "TRUE\n" : "FALSE\n";
}
break;
case INTEGER_VALUE:
if (value.isIntegerValue(intValue)) {
result += String.format("%lld", intValue.getLongValue());
result += "\n";
}
break;
case REAL_VALUE:
if (value.isRealValue(doubleValue)) {
result += String.format("%lld", doubleValue.getDoubleValue());
result += "\n";
}
break;
case RELATIVE_TIME_VALUE:
result += "RELATIVE TIME\n";
break;
case ABSOLUTE_TIME_VALUE:
result += "ABSOLUTE TIME\n";
break;
case STRING_VALUE:
if (value.isStringValue(stringValue)) {
result += stringValue.toString();
result += "\n";
}
break;
case CLASSAD_VALUE:
result += "CLASSAD\n";
break;
case LIST_VALUE:
result += "LIST\n";
break;
case SLIST_VALUE:
result += "SLIST\n";
break;
}
debugPrint(result);
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project apex-malhar by apache.
the class SimpleDoneQueryQueueManagerTest method resetPermitsTest.
@Test
public void resetPermitsTest() throws Exception {
SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>();
sdqqm.setup(null);
sdqqm.beginWindow(0);
Query query = new MockQuery("1");
sdqqm.enqueue(query, null, new MutableBoolean(false));
Assert.assertEquals(1, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
QueryBundle<Query, Void, MutableBoolean> qb = sdqqm.dequeueBlock();
Assert.assertEquals(0, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
sdqqm.endWindow();
sdqqm.beginWindow(1);
Assert.assertEquals(1, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
qb = sdqqm.dequeueBlock();
Assert.assertEquals(0, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
testBlocking(sdqqm);
sdqqm.endWindow();
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project apex-malhar by apache.
the class SimpleDoneQueryQueueManagerTest method firstDoneTest.
@Test
public void firstDoneTest() {
SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>();
sdqqm.setup(null);
sdqqm.beginWindow(0);
Query query = new MockQuery("1");
sdqqm.enqueue(query, null, new MutableBoolean(true));
QueryBundle<Query, Void, MutableBoolean> qb = sdqqm.dequeue();
Assert.assertEquals("Should return back null.", null, qb);
sdqqm.endWindow();
sdqqm.beginWindow(1);
qb = sdqqm.dequeue();
Assert.assertEquals("Should return back null.", null, qb);
qb = sdqqm.dequeue();
Assert.assertEquals("Should return back null.", null, qb);
sdqqm.endWindow();
sdqqm.teardown();
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project apex-malhar by apache.
the class SimpleDoneQueryQueueManagerTest method expiredTestBlockingExpiredFirstValidLast.
@Test
public void expiredTestBlockingExpiredFirstValidLast() throws Exception {
SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>();
sdqqm.setup(null);
sdqqm.beginWindow(0);
Query query = new MockQuery("1");
MutableBoolean queueContext = new MutableBoolean(false);
sdqqm.enqueue(query, null, queueContext);
Query query1 = new MockQuery("2");
MutableBoolean queueContext1 = new MutableBoolean(false);
sdqqm.enqueue(query1, null, queueContext1);
Assert.assertEquals(2, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
QueryBundle<Query, Void, MutableBoolean> qb = sdqqm.dequeueBlock();
Assert.assertEquals(1, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
sdqqm.endWindow();
sdqqm.beginWindow(1);
Assert.assertEquals(2, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
queueContext.setValue(true);
qb = sdqqm.dequeueBlock();
Assert.assertEquals(0, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
testBlocking(sdqqm);
sdqqm.endWindow();
sdqqm.beginWindow(2);
Assert.assertEquals(1, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
qb = sdqqm.dequeueBlock();
testBlocking(sdqqm);
sdqqm.endWindow();
sdqqm.teardown();
}
Aggregations