Skip to content

Commit ce3d33b

Browse files
committed
feat(bigquery): validate integration against live API docs, add dataset/table lifecycle + query-result tools
- Cross-checked existing query/list_datasets/list_tables/get_table/insert_rows tools against BigQuery REST v2 docs; no critical issues found - Added 6 new tools covered by the existing bigquery OAuth scope: create/delete dataset, create/delete table, list table data, get query results - Wired new operations into the block (subblocks, conditions, tools.config), registry, and barrel exports
1 parent a48ecd2 commit ce3d33b

10 files changed

Lines changed: 1125 additions & 19 deletions

File tree

apps/sim/blocks/blocks/google_bigquery.ts

Lines changed: 258 additions & 19 deletions
Large diffs are not rendered by default.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import type {
2+
GoogleBigQueryCreateDatasetParams,
3+
GoogleBigQueryCreateDatasetResponse,
4+
} from '@/tools/google_bigquery/types'
5+
import type { ToolConfig } from '@/tools/types'
6+
7+
export const googleBigQueryCreateDatasetTool: ToolConfig<
8+
GoogleBigQueryCreateDatasetParams,
9+
GoogleBigQueryCreateDatasetResponse
10+
> = {
11+
id: 'google_bigquery_create_dataset',
12+
name: 'BigQuery Create Dataset',
13+
description: 'Create a new dataset in a Google BigQuery project',
14+
version: '1.0.0',
15+
16+
oauth: {
17+
required: true,
18+
provider: 'google-bigquery',
19+
},
20+
21+
params: {
22+
accessToken: {
23+
type: 'string',
24+
required: true,
25+
visibility: 'hidden',
26+
description: 'OAuth access token',
27+
},
28+
projectId: {
29+
type: 'string',
30+
required: true,
31+
visibility: 'user-or-llm',
32+
description: 'Google Cloud project ID',
33+
},
34+
datasetId: {
35+
type: 'string',
36+
required: true,
37+
visibility: 'user-or-llm',
38+
description: 'ID for the new BigQuery dataset',
39+
},
40+
location: {
41+
type: 'string',
42+
required: false,
43+
visibility: 'user-or-llm',
44+
description: 'Geographic location for the dataset (e.g., "US", "EU")',
45+
},
46+
friendlyName: {
47+
type: 'string',
48+
required: false,
49+
visibility: 'user-or-llm',
50+
description: 'Human-readable name for the dataset',
51+
},
52+
description: {
53+
type: 'string',
54+
required: false,
55+
visibility: 'user-or-llm',
56+
description: 'Description of the dataset',
57+
},
58+
},
59+
60+
request: {
61+
url: (params) =>
62+
`https://bigquery.googleapis.com/bigquery/v2/projects/${encodeURIComponent(params.projectId)}/datasets`,
63+
method: 'POST',
64+
headers: (params) => ({
65+
Authorization: `Bearer ${params.accessToken}`,
66+
'Content-Type': 'application/json',
67+
}),
68+
body: (params) => {
69+
const body: Record<string, unknown> = {
70+
datasetReference: {
71+
projectId: params.projectId,
72+
datasetId: params.datasetId,
73+
},
74+
}
75+
if (params.location) body.location = params.location
76+
if (params.friendlyName) body.friendlyName = params.friendlyName
77+
if (params.description) body.description = params.description
78+
return body
79+
},
80+
},
81+
82+
transformResponse: async (response: Response) => {
83+
const data = await response.json()
84+
if (!response.ok) {
85+
const errorMessage = data.error?.message || 'Failed to create BigQuery dataset'
86+
throw new Error(errorMessage)
87+
}
88+
89+
return {
90+
success: true,
91+
output: {
92+
datasetId: data.datasetReference?.datasetId ?? null,
93+
projectId: data.datasetReference?.projectId ?? null,
94+
friendlyName: data.friendlyName ?? null,
95+
description: data.description ?? null,
96+
location: data.location ?? null,
97+
creationTime: data.creationTime ?? null,
98+
},
99+
}
100+
},
101+
102+
outputs: {
103+
datasetId: { type: 'string', description: 'Unique dataset identifier' },
104+
projectId: { type: 'string', description: 'Project ID containing this dataset' },
105+
friendlyName: {
106+
type: 'string',
107+
description: 'Descriptive name for the dataset',
108+
optional: true,
109+
},
110+
description: { type: 'string', description: 'Dataset description', optional: true },
111+
location: {
112+
type: 'string',
113+
description: 'Geographic location where the data resides',
114+
optional: true,
115+
},
116+
creationTime: {
117+
type: 'string',
118+
description: 'Dataset creation time (milliseconds since epoch)',
119+
optional: true,
120+
},
121+
},
122+
}
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import type {
2+
GoogleBigQueryCreateTableParams,
3+
GoogleBigQueryCreateTableResponse,
4+
} from '@/tools/google_bigquery/types'
5+
import type { ToolConfig } from '@/tools/types'
6+
7+
export const googleBigQueryCreateTableTool: ToolConfig<
8+
GoogleBigQueryCreateTableParams,
9+
GoogleBigQueryCreateTableResponse
10+
> = {
11+
id: 'google_bigquery_create_table',
12+
name: 'BigQuery Create Table',
13+
description: 'Create a new table in a Google BigQuery dataset',
14+
version: '1.0.0',
15+
16+
oauth: {
17+
required: true,
18+
provider: 'google-bigquery',
19+
},
20+
21+
params: {
22+
accessToken: {
23+
type: 'string',
24+
required: true,
25+
visibility: 'hidden',
26+
description: 'OAuth access token',
27+
},
28+
projectId: {
29+
type: 'string',
30+
required: true,
31+
visibility: 'user-or-llm',
32+
description: 'Google Cloud project ID',
33+
},
34+
datasetId: {
35+
type: 'string',
36+
required: true,
37+
visibility: 'user-or-llm',
38+
description: 'BigQuery dataset ID',
39+
},
40+
tableId: {
41+
type: 'string',
42+
required: true,
43+
visibility: 'user-or-llm',
44+
description: 'ID for the new BigQuery table',
45+
},
46+
schema: {
47+
type: 'string',
48+
required: true,
49+
visibility: 'user-or-llm',
50+
description:
51+
'JSON array of column field definitions, e.g. [{"name":"id","type":"STRING","mode":"REQUIRED"}]',
52+
},
53+
description: {
54+
type: 'string',
55+
required: false,
56+
visibility: 'user-or-llm',
57+
description: 'Description of the table',
58+
},
59+
friendlyName: {
60+
type: 'string',
61+
required: false,
62+
visibility: 'user-or-llm',
63+
description: 'Human-readable name for the table',
64+
},
65+
},
66+
67+
request: {
68+
url: (params) =>
69+
`https://bigquery.googleapis.com/bigquery/v2/projects/${encodeURIComponent(params.projectId)}/datasets/${encodeURIComponent(params.datasetId.trim())}/tables`,
70+
method: 'POST',
71+
headers: (params) => ({
72+
Authorization: `Bearer ${params.accessToken}`,
73+
'Content-Type': 'application/json',
74+
}),
75+
body: (params) => {
76+
const fields = typeof params.schema === 'string' ? JSON.parse(params.schema) : params.schema
77+
78+
const body: Record<string, unknown> = {
79+
tableReference: {
80+
projectId: params.projectId,
81+
datasetId: params.datasetId,
82+
tableId: params.tableId,
83+
},
84+
schema: { fields },
85+
}
86+
if (params.description) body.description = params.description
87+
if (params.friendlyName) body.friendlyName = params.friendlyName
88+
return body
89+
},
90+
},
91+
92+
transformResponse: async (response: Response) => {
93+
const data = await response.json()
94+
if (!response.ok) {
95+
const errorMessage = data.error?.message || 'Failed to create BigQuery table'
96+
throw new Error(errorMessage)
97+
}
98+
99+
const schema = (data.schema?.fields ?? []).map(
100+
(f: { name: string; type: string; mode?: string; description?: string }) => ({
101+
name: f.name,
102+
type: f.type,
103+
mode: f.mode ?? null,
104+
description: f.description ?? null,
105+
})
106+
)
107+
108+
return {
109+
success: true,
110+
output: {
111+
tableId: data.tableReference?.tableId ?? null,
112+
datasetId: data.tableReference?.datasetId ?? null,
113+
projectId: data.tableReference?.projectId ?? null,
114+
type: data.type ?? null,
115+
description: data.description ?? null,
116+
schema,
117+
creationTime: data.creationTime ?? null,
118+
location: data.location ?? null,
119+
},
120+
}
121+
},
122+
123+
outputs: {
124+
tableId: { type: 'string', description: 'Table ID' },
125+
datasetId: { type: 'string', description: 'Dataset ID' },
126+
projectId: { type: 'string', description: 'Project ID' },
127+
type: { type: 'string', description: 'Table type (usually TABLE)', optional: true },
128+
description: { type: 'string', description: 'Table description', optional: true },
129+
schema: {
130+
type: 'array',
131+
description: 'Array of column definitions',
132+
items: {
133+
type: 'object',
134+
properties: {
135+
name: { type: 'string', description: 'Column name' },
136+
type: { type: 'string', description: 'Data type' },
137+
mode: {
138+
type: 'string',
139+
description: 'Column mode (NULLABLE, REQUIRED, or REPEATED)',
140+
optional: true,
141+
},
142+
description: { type: 'string', description: 'Column description', optional: true },
143+
},
144+
},
145+
},
146+
creationTime: {
147+
type: 'string',
148+
description: 'Table creation time (milliseconds since epoch)',
149+
optional: true,
150+
},
151+
location: {
152+
type: 'string',
153+
description: 'Geographic location where the table resides',
154+
optional: true,
155+
},
156+
},
157+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import type {
2+
GoogleBigQueryDeleteDatasetParams,
3+
GoogleBigQueryDeleteDatasetResponse,
4+
} from '@/tools/google_bigquery/types'
5+
import type { ToolConfig } from '@/tools/types'
6+
7+
export const googleBigQueryDeleteDatasetTool: ToolConfig<
8+
GoogleBigQueryDeleteDatasetParams,
9+
GoogleBigQueryDeleteDatasetResponse
10+
> = {
11+
id: 'google_bigquery_delete_dataset',
12+
name: 'BigQuery Delete Dataset',
13+
description: 'Delete a dataset from a Google BigQuery project',
14+
version: '1.0.0',
15+
16+
oauth: {
17+
required: true,
18+
provider: 'google-bigquery',
19+
},
20+
21+
params: {
22+
accessToken: {
23+
type: 'string',
24+
required: true,
25+
visibility: 'hidden',
26+
description: 'OAuth access token',
27+
},
28+
projectId: {
29+
type: 'string',
30+
required: true,
31+
visibility: 'user-or-llm',
32+
description: 'Google Cloud project ID',
33+
},
34+
datasetId: {
35+
type: 'string',
36+
required: true,
37+
visibility: 'user-or-llm',
38+
description: 'BigQuery dataset ID to delete',
39+
},
40+
deleteContents: {
41+
type: 'boolean',
42+
required: false,
43+
visibility: 'user-or-llm',
44+
description: 'Whether to delete tables inside the dataset (default: false)',
45+
},
46+
},
47+
48+
request: {
49+
url: (params) => {
50+
const url = new URL(
51+
`https://bigquery.googleapis.com/bigquery/v2/projects/${encodeURIComponent(params.projectId)}/datasets/${encodeURIComponent(params.datasetId.trim())}`
52+
)
53+
if (params.deleteContents !== undefined) {
54+
url.searchParams.set('deleteContents', String(params.deleteContents))
55+
}
56+
return url.toString()
57+
},
58+
method: 'DELETE',
59+
headers: (params) => ({
60+
Authorization: `Bearer ${params.accessToken}`,
61+
}),
62+
},
63+
64+
transformResponse: async (response: Response) => {
65+
if (!response.ok) {
66+
const data = await response.json()
67+
const errorMessage = data.error?.message || 'Failed to delete BigQuery dataset'
68+
throw new Error(errorMessage)
69+
}
70+
71+
return {
72+
success: true,
73+
output: {
74+
deleted: true,
75+
},
76+
}
77+
},
78+
79+
outputs: {
80+
deleted: { type: 'boolean', description: 'Whether the dataset was deleted' },
81+
},
82+
}

0 commit comments

Comments
 (0)