@@ -3,7 +3,13 @@ import { PromisePoolExecutor } from "promise-pool-executor";
3
3
4
4
import { BigQuery , TableField , TableMetadata } from "@google-cloud/bigquery" ;
5
5
import { Credentials } from "df/api/commands/credentials" ;
6
- import { IDbAdapter , IDbClient , IExecutionResult , OnCancel } from "df/api/dbadapters/index" ;
6
+ import {
7
+ CACHED_STATE_TABLE_TARGET ,
8
+ IDbAdapter ,
9
+ IDbClient ,
10
+ IExecutionResult ,
11
+ OnCancel
12
+ } from "df/api/dbadapters/index" ;
7
13
import { parseBigqueryEvalError } from "df/api/utils/error_parsing" ;
8
14
import { LimitedResultSet } from "df/api/utils/results" ;
9
15
import {
@@ -18,8 +24,6 @@ import { StringifiedMap } from "df/common/strings/stringifier";
18
24
import { collectEvaluationQueries , QueryOrAction } from "df/core/adapters" ;
19
25
import { dataform } from "df/protos/ts" ;
20
26
21
- const CACHED_STATE_TABLE_NAME = "dataform_meta.cache_state" ;
22
-
23
27
const EXTRA_GOOGLE_SCOPES = [ "https://www.googleapis.com/auth/drive" ] ;
24
28
25
29
const BIGQUERY_DATE_RELATED_FIELDS = [
@@ -254,17 +258,23 @@ export class BigQueryDbAdapter implements IDbAdapter {
254
258
// Unimplemented.
255
259
}
256
260
257
- public async persistedStateMetadata ( ) : Promise < dataform . IPersistedTableMetadata [ ] > {
258
- const { rows } = await this . execute ( `SELECT * FROM ${ CACHED_STATE_TABLE_NAME } ` , {
259
- rowLimit : 5000 // TODO: Add pagination for 5000+ rows
260
- } ) ;
261
+ public async persistedStateMetadata (
262
+ database : string
263
+ ) : Promise < dataform . IPersistedTableMetadata [ ] > {
264
+ const { rows } = await this . execute (
265
+ `SELECT * FROM \`${ database } .${ CACHED_STATE_TABLE_TARGET . schema } .${ CACHED_STATE_TABLE_TARGET . name } \`` ,
266
+ {
267
+ rowLimit : 5000 // TODO: Add pagination for 5000+ rows
268
+ }
269
+ ) ;
261
270
const persistedMetadata = rows . map ( ( row : IMetadataRow ) =>
262
271
decodePersistedTableMetadata ( row . metadata_proto )
263
272
) ;
264
273
return persistedMetadata ;
265
274
}
266
275
267
276
public async persistStateMetadata (
277
+ database : string ,
268
278
transitiveInputMetadataByTarget : StringifiedMap <
269
279
dataform . ITarget ,
270
280
dataform . PersistedTableMetadata . ITransitiveInputMetadata
@@ -278,11 +288,12 @@ export class BigQueryDbAdapter implements IDbAdapter {
278
288
if ( allActions . length === 0 ) {
279
289
return ;
280
290
}
291
+ const cachedStateTableName = `${ database } .${ CACHED_STATE_TABLE_TARGET . schema } .${ CACHED_STATE_TABLE_TARGET . name } ` ;
281
292
try {
282
293
// Create the cache table, if needed.
283
294
await this . execute (
284
295
`
285
- CREATE TABLE IF NOT EXISTS \`${ CACHED_STATE_TABLE_NAME } \` (
296
+ CREATE TABLE IF NOT EXISTS \`${ cachedStateTableName } \` (
286
297
target STRING,
287
298
metadata_proto STRING
288
299
)` ,
@@ -291,7 +302,7 @@ CREATE TABLE IF NOT EXISTS \`${CACHED_STATE_TABLE_NAME}\` (
291
302
// Before saving any new data, delete all entries for 'allActions'.
292
303
await this . execute (
293
304
`
294
- DELETE \`${ CACHED_STATE_TABLE_NAME } \` WHERE target IN (${ allActions
305
+ DELETE \`${ cachedStateTableName } \` WHERE target IN (${ allActions
295
306
. map ( ( { target } ) => `'${ toRowKey ( target ) } '` )
296
307
. join ( "," ) } )`,
297
308
options
@@ -322,7 +333,7 @@ DELETE \`${CACHED_STATE_TABLE_NAME}\` WHERE target IN (${allActions
322
333
) ;
323
334
// We have to split up the INSERT queries to get around BigQuery's query length limit.
324
335
while ( valuesTuples . length > 0 ) {
325
- let insertStatement = `INSERT INTO \`${ CACHED_STATE_TABLE_NAME } \` (target, metadata_proto) VALUES ${ valuesTuples . pop ( ) } ` ;
336
+ let insertStatement = `INSERT INTO \`${ cachedStateTableName } \` (target, metadata_proto) VALUES ${ valuesTuples . pop ( ) } ` ;
326
337
let nextInsertStatement = `${ insertStatement } , ${ valuesTuples [ valuesTuples . length - 1 ] } ` ;
327
338
while ( valuesTuples . length > 0 && nextInsertStatement . length < MAX_QUERY_LENGTH ) {
328
339
insertStatement = nextInsertStatement ;
0 commit comments