Support new SQL executor in ETL command transformer (with a flag, disabled by default for backward compatibility)
@@ -25,15 +25,21 @@ import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.record.OElement;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.OCommandSQL;
+import com.orientechnologies.orient.core.sql.executor.OResult;
+import com.orientechnologies.orient.core.sql.executor.OResultSet;
+import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
/**
* Executes a command.
*/
public class OETLCommandTransformer extends OETLAbstractTransformer {
private String language = "sql";
+ private boolean newSqlExecutor = false;
private String command;
private boolean returnInput = false;
@@ -53,6 +59,7 @@ public class OETLCommandTransformer extends OETLAbstractTransformer {
command = conf.field("command");
returnInput = Boolean.TRUE.equals(conf.field("returnInput"));
+ newSqlExecutor = Boolean.TRUE.equals(conf.field("newSqlExecutor"));
}
@Override
@@ -64,6 +71,25 @@ public class OETLCommandTransformer extends OETLAbstractTransformer {
public Object executeTransform(ODatabaseDocument db, Object input) {
String runtimeCommand = (String) resolve(command);
+ if (newSqlExecutor) {
+ OResultSet result;
+ if (language.equals("sql")) {
+ result = db.command(runtimeCommand);
+ } else {
+ result = db.execute(language, runtimeCommand);
+ }
+ List<OElement> finalResult = result.stream().map(x -> x.toElement()).collect(Collectors.toList());
+ result.close();
+
+ if (returnInput) {
+ if (input instanceof OElement) {
+ input = db.reload(((OElement) input).getRecord(), null, true);
+ }
+ return input;
+ } else {
+ return finalResult;
+ }
+ } else {
final OCommandRequest cmd;
if (language.equals("sql")) {
cmd = new OCommandSQL(runtimeCommand);
@@ -72,7 +98,6 @@ public class OETLCommandTransformer extends OETLAbstractTransformer {
}
cmd.setContext(context);
try {
-
Object result = db.command(cmd).execute();
log(Level.FINE, "input=%s - command=%s - result=%s", input, cmd, result);
@@ -92,5 +117,6 @@ public class OETLCommandTransformer extends OETLAbstractTransformer {
throw e;
}
}
+ }
}
