From c62584c861b36516410f41dd8ba426b17f27497a Mon Sep 17 00:00:00 2001 From: surbhigarg92 Date: Thu, 11 Jan 2024 15:17:16 +0530 Subject: [PATCH 1/2] chore: integration test fix --- system-test/spanner.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system-test/spanner.ts b/system-test/spanner.ts index d2bde030f..5575d5c5f 100644 --- a/system-test/spanner.ts +++ b/system-test/spanner.ts @@ -8731,10 +8731,10 @@ describe('Spanner', () => { }, err => { assert.strictEqual(err?.details, expectedErrorMessage); + transaction!.end(); + done(); } ); - transaction!.end(); - done(); }); }); }); From 1ee36d9e4e495afbf030f9b6751260dd40b633e0 Mon Sep 17 00:00:00 2001 From: surbhigarg92 Date: Mon, 4 Mar 2024 14:45:31 +0530 Subject: [PATCH 2/2] fix: untyped string array type --- src/codec.ts | 9 +++++++-- system-test/spanner.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/codec.ts b/src/codec.ts index 663a76873..6910cad6d 100644 --- a/src/codec.ts +++ b/src/codec.ts @@ -589,6 +589,7 @@ interface FieldType extends Type { * @private * * @param {*} value - The value. + * @param {boolean} isArrayValue - If the value is for an array type. * @returns {object} * * @example @@ -597,7 +598,7 @@ interface FieldType extends Type { * // {type: 'float64'} * ``` */ -function getType(value: Value): Type { +function getType(value: Value, isArrayValue = false): Type { const isSpecialNumber = is.infinite(value) || (is.number(value) && isNaN(value)); @@ -629,6 +630,10 @@ function getType(value: Value): Type { return {type: 'bool'}; } + if (is.string(value) && isArrayValue) { + return {type: 'string'}; + } + if (Buffer.isBuffer(value)) { return {type: 'bytes'}; } @@ -663,7 +668,7 @@ function getType(value: Value): Type { return { type: 'array', - child: getType(child), + child: getType(child, true), }; } diff --git a/system-test/spanner.ts b/system-test/spanner.ts index a31b89f01..68000b2ea 100644 --- a/system-test/spanner.ts +++ b/system-test/spanner.ts @@ -1431,6 +1431,46 @@ describe('Spanner', () => { ); }); + it('GOOGLE_STANDARD_SQL should query untyped string array values', function (done) { + if (IS_EMULATOR_ENABLED) { + this.skip(); + } + + const value = ['ghi', 'jkl']; + const table = googleSqlTable; + + const query: ExecuteSqlRequest = { + sql: + 'SELECT * FROM `' + + table.name + + '` WHERE EXISTS (SELECT 1 FROM UNNEST(StringArray) AS c WHERE c IN UNNEST(@value))', + params: { + value, + }, + }; + + insert( + {StringArray: value}, + Spanner.GOOGLE_STANDARD_SQL, + (err, row) => { + assert.ifError(err); + assert.deepStrictEqual(row.toJSON().StringArray, ['ghi', 'jkl']); + + DATABASE.run(query, (err, rows) => { + if (err) { + assert.ifError(err); + done(); + } + assert.deepStrictEqual(rows!.shift()!.toJSON().StringArray, [ + 'ghi', + 'jkl', + ]); + done(); + }); + } + ); + }); + it('GOOGLE_STANDARD_SQL should read untyped string values', function (done) { if (IS_EMULATOR_ENABLED) { this.skip();