mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(redshift-data): return QueryParameters in DescribeStatement and ListStatements (#6461)
- Store and return QueryParameters in DescribeStatement and ListStatements - Extract putQueryParameters helper to deduplicate JSON response building - Add unit tests for statement store serialization and service response - Add SDK compatibility test for parameterized statement binding
This commit is contained in:
1 parent
40b6bfc204
commit
217929bd65
5 files changed
+99
No files matched your search
+25
@@ -16,6 +16,8 @@ import io.github.hectorvent.floci.services.redshift.spectrum.SpectrumQueryPrepar
|
||||
import io.github.hectorvent.floci.services.redshift.spectrum.SpectrumReadException;
|
||||
import io.github.hectorvent.floci.services.redshift.spectrum.SpectrumSession;
|
||||
import io.github.hectorvent.floci.services.redshift.spectrum.SpectrumSqlException;
|
||||
import io.github.hectorvent.floci.services.redshiftdata.RedshiftDataStatementStore.StoredParameter;
|
||||
import io.github.hectorvent.floci.services.redshiftdata.RedshiftDataStatementStore.StoredStatement;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
@@ -380,6 +382,11 @@ public class RedshiftDataService implements Resettable {
|
||||
stored.dbUser = target.user();
|
||||
stored.database = target.database();
|
||||
stored.resultFormat = request.path("ResultFormat").asText("JSON");
|
||||
if (!parameters.isEmpty()) {
|
||||
stored.queryParameters = parameters.entrySet().stream()
|
||||
.map(entry -> new StoredParameter(entry.getKey(), entry.getValue()))
|
||||
.toList();
|
||||
}
|
||||
capture(stored, target, region, request);
|
||||
|
||||
return new PendingStatement(stored, (execution, session) -> runStatement(stored, target, sql, parameters, execution, session),
|
||||
@@ -646,6 +653,7 @@ public class RedshiftDataService implements Resettable {
|
||||
response.put("Error", stored.error);
|
||||
}
|
||||
response.put("QueryString", stored.sql);
|
||||
putQueryParameters(response, stored.queryParameters);
|
||||
int stableId = stored.id.hashCode() & Integer.MAX_VALUE;
|
||||
response.put("RedshiftPid", stableId);
|
||||
response.put("RedshiftQueryId", (long) stableId);
|
||||
@@ -945,6 +953,7 @@ public class RedshiftDataService implements Resettable {
|
||||
node.put("StatementName", s.statementName);
|
||||
}
|
||||
node.put("IsBatchStatement", s.batch);
|
||||
putQueryParameters(node, s.queryParameters);
|
||||
node.put("ResultRows", s.resultRows);
|
||||
node.put("ResultSize", s.resultSize);
|
||||
node.put("Duration", s.durationNanos);
|
||||
@@ -1229,6 +1238,22 @@ public class RedshiftDataService implements Resettable {
|
||||
}
|
||||
}
|
||||
|
||||
private static void putQueryParameters(ObjectNode target, List<StoredParameter> parameters) {
|
||||
if (parameters == null || parameters.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ArrayNode queryParameters = target.putArray("QueryParameters");
|
||||
for (StoredParameter parameter : parameters) {
|
||||
ObjectNode paramNode = queryParameters.addObject();
|
||||
paramNode.put("name", parameter.name());
|
||||
if (parameter.value() == null) {
|
||||
paramNode.putNull("value");
|
||||
} else {
|
||||
paramNode.put("value", parameter.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String requiredText(JsonNode request, String name) {
|
||||
String value = textOrNull(request, name);
|
||||
if (value == null || value.isBlank()) {
|
||||
|
||||
+7
@@ -162,6 +162,11 @@ class RedshiftDataStatementStore {
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
|
||||
record StoredParameter(String name, String value) {
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
|
||||
static final class StoredStatement {
|
||||
@@ -188,6 +193,7 @@ class RedshiftDataStatementStore {
|
||||
ArrayNode columnMetadata;
|
||||
List<ArrayNode> rows;
|
||||
List<StoredStatement> subStatements;
|
||||
List<StoredParameter> queryParameters;
|
||||
String accountId;
|
||||
String region;
|
||||
String resourceArn;
|
||||
@@ -229,6 +235,7 @@ class RedshiftDataStatementStore {
|
||||
copy.hasResultSet = hasResultSet;
|
||||
copy.resultRows = resultRows;
|
||||
copy.resultSize = resultSize;
|
||||
copy.queryParameters = queryParameters == null ? null : List.copyOf(queryParameters);
|
||||
if (withResults) {
|
||||
copy.columnMetadata = columnMetadata;
|
||||
copy.rows = rows == null ? null : List.copyOf(rows);
|
||||
|
||||
Reference in new issue
Block a user