@malloydata/db-bigquery 0.0.11-dev221202152346 → 0.0.11-dev221202180154
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RowMetadata } from "@google-cloud/bigquery";
|
|
2
2
|
import bigquery from "@google-cloud/bigquery/build/src/types";
|
|
3
3
|
import { ResourceStream } from "@google-cloud/paginator";
|
|
4
|
-
import {
|
|
4
|
+
import { PersistSQLResults, PooledConnection, QueryData, StructDef, StreamingConnection, MalloyQueryData, FieldTypeDef, SQLBlock, Connection, QueryDataRow } from "@malloydata/malloy";
|
|
5
5
|
export interface BigQueryManagerOptions {
|
|
6
6
|
credentials?: {
|
|
7
7
|
clientId: string;
|
|
@@ -29,7 +29,7 @@ declare type QueryOptionsReader = Partial<BigQueryQueryOptions> | (() => Partial
|
|
|
29
29
|
export declare class BigQueryAuthenticationError extends Error {
|
|
30
30
|
constructor(message: string);
|
|
31
31
|
}
|
|
32
|
-
export declare class BigQueryConnection implements Connection, PersistSQLResults, StreamingConnection
|
|
32
|
+
export declare class BigQueryConnection implements Connection, PersistSQLResults, StreamingConnection {
|
|
33
33
|
static DEFAULT_QUERY_OPTIONS: BigQueryQueryOptions;
|
|
34
34
|
private bigQuery;
|
|
35
35
|
private projectId;
|
|
@@ -50,8 +50,6 @@ export declare class BigQueryConnection implements Connection, PersistSQLResults
|
|
|
50
50
|
isPool(): this is PooledConnection;
|
|
51
51
|
canPersist(): this is PersistSQLResults;
|
|
52
52
|
canStream(): this is StreamingConnection;
|
|
53
|
-
canFetchSchemaAndRunSimultaneously(): this is FetchSchemaAndRunSimultaneously;
|
|
54
|
-
canFetchSchemaAndRunStreamSimultaneously(): this is FetchSchemaAndRunStreamSimultaneously;
|
|
55
53
|
private _runSQL;
|
|
56
54
|
runSQL(sqlCommand: string, options?: Partial<BigQueryQueryOptions>, rowIndex?: number): Promise<MalloyQueryData>;
|
|
57
55
|
runSQLBlockAndFetchResultSchema(sqlBlock: SQLBlock, options?: {
|
|
@@ -78,9 +76,12 @@ export declare class BigQueryConnection implements Connection, PersistSQLResults
|
|
|
78
76
|
errors: Record<string, string>;
|
|
79
77
|
}>;
|
|
80
78
|
private getSQLBlockSchema;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
fetchSchemaForSQLBlock(sqlRef: SQLBlock): Promise<{
|
|
80
|
+
structDef: StructDef;
|
|
81
|
+
error?: undefined;
|
|
82
|
+
} | {
|
|
83
|
+
error: string;
|
|
84
|
+
structDef?: undefined;
|
|
84
85
|
}>;
|
|
85
86
|
private createBigQueryJobAndGetResults;
|
|
86
87
|
private createBigQueryJob;
|
|
@@ -139,12 +139,6 @@ class BigQueryConnection {
|
|
|
139
139
|
canStream() {
|
|
140
140
|
return true;
|
|
141
141
|
}
|
|
142
|
-
canFetchSchemaAndRunSimultaneously() {
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
145
|
-
canFetchSchemaAndRunStreamSimultaneously() {
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
142
|
async _runSQL(sqlCommand, options = {}, rowIndex = 0) {
|
|
149
143
|
var _a, _b, _c, _d;
|
|
150
144
|
const defaultOptions = this.readQueryOptions();
|
|
@@ -176,7 +170,7 @@ class BigQueryConnection {
|
|
|
176
170
|
return data;
|
|
177
171
|
}
|
|
178
172
|
async runSQLBlockAndFetchResultSchema(sqlBlock, options) {
|
|
179
|
-
const { data, schema: schemaRaw } = await this._runSQL(sqlBlock.
|
|
173
|
+
const { data, schema: schemaRaw } = await this._runSQL(sqlBlock.selectStr, options);
|
|
180
174
|
const schema = this.structDefFromSQLSchema(sqlBlock, schemaRaw);
|
|
181
175
|
return { data, schema };
|
|
182
176
|
}
|
|
@@ -469,7 +463,7 @@ class BigQueryConnection {
|
|
|
469
463
|
try {
|
|
470
464
|
const [job] = await this.bigQuery.createQueryJob({
|
|
471
465
|
location: this.location,
|
|
472
|
-
query: sqlRef.
|
|
466
|
+
query: sqlRef.selectStr,
|
|
473
467
|
dryRun: true,
|
|
474
468
|
});
|
|
475
469
|
return job.metadata.statistics.query.schema;
|
|
@@ -480,32 +474,22 @@ class BigQueryConnection {
|
|
|
480
474
|
}
|
|
481
475
|
throw lastFetchError;
|
|
482
476
|
}
|
|
483
|
-
async
|
|
484
|
-
const
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
inCache = {
|
|
493
|
-
schema: this.structDefFromSQLSchema(sqlRef, tableFieldSchema),
|
|
494
|
-
};
|
|
495
|
-
this.schemaCache.set(key, inCache);
|
|
496
|
-
}
|
|
497
|
-
catch (error) {
|
|
498
|
-
inCache = { error: error.message };
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
if (inCache.schema !== undefined) {
|
|
502
|
-
schemas[key] = inCache.schema;
|
|
477
|
+
async fetchSchemaForSQLBlock(sqlRef) {
|
|
478
|
+
const key = sqlRef.name;
|
|
479
|
+
let inCache = this.sqlSchemaCache.get(key);
|
|
480
|
+
if (!inCache) {
|
|
481
|
+
try {
|
|
482
|
+
const tableFieldSchema = await this.getSQLBlockSchema(sqlRef);
|
|
483
|
+
inCache = {
|
|
484
|
+
structDef: this.structDefFromSQLSchema(sqlRef, tableFieldSchema),
|
|
485
|
+
};
|
|
503
486
|
}
|
|
504
|
-
|
|
505
|
-
|
|
487
|
+
catch (error) {
|
|
488
|
+
inCache = { error: error.message };
|
|
506
489
|
}
|
|
490
|
+
this.sqlSchemaCache.set(key, inCache);
|
|
507
491
|
}
|
|
508
|
-
return
|
|
492
|
+
return inCache;
|
|
509
493
|
}
|
|
510
494
|
// TODO this needs to extend the wait for results using a timeout set by the user,
|
|
511
495
|
// and probably needs to loop to check for results - BQ docs now say that after ~2min of waiting,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/db-bigquery",
|
|
3
|
-
"version": "0.0.11-
|
|
3
|
+
"version": "0.0.11-dev221202180154",
|
|
4
4
|
"license": "GPL-2.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@google-cloud/bigquery": "^5.5.0",
|
|
22
22
|
"@google-cloud/common": "^3.6.0",
|
|
23
|
-
"@malloydata/malloy": "^0.0.11-
|
|
23
|
+
"@malloydata/malloy": "^0.0.11-dev221202180154",
|
|
24
24
|
"gaxios": "^4.2.0"
|
|
25
25
|
}
|
|
26
26
|
}
|