Skip to content

Commit

Permalink
refactor: removed legacy query engine usages in eval and etl
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Dec 19, 2024
1 parent 63e81f4 commit e5c77c1
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ public Object eval(final String iExpression, OCommandContext context) {
if (context == null) {
context = new OBasicCommandContext();
}
return OSQLEngine.parseExpression(iExpression).execute(this, context);
return OSQLEngine.eval(iExpression, this, context);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ public static Optional<OOrBlock> maybeParsePredicate(String predicate)
}
}

public static Object eval(String expression, Object target, OCommandContext ctx) {
Optional<OOrBlock> predicate = maybeParsePredicate(expression);
if (predicate.isPresent()) {
return predicate.get().evaluate(target, ctx);
} else {
return parseExpression(expression).execute((OIdentifiable) target, ctx);
}
}

public static OExpression parseExpression(String predicate) throws OCommandSQLParsingException {
final InputStream is = new ByteArrayInputStream(predicate.getBytes());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.orientechnologies.orient.core.exception.OConfigurationException;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.OSQLEngine;
import com.orientechnologies.orient.core.sql.filter.OSQLFilter;
import com.orientechnologies.orient.core.sql.parser.OOrBlock;
import com.orientechnologies.orient.etl.context.OETLContext;

/** ETL abstract component. */
Expand Down Expand Up @@ -92,14 +92,14 @@ public String toString() {
}

protected boolean skip(final Object input) {
final OSQLFilter ifFilter = getIfFilter();
final OOrBlock ifFilter = getIfFilter();
if (ifFilter != null) {
final ODocument doc =
input instanceof OIdentifiable ? (ODocument) ((OIdentifiable) input).getRecord() : null;

debug("Evaluating conditional expression if=%s...", ifFilter);

final Object result = ifFilter.evaluate(doc, null, context);
final Object result = ifFilter.evaluate(doc, context);
if (!(result instanceof Boolean))
throw new OConfigurationException(
"'if' expression in Transformer "
Expand All @@ -113,8 +113,8 @@ protected boolean skip(final Object input) {
return false;
}

protected OSQLFilter getIfFilter() {
if (ifExpression != null) return new OSQLFilter(ifExpression, context, null);
protected OOrBlock getIfFilter() {
if (ifExpression != null) return OSQLEngine.parsePredicate(ifExpression);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@

import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.filter.OSQLFilter;
import com.orientechnologies.orient.core.sql.OSQLEngine;
import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.sql.parser.OExpression;

public class OETLLetBlock extends OETLAbstractBlock {
protected String name;
protected OSQLFilter expression;
protected OExpression expression;
protected Object value;

@Override
Expand All @@ -44,7 +46,7 @@ public void configure(final ODocument iConfiguration, final OCommandContext iCon
name = iConfiguration.field("name");
if (iConfiguration.containsField("value")) {
value = iConfiguration.field("value");
} else expression = new OSQLFilter((String) iConfiguration.field("expression"), iContext, null);
} else expression = OSQLEngine.parseExpression(iConfiguration.field("expression"));

if (value == null && expression == null)
throw new IllegalArgumentException(
Expand All @@ -58,7 +60,8 @@ public String getName() {

@Override
public Object executeBlock() {
final Object v = expression != null ? expression.evaluate(null, null, context) : resolve(value);
final Object v =
expression != null ? expression.execute((OResult) null, context) : resolve(value);
context.setVariable(name, v);
return v;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.record.ORecord;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.filter.OSQLFilter;
import com.orientechnologies.orient.core.sql.OSQLEngine;
import com.orientechnologies.orient.core.sql.parser.OExpression;
import java.util.List;

public class OETLFieldTransformer extends OETLAbstractTransformer {
Expand All @@ -32,7 +33,7 @@ public class OETLFieldTransformer extends OETLAbstractTransformer {
private String expression;
private Object value;
private boolean setOperation = true;
private OSQLFilter sqlFilter;
private OExpression sqlFilter;
private boolean save = false;

@Override
Expand Down Expand Up @@ -93,9 +94,9 @@ public Object executeTransform(ODatabaseDocument db, final Object input) {
if (expression != null) {
if (sqlFilter == null)
// ONLY THE FIRST TIME
sqlFilter = new OSQLFilter(expression, context, null);
sqlFilter = OSQLEngine.parseExpression(expression);

newValue = sqlFilter.evaluate(doc, null, context);
newValue = sqlFilter.execute(doc, context);
} else newValue = value;

// SET THE TRANSFORMED FIELD BACK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
import com.orientechnologies.orient.core.sql.OSQLEngine;
import com.orientechnologies.orient.core.sql.executor.OResult;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import com.orientechnologies.orient.core.sql.filter.OSQLPredicate;
import com.orientechnologies.orient.core.storage.OStorage;
import com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage;
import com.orientechnologies.orient.core.util.OURLConnection;
Expand Down Expand Up @@ -1273,7 +1272,9 @@ public void move(

if (currentRecord == null) return;

final Object result = new OSQLPredicate(iText).evaluate(currentRecord, null, null);
final Object result =
OSQLEngine.parseExpression(iText)
.execute(currentRecord, new OBasicCommandContext(currentDatabase));

if (result != null) {
if (result instanceof OIdentifiable) {
Expand All @@ -1300,8 +1301,7 @@ public void eval(

if (currentRecord == null) return;

final Object result =
OSQLEngine.parseExpression(iText).execute(currentRecord, new OBasicCommandContext());
final Object result = OSQLEngine.eval(iText, currentRecord, new OBasicCommandContext());
if (result != null) out.println("\n" + result);
}

Expand Down

0 comments on commit e5c77c1

Please sign in to comment.