From 2072d52a169a78e5f4fdf76bd9bba39e493ae3f8 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 12 Feb 2026 10:54:49 -0500 Subject: [PATCH 1/2] Finish tests for named parameters --- handwritten/bigquery/system-test/bigquery.ts | 155 +++++++++++++++++++ 1 file changed, 155 insertions(+) diff --git a/handwritten/bigquery/system-test/bigquery.ts b/handwritten/bigquery/system-test/bigquery.ts index 3d07debe82c..62d40155c3d 100644 --- a/handwritten/bigquery/system-test/bigquery.ts +++ b/handwritten/bigquery/system-test/bigquery.ts @@ -1950,6 +1950,161 @@ describe('BigQuery', () => { }, ); }); + describe.only('High Precision Query System Tests', () => { + let bigquery: BigQuery; + const expectedTsValueNanoseconds = '2023-01-01T12:00:00.123456000Z'; + const expectedTsValuePicoseconds = + '2023-01-01T12:00:00.123456789123Z'; + const expectedErrorMessage = + 'Cannot specify both timestamp_as_int and timestamp_output_format.'; + + before(() => { + bigquery = new BigQuery(); + }); + + const testCases = [ + { + name: 'TOF: FLOAT64, UI64: true (error)', + timestampOutputFormat: 'FLOAT64', + useInt64Timestamp: true, + expectedTsValue: undefined, + expectedError: expectedErrorMessage, + }, + { + name: 'TOF: omitted, UI64: omitted (default INT64)', + timestampOutputFormat: undefined, + useInt64Timestamp: undefined, + expectedTsValue: expectedTsValuePicoseconds, + }, + { + name: 'TOF: omitted, UI64: true', + timestampOutputFormat: undefined, + useInt64Timestamp: true, + expectedTsValue: expectedTsValueNanoseconds, + }, + ]; + + testCases.forEach(testCase => { + it(`should handle ${testCase.name}`, async () => { + /* + The users use the new TIMESTAMP(12) type to indicate they want to + opt in to using timestampPrecision=12. The reason is that some queries + like `SELECT CAST(? as TIMESTAMP(12))` will fail if we set + timestampPrecision=12 and we don't want this code change to affect + existing users. Queries using TIMESTAMP_ADD are another example. + */ + const query = { + query: 'SELECT @r AS ts', + params: { + r: bigquery.timestamp('2023-01-01T12:00:00.123456789123Z'), + }, + types: { + r: 'TIMESTAMP(12)', + }, + }; + + const options: any = {}; + if (testCase.timestampOutputFormat !== undefined) { + options['formatOptions.timestampOutputFormat'] = + testCase.timestampOutputFormat; + } + if (testCase.useInt64Timestamp !== undefined) { + options['formatOptions.useInt64Timestamp'] = + testCase.useInt64Timestamp; + } + + try { + const [rows] = await bigquery.query(query, options); + if (testCase.expectedError) { + assert.fail( + `Query should have failed for ${testCase.name}, but succeeded`, + ); + } + assert.ok(rows.length > 0); + assert.ok(rows[0].ts.value !== undefined); + assert.strictEqual( + rows[0].ts.value, + testCase.expectedTsValue, + ); + } catch (err: any) { + if (!testCase.expectedError) { + throw err; + } + + const message = err.message; + assert.strictEqual( + message, + testCase.expectedError, + `Expected ${testCase.expectedError} error for ${testCase.name}, got ${message} (${err.message})`, + ); + } + }); + it(`should handle nested ${testCase.name}`, async () => { + /* + The users use the new TIMESTAMP(12) type to indicate they want to + opt in to using timestampPrecision=12. The reason is that some queries + like `SELECT CAST(? as TIMESTAMP(12))` will fail if we set + timestampPrecision=12 and we don't want this code change to affect + existing users. + */ + const query = { + query: 'SELECT @r obj', + params: { + r: { + nested: { + a: bigquery.timestamp( + '2023-01-01T12:00:00.123456789123Z', + ), + }, + }, + }, + types: { + r: { + nested: { + a: 'TIMESTAMP(12)', + }, + }, + }, + }; + + const options: any = {}; + if (testCase.timestampOutputFormat !== undefined) { + options['formatOptions.timestampOutputFormat'] = + testCase.timestampOutputFormat; + } + if (testCase.useInt64Timestamp !== undefined) { + options['formatOptions.useInt64Timestamp'] = + testCase.useInt64Timestamp; + } + + try { + const [rows] = await bigquery.query(query, options); + if (testCase.expectedError) { + assert.fail( + `Query should have failed for ${testCase.name}, but succeeded`, + ); + } + assert.ok(rows.length > 0); + assert.ok(rows[0].obj.nested.a.value !== undefined); + assert.strictEqual( + rows[0].obj.nested.a.value, + testCase.expectedTsValue, + ); + } catch (err: any) { + if (!testCase.expectedError) { + throw err; + } + + const message = err.message; + assert.strictEqual( + message, + testCase.expectedError, + `Expected ${testCase.expectedError} error for ${testCase.name}, got ${message} (${err.message})`, + ); + } + }); + }); + }); }); }); From d2e6e4b4c2be73cc993d0fe72540afdbd4b9c02d Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 12 Feb 2026 11:09:32 -0500 Subject: [PATCH 2/2] Remove only --- handwritten/bigquery/system-test/bigquery.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handwritten/bigquery/system-test/bigquery.ts b/handwritten/bigquery/system-test/bigquery.ts index 62d40155c3d..fcebc9c86f0 100644 --- a/handwritten/bigquery/system-test/bigquery.ts +++ b/handwritten/bigquery/system-test/bigquery.ts @@ -1950,7 +1950,7 @@ describe('BigQuery', () => { }, ); }); - describe.only('High Precision Query System Tests', () => { + describe('High Precision Query System Tests', () => { let bigquery: BigQuery; const expectedTsValueNanoseconds = '2023-01-01T12:00:00.123456000Z'; const expectedTsValuePicoseconds =