use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.
the class ClassAdUnitTester method testValue.
/*********************************************************************
* Function: test_value
* Purpose: Test the Value class.
*
* @throws HyracksDataException
*********************************************************************/
public static void testValue(Parameters parameters, Results results, ClassAdObjectPool objectPool) throws HyracksDataException {
Value v = new Value(objectPool);
boolean isExpectedType;
System.out.println("Testing the Value class...");
test("New value is undefined", (v.isUndefinedValue()), "test_value 1", results);
test("New value isn't boolean", !(v.isBooleanValue()), "test_value 2", results);
test("GetType gives UNDEFINED_VALUE", (v.getType() == ValueType.UNDEFINED_VALUE), "test_value 3", results);
v.setErrorValue();
test("Is error value", (v.isErrorValue()), "test_value 4", results);
test("GetType gives ERROR_VALUE", (v.getType() == ValueType.ERROR_VALUE), "test_value 5", results);
MutableBoolean b = new MutableBoolean();
v.setBooleanValue(true);
isExpectedType = v.isBooleanValue(b);
test("Value is not undefined", !(v.isUndefinedValue()), "Value is not undefined", results);
test("Value is boolean", (v.isBooleanValue()), "Value is boolean", results);
test("Try 2: New value is boolean", (isExpectedType == true), "Try 2: New value is boolean", results);
test("Boolean is true", (b.booleanValue() == true), "Boolean is true", results);
test("GetType gives BOOLEAN_VALUE", (v.getType() == ValueType.BOOLEAN_VALUE), "GetType gives BOOLEAN_VALUE", results);
AMutableDouble r = new AMutableDouble(0.0);
v.setRealValue(1.0);
isExpectedType = v.isRealValue(r);
test("Value is real", isExpectedType, results);
test("Real is 1.0", (r.getDoubleValue() == 1.0), results);
test("GetType gives REAL_VALUE", (v.getType() == ValueType.REAL_VALUE), results);
test("Real is a number", v.isNumber(), results);
AMutableInt64 i = new AMutableInt64(0);
v.setIntegerValue(1);
isExpectedType = v.isIntegerValue(i);
test("Value is integer", isExpectedType, results);
test("Integer is 1", (i.getLongValue() == 1), results);
test("GetType gives INTEGER_VALUE", (v.getType() == ValueType.INTEGER_VALUE), results);
test("Integer is a number", v.isNumber(), results);
AMutableCharArrayString s = new AMutableCharArrayString();
v.setStringValue("Robert-Houdin");
isExpectedType = v.isStringValue(s);
test("Value is String", isExpectedType, results);
test("String is 'Robert-Houdin'", (0 == s.compareTo("Robert-Houdin")), results);
test("GetType gives STRING_VALUE", (v.getType() == ValueType.STRING_VALUE), results);
ClassAdTime at = new ClassAdTime(10, 36000000);
v.setAbsoluteTimeValue(at);
at.setValue(0);
at.setTimeZone(0);
isExpectedType = v.isAbsoluteTimeValue(at);
test("Value is absolute time", isExpectedType, results);
test("Absolute time is 10, 0", (10 == at.getTime() && 36000000 == at.getOffset()), results);
test("GetType gives ABSOLUTE_TIME_VALUE", (v.getType() == ValueType.ABSOLUTE_TIME_VALUE), results);
ClassAdTime rt = new ClassAdTime(10, false);
v.setRelativeTimeValue(10);
isExpectedType = v.isRelativeTimeValue(rt);
test("Value is relative time", isExpectedType, results);
test("Relative time is 10", (10 == rt.getRelativeTime()), results);
test("GetType gives RELATIVE_TIME_VALUE", (v.getType() == ValueType.RELATIVE_TIME_VALUE), results);
ExprList l = new ExprList(objectPool);
ExprList ll = new ExprList(objectPool);
v.setListValue(l);
isExpectedType = v.isListValue(ll);
test("Value is list value", isExpectedType, results);
test("List value is correct", l.equals(ll), results);
test("GetType gives LIST_VALUE", (v.getType() == ValueType.LIST_VALUE), results);
ExprList sl = new ExprList(true, objectPool);
ll = new ExprList(true, objectPool);
v.setListValue(sl);
isExpectedType = v.isListValue(ll);
test("Value is list value", isExpectedType, results);
test("List value is correct", sl.equals(ll), results);
test("GetType gives SLIST_VALUE", (v.getType() == ValueType.SLIST_VALUE), results);
ClassAd c = new ClassAd(objectPool);
c.insertAttr("test_int", 10);
ClassAd cc = new ClassAd(objectPool);
v.setClassAdValue(c);
isExpectedType = v.isClassAdValue(cc);
test("Value is ClassAd value", isExpectedType, results);
test("ClassAd value is correct", c.equals(cc), results);
test("GetType gives CLASSAD_VALUE", (v.getType() == ValueType.CLASSAD_VALUE), results);
return;
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.
the class Operation method privateDoOperation.
public static int privateDoOperation(int op, Value val1, Value val2, Value val3, boolean valid1, boolean valid2, boolean valid3, Value result, EvalState es, ClassAdObjectPool objectPool) throws HyracksDataException {
ValueType vt1;
ValueType vt2;
ValueType vt3;
// get the types of the values
vt1 = val1.getType();
vt2 = val2.getType();
vt3 = val3.getType();
// take care of the easy cases
if (op == OpKind_NO_OP || op == OpKind_PARENTHESES_OP) {
result.setValue(val1);
return SigValues.SIG_CHLD1.ordinal();
} else if (op == OpKind_UNARY_PLUS_OP) {
if (vt1 == ValueType.BOOLEAN_VALUE || vt1 == ValueType.STRING_VALUE || val1.isListValue() || vt1 == ValueType.CLASSAD_VALUE || vt1 == ValueType.ABSOLUTE_TIME_VALUE) {
result.setErrorValue();
} else {
// applies for ERROR, UNDEFINED and Numbers
result.setValue(val1);
}
return SigValues.SIG_CHLD1.ordinal();
}
// test for cases when evaluation is strict
if (isStrictOperator(op)) {
// check for error values
if (vt1 == ValueType.ERROR_VALUE) {
result.setErrorValue();
return SigValues.SIG_CHLD1.ordinal();
}
if (valid2 && vt2 == ValueType.ERROR_VALUE) {
result.setErrorValue();
return SigValues.SIG_CHLD2.ordinal();
}
if (valid3 && vt3 == ValueType.ERROR_VALUE) {
result.setErrorValue();
return SigValues.SIG_CHLD3.ordinal();
}
// tree exists, because these values would be undefined" anyway then.
if (valid1 && vt1 == ValueType.UNDEFINED_VALUE) {
result.setUndefinedValue();
return SigValues.SIG_CHLD1.ordinal();
}
if (valid2 && vt2 == ValueType.UNDEFINED_VALUE) {
result.setUndefinedValue();
return SigValues.SIG_CHLD2.ordinal();
}
if (valid3 && vt3 == ValueType.UNDEFINED_VALUE) {
result.setUndefinedValue();
return SigValues.SIG_CHLD3.ordinal();
}
}
// comparison operations (binary, one unary)
if (op >= OpKind_COMPARISON_START && op <= OpKind_COMPARISON_END) {
return (doComparison(op, val1, val2, result, objectPool));
}
// arithmetic operations (binary)
if (op >= OpKind_ARITHMETIC_START && op <= OpKind_ARITHMETIC_END) {
return (doArithmetic(op, val1, val2, result, objectPool));
}
// logical operators (binary, one unary)
if (op >= OpKind_LOGIC_START && op <= OpKind_LOGIC_END) {
return (doLogical(op, val1, val2, result, objectPool));
}
// bitwise operators (binary, one unary)
if (op >= OpKind_BITWISE_START && op <= OpKind_BITWISE_END) {
return (doBitwise(op, val1, val2, result, objectPool));
}
// misc.
if (op == OpKind_TERNARY_OP) {
// ternary (if-operator)
MutableBoolean b = objectPool.boolPool.get();
// if the selector is UNDEFINED, the result is undefined
if (vt1 == ValueType.UNDEFINED_VALUE) {
result.setUndefinedValue();
return SigValues.SIG_CHLD1.ordinal();
}
if (!val1.isBooleanValueEquiv(b)) {
result.setErrorValue();
return SigValues.SIG_CHLD1.ordinal();
} else if (b.booleanValue()) {
result.setValue(val2);
return (SigValues.SIG_CHLD2.ordinal());
} else {
result.setValue(val3);
return (SigValues.SIG_CHLD3.ordinal());
}
} else if (op == OpKind_SUBSCRIPT_OP) {
if (vt1 == ValueType.CLASSAD_VALUE && vt2 == ValueType.STRING_VALUE) {
ClassAd classad = objectPool.classAdPool.get();
AMutableCharArrayString index = objectPool.strPool.get();
val1.isClassAdValue(classad);
val2.isStringValue(index);
if (classad.lookup(index.toString()) == null) {
result.setErrorValue();
return SigValues.SIG_CHLD2.ordinal();
}
if (!classad.evaluateAttr(index.toString(), result)) {
result.setErrorValue();
return SigValues.SIG_CHLD2.ordinal();
}
return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
} else if (val1.isListValue() && vt2 == ValueType.INTEGER_VALUE) {
AMutableInt64 index = objectPool.int64Pool.get();
ExprList elist = objectPool.exprListPool.get();
val1.isListValue(elist);
val2.isIntegerValue(index);
// check bounds
if (index.getLongValue() < 0 || index.getLongValue() >= elist.getExprList().size()) {
result.setErrorValue();
return SigValues.SIG_CHLD2.ordinal();
}
// get value
elist.getValue(result, elist.get((int) index.getLongValue()), es);
return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
}
// should not reach here
throw new HyracksDataException("Should not get here");
}
return -1;
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.
the class QueryTranslator method doDropDataset.
public static void doDropDataset(String dataverseName, String datasetName, MetadataProvider metadataProvider, boolean ifExists, IHyracksClientConnection hcc, boolean dropCorrespondingNodeGroup) throws Exception {
MutableObject<ProgressState> progress = new MutableObject<>(ProgressState.NO_PROGRESS);
MutableObject<MetadataTransactionContext> mdTxnCtx = new MutableObject<>(MetadataManager.INSTANCE.beginTransaction());
MutableBoolean bActiveTxn = new MutableBoolean(true);
metadataProvider.setMetadataTxnContext(mdTxnCtx.getValue());
List<JobSpecification> jobsToExecute = new ArrayList<>();
try {
Dataset ds = metadataProvider.findDataset(dataverseName, datasetName);
if (ds == null) {
if (ifExists) {
MetadataManager.INSTANCE.commitTransaction(mdTxnCtx.getValue());
return;
} else {
throw new AlgebricksException("There is no dataset with this name " + datasetName + " in dataverse " + dataverseName + ".");
}
}
ds.drop(metadataProvider, mdTxnCtx, jobsToExecute, bActiveTxn, progress, hcc, dropCorrespondingNodeGroup);
MetadataManager.INSTANCE.commitTransaction(mdTxnCtx.getValue());
} catch (Exception e) {
if (bActiveTxn.booleanValue()) {
abort(e, e, mdTxnCtx.getValue());
}
if (progress.getValue() == ProgressState.ADDED_PENDINGOP_RECORD_TO_METADATA) {
// remove the all indexes in NC
try {
for (JobSpecification jobSpec : jobsToExecute) {
JobUtils.runJob(hcc, jobSpec, true);
}
} catch (Exception e2) {
// do no throw exception since still the metadata needs to be compensated.
e.addSuppressed(e2);
}
// remove the record from the metadata.
mdTxnCtx.setValue(MetadataManager.INSTANCE.beginTransaction());
metadataProvider.setMetadataTxnContext(mdTxnCtx.getValue());
try {
MetadataManager.INSTANCE.dropDataset(metadataProvider.getMetadataTxnContext(), dataverseName, datasetName);
MetadataManager.INSTANCE.commitTransaction(mdTxnCtx.getValue());
} catch (Exception e2) {
e.addSuppressed(e2);
abort(e, e2, mdTxnCtx.getValue());
throw new IllegalStateException("System is inconsistent state: pending dataset(" + dataverseName + "." + datasetName + ") couldn't be removed from the metadata", e);
}
}
throw e;
} finally {
ExternalDatasetsRegistry.INSTANCE.releaseAcquiredLocks(metadataProvider);
}
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.
the class QueryTranslator method deliverResult.
private void deliverResult(IHyracksClientConnection hcc, IHyracksDataset hdc, IStatementCompiler compiler, MetadataProvider metadataProvider, IMetadataLocker locker, ResultDelivery resultDelivery, ResultMetadata outMetadata, Stats stats, String clientContextId, IStatementExecutorContext ctx) throws Exception {
final ResultSetId resultSetId = metadataProvider.getResultSetId();
switch(resultDelivery) {
case ASYNC:
MutableBoolean printed = new MutableBoolean(false);
executorService.submit(() -> asyncCreateAndRunJob(hcc, compiler, locker, resultDelivery, clientContextId, ctx, resultSetId, printed));
synchronized (printed) {
while (!printed.booleanValue()) {
printed.wait();
}
}
break;
case IMMEDIATE:
createAndRunJob(hcc, null, compiler, locker, resultDelivery, id -> {
final ResultReader resultReader = new ResultReader(hdc, id, resultSetId);
ResultUtil.printResults(appCtx, resultReader, sessionOutput, stats, metadataProvider.findOutputRecordType());
}, clientContextId, ctx);
break;
case DEFERRED:
createAndRunJob(hcc, null, compiler, locker, resultDelivery, id -> {
ResultUtil.printResultHandle(sessionOutput, new ResultHandle(id, resultSetId));
if (outMetadata != null) {
outMetadata.getResultSets().add(Triple.of(id, resultSetId, metadataProvider.findOutputRecordType()));
}
}, clientContextId, ctx);
break;
default:
break;
}
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.
the class Dataset method drop.
/**
* Drop this dataset
*
* @param metadataProvider
* metadata provider that can be used to get metadata info and runtimes
* @param mdTxnCtx
* the transaction context
* @param jobsToExecute
* a list of jobs to be executed as part of the drop operation
* @param bActiveTxn
* whether the metadata transaction is ongoing
* @param progress
* a mutable progress state used for error handling during the drop operation
* @param hcc
* a client connection to hyracks master for job execution
* @throws Exception
* if an error occur during the drop process or if the dataset can't be dropped for any reason
*/
public void drop(MetadataProvider metadataProvider, MutableObject<MetadataTransactionContext> mdTxnCtx, List<JobSpecification> jobsToExecute, MutableBoolean bActiveTxn, MutableObject<ProgressState> progress, IHyracksClientConnection hcc, boolean dropCorrespondingNodeGroup) throws Exception {
Map<FeedConnectionId, Pair<JobSpecification, Boolean>> disconnectJobList = new HashMap<>();
if (getDatasetType() == DatasetType.INTERNAL) {
// prepare job spec(s) that would disconnect any active feeds involving the dataset.
ActiveLifecycleListener activeListener = (ActiveLifecycleListener) metadataProvider.getApplicationContext().getActiveLifecycleListener();
IActiveEntityEventsListener[] activeListeners = activeListener.getNotificationHandler().getEventListeners();
for (IActiveEntityEventsListener listener : activeListeners) {
if (listener.isEntityUsingDataset(this)) {
throw new CompilationException(ErrorCode.COMPILATION_CANT_DROP_ACTIVE_DATASET, RecordUtil.toFullyQualifiedName(dataverseName, datasetName), listener.getEntityId().toString());
}
}
// #. prepare jobs to drop the datatset and the indexes in NC
List<Index> indexes = MetadataManager.INSTANCE.getDatasetIndexes(mdTxnCtx.getValue(), dataverseName, datasetName);
for (int j = 0; j < indexes.size(); j++) {
if (indexes.get(j).isSecondaryIndex()) {
jobsToExecute.add(IndexUtil.buildDropIndexJobSpec(indexes.get(j), metadataProvider, this));
}
}
jobsToExecute.add(DatasetUtil.dropDatasetJobSpec(this, metadataProvider));
// #. mark the existing dataset as PendingDropOp
MetadataManager.INSTANCE.dropDataset(mdTxnCtx.getValue(), dataverseName, datasetName);
MetadataManager.INSTANCE.addDataset(mdTxnCtx.getValue(), new Dataset(dataverseName, datasetName, getItemTypeDataverseName(), getItemTypeName(), getMetaItemTypeDataverseName(), getMetaItemTypeName(), getNodeGroupName(), getCompactionPolicy(), getCompactionPolicyProperties(), getDatasetDetails(), getHints(), getDatasetType(), getDatasetId(), MetadataUtil.PENDING_DROP_OP));
MetadataManager.INSTANCE.commitTransaction(mdTxnCtx.getValue());
bActiveTxn.setValue(false);
progress.setValue(ProgressState.ADDED_PENDINGOP_RECORD_TO_METADATA);
// # disconnect the feeds
for (Pair<JobSpecification, Boolean> p : disconnectJobList.values()) {
JobUtils.runJob(hcc, p.first, true);
}
// #. run the jobs
for (JobSpecification jobSpec : jobsToExecute) {
JobUtils.runJob(hcc, jobSpec, true);
}
mdTxnCtx.setValue(MetadataManager.INSTANCE.beginTransaction());
bActiveTxn.setValue(true);
metadataProvider.setMetadataTxnContext(mdTxnCtx.getValue());
} else {
// External dataset
ExternalDatasetsRegistry.INSTANCE.removeDatasetInfo(this);
// #. prepare jobs to drop the datatset and the indexes in NC
List<Index> indexes = MetadataManager.INSTANCE.getDatasetIndexes(mdTxnCtx.getValue(), dataverseName, datasetName);
for (int j = 0; j < indexes.size(); j++) {
if (ExternalIndexingOperations.isFileIndex(indexes.get(j))) {
jobsToExecute.add(IndexUtil.buildDropIndexJobSpec(indexes.get(j), metadataProvider, this));
} else {
jobsToExecute.add(DatasetUtil.buildDropFilesIndexJobSpec(metadataProvider, this));
}
}
// #. mark the existing dataset as PendingDropOp
MetadataManager.INSTANCE.dropDataset(mdTxnCtx.getValue(), dataverseName, datasetName);
MetadataManager.INSTANCE.addDataset(mdTxnCtx.getValue(), new Dataset(dataverseName, datasetName, getItemTypeDataverseName(), getItemTypeName(), getNodeGroupName(), getCompactionPolicy(), getCompactionPolicyProperties(), getDatasetDetails(), getHints(), getDatasetType(), getDatasetId(), MetadataUtil.PENDING_DROP_OP));
MetadataManager.INSTANCE.commitTransaction(mdTxnCtx.getValue());
bActiveTxn.setValue(false);
progress.setValue(ProgressState.ADDED_PENDINGOP_RECORD_TO_METADATA);
// #. run the jobs
for (JobSpecification jobSpec : jobsToExecute) {
JobUtils.runJob(hcc, jobSpec, true);
}
if (!indexes.isEmpty()) {
ExternalDatasetsRegistry.INSTANCE.removeDatasetInfo(this);
}
mdTxnCtx.setValue(MetadataManager.INSTANCE.beginTransaction());
bActiveTxn.setValue(true);
metadataProvider.setMetadataTxnContext(mdTxnCtx.getValue());
}
// #. finally, delete the dataset.
MetadataManager.INSTANCE.dropDataset(mdTxnCtx.getValue(), dataverseName, datasetName);
// Drops the associated nodegroup if it is no longer used by any other dataset.
if (dropCorrespondingNodeGroup) {
MetadataLockManager.INSTANCE.acquireNodeGroupWriteLock(metadataProvider.getLocks(), nodeGroupName);
MetadataManager.INSTANCE.dropNodegroup(mdTxnCtx.getValue(), nodeGroupName, true);
}
}
Aggregations