Skip to content

Commit cb7b290

Browse files
committed
* Add debug console output to watch response from query for top-level output.
* Better handling for no specification of outputs in query call. * Add tests for top-level query output. The top-level output may be being mangled through the OpenAPI stack. Need to investigate.
1 parent 8057e81 commit cb7b290

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

client/src/sdk/LocalConnection.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@ class LocalConnection extends Connection {
234234
action.source.type = 'Source'
235235

236236
action.outputs = []
237-
action.outputs.push(params.out)
237+
if (params.out != null) {
238+
action.outputs.push(params.out)
239+
}
238240

239241
action.source.name = params.name || 'query'
240242
action.source.path = params.path || ''
@@ -249,6 +251,14 @@ class LocalConnection extends Connection {
249251

250252
this.runAction(action, txnParams)
251253
.then(res => {
254+
// TODO(PR): remove
255+
// Compare the raw response.text with the OpenAPI-deserialized
256+
// TransactionResult to look at the top-level output. The expected
257+
// values appear correct in the response, but we run into AnyType
258+
// types in the TransactionResult top-level output.
259+
console.dir(JSON.parse(res.response.text));
260+
console.dir(res.transactionResult);
261+
252262
const tr = res.transactionResult;
253263
const txn_output = tr.output;
254264
const query_output = tr.actions[0].result.output;

client/test/sdk/LocalConnection.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,48 @@ describe('LocalConnection', () => {
199199
})
200200
})
201201

202+
describe('#top-level query output', () => {
203+
it(`def output = 2`, () => {
204+
return defaultConnection.query({
205+
query: 'def output = 2',
206+
}).then(res => {
207+
assert(res.txn_output[0].columns[0][0] === 2);
208+
});
209+
})
210+
it(`def output = {(1,); (2,); (3,)}`, () => {
211+
return defaultConnection.query({
212+
query: 'def output = {(1,); (2,); (3,)}',
213+
}).then(res => {
214+
assert(setsEqual(new Set(res.txn_output[0].columns[0]), new Set([1,2,3])));
215+
});
216+
})
217+
it(`def output = {(1.1,); (2.2,); (3.4,)}`, () => {
218+
return defaultConnection.query({
219+
query: 'def output = {(1.1,); (2.2,); (3.4,)}',
220+
}).then(res => {
221+
assert(setsEqual(new Set(res.txn_output[0].columns[0]), new Set([1.1,2.2,3.4])));
222+
});
223+
})
224+
it(`def output = {(parse_decimal[64, 2, \"1.1\"],); (parse_decimal[64, 2, \"2.2\"],); (parse_decimal[64, 2, \"3.4\"],)}`, () => {
225+
return defaultConnection.query({
226+
query: 'def output = {(parse_decimal[64, 2, \"1.1\"],); (parse_decimal[64, 2, \"2.2\"],); (parse_decimal[64, 2, \"3.4\"],)}',
227+
}).then(res => {
228+
assert(setsEqual(new Set(res.txn_output[0].columns[0]), new Set([1.1,2.2,3.4])));
229+
});
230+
})
231+
it(`def output = {(1, 5); (2, 7); (3, 9)}`, () => {
232+
return defaultConnection.query({
233+
query: 'def output = {(1, 5); (2, 7); (3, 9)}',
234+
}).then(res => {
235+
let success = [];
236+
success = [[1,2,3],[5,7,9]].map((X,i) => {
237+
return setsEqual(new Set(X), new Set(res.txn_output[0].columns[i]));
238+
});
239+
assert.deepStrictEqual(success, [true, true]);
240+
});
241+
})
242+
})
243+
202244
describe('#list_edb', () => {
203245
it(`create_database() should execute without error`, () => {
204246
defaultConnection.defaultOpenMode = 'CREATE_OVERWRITE'

0 commit comments

Comments
 (0)