use of org.finos.legend.engine.plan.execution.stores.relational.result.VoidRelationalResult in project legend-engine by finos.
the class RelationalExecutor method execute.
public Result execute(RelationalExecutionNode node, MutableList<CommonProfile> profiles, ExecutionState executionState) {
Connection connectionManagerConnection;
String databaseTimeZone = node.getDatabaseTimeZone() == null ? DEFAULT_DB_TIME_ZONE : node.getDatabaseTimeZone();
String databaseTypeName = node.getDatabaseTypeName();
List<String> tempTableList = new FastList<>();
connectionManagerConnection = getConnection(node, profiles, ((RelationalStoreExecutionState) executionState.getStoreExecutionState(StoreType.Relational)));
Span span = GlobalTracer.get().activeSpan();
if (span != null) {
span.log("Connection acquired");
}
this.prepareForSQLExecution(node, connectionManagerConnection, databaseTimeZone, databaseTypeName, tempTableList, profiles, executionState);
if (executionState.inAllocation) {
if ((ExecutionNodeTDSResultHelper.isResultTDS(node) || (ExecutionNodeResultHelper.isResultSizeRangeSet(node) && !ExecutionNodeResultHelper.isSingleRecordResult(node))) && !executionState.transformAllocation) {
return new RelationalResult(executionState.activities, node, node.resultColumns, databaseTypeName, databaseTimeZone, connectionManagerConnection, profiles, tempTableList, executionState.topSpan);
} else if (node.isResultVoid()) {
return new VoidRelationalResult(executionState.activities, connectionManagerConnection, profiles);
} else {
// Refactor and clean up the flush to Constant
RelationalResult result = new RelationalResult(executionState.activities, node, node.resultColumns, databaseTypeName, databaseTimeZone, connectionManagerConnection, profiles, tempTableList, executionState.topSpan);
if (node.isResultPrimitiveType()) {
try {
if (result.resultSet.next()) {
MutableList<Function<Object, Object>> transformers = result.getTransformers();
Object convertedValue = transformers.get(0).valueOf(result.resultSet.getObject(1));
return new ConstantResult(convertedValue);
} else {
throw new RuntimeException("Result set is empty for allocation node");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
} else {
try {
RealizedRelationalResult realizedRelationalResult = (RealizedRelationalResult) result.realizeInMemory();
List<Map<String, Object>> rowValueMaps = realizedRelationalResult.getRowValueMaps(false);
Result res = evaluateAdditionalExtractors(this.resultInterpreterExtensions, executionState, rowValueMaps);
if (res != null) {
return res;
} else if (ExecutionNodeClassResultHelper.isClassResult(node) && rowValueMaps.size() == 1) {
return new ConstantResult(rowValueMaps.get(0));
} else {
return new ConstantResult(rowValueMaps);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
} else if (node.isResultVoid()) {
return new VoidRelationalResult(executionState.activities, connectionManagerConnection, profiles);
} else {
return new RelationalResult(executionState.activities, node, node.resultColumns, databaseTypeName, databaseTimeZone, connectionManagerConnection, profiles, tempTableList, executionState.topSpan);
}
}
use of org.finos.legend.engine.plan.execution.stores.relational.result.VoidRelationalResult in project legend-engine by finos.
the class RelationalExecutor method execute.
public Result execute(SQLExecutionNode node, MutableList<CommonProfile> profiles, ExecutionState executionState) {
Connection connectionManagerConnection;
String databaseTimeZone = node.getDatabaseTimeZone() == null ? DEFAULT_DB_TIME_ZONE : node.getDatabaseTimeZone();
String databaseType = node.getDatabaseTypeName();
List<String> tempTableList = FastList.newList();
Span span = GlobalTracer.get().activeSpan();
connectionManagerConnection = getConnection(node, profiles, (RelationalStoreExecutionState) executionState.getStoreExecutionState(StoreType.Relational));
if (span != null) {
span.log("Connection acquired");
}
this.prepareForSQLExecution(node, connectionManagerConnection, databaseTimeZone, databaseType, tempTableList, profiles, executionState);
if (node.isResultVoid()) {
return new VoidRelationalResult(executionState.activities, connectionManagerConnection, profiles);
}
return new SQLExecutionResult(executionState.activities, node, databaseType, databaseTimeZone, connectionManagerConnection, profiles, tempTableList, executionState.topSpan);
}
Aggregations