diff --git a/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/executeQuery.test.ts b/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/executeQuery.test.ts index 39cefa7319..f7a0965d3d 100644 --- a/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/executeQuery.test.ts +++ b/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/executeQuery.test.ts @@ -10,7 +10,7 @@ jest.mock('../../../v2/transport', () => { const originalModule = jest.requireActual('../../../v2/transport'); return { ...originalModule, - googleApiRequest: jest.fn(async (method: IHttpRequestMethods, resource: string) => { + googleBigQueryApiRequest: jest.fn(async (method: IHttpRequestMethods, resource: string) => { if (resource === '/v2/projects/test-project/jobs' && method === 'POST') { return { jobReference: { @@ -25,7 +25,7 @@ jest.mock('../../../v2/transport', () => { return {}; } }), - // googleApiRequestAllItems: jest.fn(async () => {}), + googleBigQueryApiRequestAllItems: jest.fn(async () => ({ rows: [], schema: {} })), }; }); @@ -47,8 +47,9 @@ describe('Test Google BigQuery V2, executeQuery', () => { const testNode = async (testData: WorkflowTestData, types: INodeTypes) => { const { result } = await executeWorkflow(testData, types); - expect(transport.googleApiRequest).toHaveBeenCalledTimes(2); - expect(transport.googleApiRequest).toHaveBeenCalledWith( + expect(transport.googleBigQueryApiRequest).toHaveBeenCalledTimes(1); + expect(transport.googleBigQueryApiRequestAllItems).toHaveBeenCalledTimes(1); + expect(transport.googleBigQueryApiRequest).toHaveBeenCalledWith( 'POST', '/v2/projects/test-project/jobs', { @@ -60,11 +61,11 @@ describe('Test Google BigQuery V2, executeQuery', () => { }, }, ); - expect(transport.googleApiRequest).toHaveBeenCalledWith( + expect(transport.googleBigQueryApiRequestAllItems).toHaveBeenCalledWith( 'GET', '/v2/projects/test-project/queries/job_123', undefined, - {}, + { location: undefined, maxResults: 1000, timeoutMs: 10000 }, ); expect(result.finished).toEqual(true); diff --git a/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.autoMapMode.test.ts b/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.autoMapMode.test.ts index 001a06315f..4ee4627838 100644 --- a/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.autoMapMode.test.ts +++ b/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.autoMapMode.test.ts @@ -10,7 +10,7 @@ jest.mock('../../../v2/transport', () => { const originalModule = jest.requireActual('../../../v2/transport'); return { ...originalModule, - googleApiRequest: jest.fn(async (method: IHttpRequestMethods, resource: string) => { + googleBigQueryApiRequest: jest.fn(async (method: IHttpRequestMethods, resource: string) => { if ( resource === '/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/num_text' && @@ -55,13 +55,13 @@ describe('Test Google BigQuery V2, insert auto map', () => { const testNode = async (testData: WorkflowTestData, types: INodeTypes) => { const { result } = await executeWorkflow(testData, types); - expect(transport.googleApiRequest).toHaveBeenCalledTimes(2); - expect(transport.googleApiRequest).toHaveBeenCalledWith( + expect(transport.googleBigQueryApiRequest).toHaveBeenCalledTimes(2); + expect(transport.googleBigQueryApiRequest).toHaveBeenCalledWith( 'GET', '/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/num_text', {}, ); - expect(transport.googleApiRequest).toHaveBeenCalledWith( + expect(transport.googleBigQueryApiRequest).toHaveBeenCalledWith( 'POST', '/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/num_text/insertAll', { diff --git a/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.manualMode.test.ts b/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.manualMode.test.ts index 0d0215d5cd..f4d94dda8b 100644 --- a/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.manualMode.test.ts +++ b/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.manualMode.test.ts @@ -10,7 +10,7 @@ jest.mock('../../../v2/transport', () => { const originalModule = jest.requireActual('../../../v2/transport'); return { ...originalModule, - googleApiRequest: jest.fn(async (method: IHttpRequestMethods, resource: string) => { + googleBigQueryApiRequest: jest.fn(async (method: IHttpRequestMethods, resource: string) => { if ( resource === '/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/test_json' && @@ -56,13 +56,13 @@ describe('Test Google BigQuery V2, insert define manually', () => { const testNode = async (testData: WorkflowTestData, types: INodeTypes) => { const { result } = await executeWorkflow(testData, types); - expect(transport.googleApiRequest).toHaveBeenCalledTimes(2); - expect(transport.googleApiRequest).toHaveBeenCalledWith( + expect(transport.googleBigQueryApiRequest).toHaveBeenCalledTimes(2); + expect(transport.googleBigQueryApiRequest).toHaveBeenCalledWith( 'GET', '/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/test_json', {}, ); - expect(transport.googleApiRequest).toHaveBeenCalledWith( + expect(transport.googleBigQueryApiRequest).toHaveBeenCalledWith( 'POST', '/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/test_json/insertAll', { diff --git a/packages/nodes-base/nodes/Google/BigQuery/v2/actions/database/executeQuery.operation.ts b/packages/nodes-base/nodes/Google/BigQuery/v2/actions/database/executeQuery.operation.ts index 4752b2631c..2561a6e5a2 100644 --- a/packages/nodes-base/nodes/Google/BigQuery/v2/actions/database/executeQuery.operation.ts +++ b/packages/nodes-base/nodes/Google/BigQuery/v2/actions/database/executeQuery.operation.ts @@ -9,7 +9,7 @@ import { ApplicationError, NodeOperationError, sleep } from 'n8n-workflow'; import type { ResponseWithJobReference } from '../../helpers/interfaces'; import { prepareOutput } from '../../helpers/utils'; -import { googleApiRequest } from '../../transport'; +import { googleBigQueryApiRequestAllItems, googleBigQueryApiRequest } from '../../transport'; import { getResolvables, updateDisplayOptions } from '@utils/utilities'; const properties: INodeProperties[] = [ @@ -108,18 +108,21 @@ const properties: INodeProperties[] = [ 'Limits the bytes billed for this query. Queries with bytes billed above this limit will fail (without incurring a charge). String in Int64Value format', }, { - displayName: 'Max Results', + displayName: 'Max Results Per Page', name: 'maxResults', type: 'number', default: 1000, - description: 'The maximum number of rows of data to return', + description: + 'Maximum number of results to return per page of results. This is particularly useful when dealing with large datasets. It will not affect the total number of results returned, e.g. rows in a table. You can use LIMIT in your SQL query to limit the number of rows returned.', }, { displayName: 'Timeout', name: 'timeoutMs', type: 'number', default: 10000, - description: 'How long to wait for the query to complete, in milliseconds', + hint: 'How long to wait for the query to complete, in milliseconds', + description: + 'Specifies the maximum amount of time, in milliseconds, that the client is willing to wait for the query to complete. Be aware that the call is not guaranteed to wait for the specified timeout; it typically returns after around 200 seconds (200,000 milliseconds), even if the query is not complete.', }, { displayName: 'Raw Output', @@ -154,19 +157,31 @@ const displayOptions = { export const description = updateDisplayOptions(displayOptions, properties); export async function execute(this: IExecuteFunctions): Promise { - // https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query - const items = this.getInputData(); const length = items.length; const returnData: INodeExecutionData[] = []; let jobs = []; + let maxResults = 1000; + let timeoutMs = 10000; for (let i = 0; i < length; i++) { try { let sqlQuery = this.getNodeParameter('sqlQuery', i) as string; - const options = this.getNodeParameter('options', i); + + const options = this.getNodeParameter('options', i) as { + defaultDataset?: string; + dryRun?: boolean; + includeSchema?: boolean; + location?: string; + maximumBytesBilled?: string; + maxResults?: number; + timeoutMs?: number; + rawOutput?: boolean; + useLegacySql?: boolean; + }; + const projectId = this.getNodeParameter('projectId', i, undefined, { extractValue: true, }); @@ -179,15 +194,25 @@ export async function execute(this: IExecuteFunctions): Promise { const projectId = this.getNodeParameter('projectId', undefined, { extractValue: true, }); const returnData: INodePropertyOptions[] = []; - const { datasets } = await googleApiRequest.call( + const { datasets } = await googleBigQueryApiRequest.call( this, 'GET', `/v2/projects/${projectId}/datasets`, @@ -33,7 +33,7 @@ export async function getSchema(this: ILoadOptionsFunctions): Promise