Search in sources :

Example 1 with OSQLFilter

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;
}
Also used : OSQLFilter(com.orientechnologies.orient.core.sql.filter.OSQLFilter) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OException(com.orientechnologies.common.exception.OException) OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) OTransactionException(com.orientechnologies.orient.core.exception.OTransactionException) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ParseException(com.orientechnologies.orient.core.sql.parser.ParseException) ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException)

Example 2 with OSQLFilter

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;
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ORecord(com.orientechnologies.orient.core.record.ORecord) OSQLFilter(com.orientechnologies.orient.core.sql.filter.OSQLFilter) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 3 with OSQLFilter

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;
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OSQLFilter(com.orientechnologies.orient.core.sql.filter.OSQLFilter) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OSQLFilter (com.orientechnologies.orient.core.sql.filter.OSQLFilter)3 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)1 OException (com.orientechnologies.common.exception.OException)1 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)1 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)1 OTransactionException (com.orientechnologies.orient.core.exception.OTransactionException)1 ORecord (com.orientechnologies.orient.core.record.ORecord)1 OCommandSQLParsingException (com.orientechnologies.orient.core.sql.OCommandSQLParsingException)1 ParseException (com.orientechnologies.orient.core.sql.parser.ParseException)1 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)1