use of com.orientechnologies.orient.core.sql.filter.OSQLFilter in project orientdb by orientechnologies.
the class OCommandExecutorScript method evaluateIfCondition.
private boolean evaluateIfCondition(String lastCommand) {
String cmd = lastCommand;
// remove IF
cmd = cmd.trim().substring(2);
// remove {
cmd = cmd.trim().substring(0, cmd.trim().length() - 1);
OSQLFilter condition = OSQLEngine.getInstance().parseCondition(cmd, getContext(), "IF");
Object result = null;
try {
result = condition.evaluate(null, null, getContext());
} catch (Exception e) {
throw new OCommandExecutionException("Could not evaluate IF condition: " + cmd + " - " + e.getMessage());
}
if (Boolean.TRUE.equals(result)) {
return true;
}
return false;
}
use of com.orientechnologies.orient.core.sql.filter.OSQLFilter in project orientdb by orientechnologies.
the class OFieldTransformer method executeTransform.
@Override
public Object executeTransform(final Object input) {
if (input instanceof OIdentifiable) {
final ORecord rec = ((OIdentifiable) input).getRecord();
if (rec instanceof ODocument) {
final ODocument doc = (ODocument) rec;
if (setOperation) {
final Object newValue;
if (expression != null) {
if (sqlFilter == null)
// ONLY THE FIRST TIME
sqlFilter = new OSQLFilter(expression, context, null);
newValue = sqlFilter.evaluate(doc, null, context);
} else
newValue = value;
// SET THE TRANSFORMED FIELD BACK
doc.field(fieldName, newValue);
log(OETLProcessor.LOG_LEVELS.DEBUG, "set %s=%s in document=%s", fieldName, newValue, doc);
} else {
if (fieldName != null) {
final Object prev = doc.removeField(fieldName);
log(OETLProcessor.LOG_LEVELS.DEBUG, "removed %s (value=%s) from document=%s", fieldName, prev, doc);
} else {
for (String f : fieldNames) {
final Object prev = doc.removeField(f);
log(OETLProcessor.LOG_LEVELS.DEBUG, "removed %s (value=%s) from document=%s", f, prev, doc);
}
}
}
if (save) {
log(OETLProcessor.LOG_LEVELS.DEBUG, "saving record %s", doc);
final ODatabaseDocument db = super.pipeline.getDocumentDatabase();
db.save(doc);
}
}
}
return input;
}
use of com.orientechnologies.orient.core.sql.filter.OSQLFilter in project orientdb by orientechnologies.
the class OAbstractETLComponent method skip.
protected boolean skip(final Object input) {
final OSQLFilter ifFilter = getIfFilter();
if (ifFilter != null) {
final ODocument doc = input instanceof OIdentifiable ? (ODocument) ((OIdentifiable) input).getRecord() : null;
log(LOG_LEVELS.DEBUG, "Evaluating conditional expression if=%s...", ifFilter);
final Object result = ifFilter.evaluate(doc, null, context);
if (!(result instanceof Boolean))
throw new OConfigurationException("'if' expression in Transformer " + getName() + " returned '" + result + "' instead of boolean");
return !(Boolean) result;
}
return false;
}
Aggregations