From 93412d3c9e0ca32944d6e88e6cb222dd42364eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Arroyo=20Torrens?= Date: Wed, 25 Oct 2023 08:31:56 +0200 Subject: [PATCH 1/2] set bigquery client timeout for deploy --- clouds/bigquery/common/run-script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clouds/bigquery/common/run-script.js b/clouds/bigquery/common/run-script.js index 8378eae9c..dead9ab52 100755 --- a/clouds/bigquery/common/run-script.js +++ b/clouds/bigquery/common/run-script.js @@ -14,7 +14,7 @@ const options = { }; const bar = new cliProgress.SingleBar(options, cliProgress.Presets.shades_classic); -const client = new BigQuery({ projectId: `${BQ_PROJECT}` }); +const client = new BigQuery({ projectId: `${BQ_PROJECT}`, timeout: 600000 }); async function runQueries (queries) { const query_options = { 'timeoutMs' : 120000 }; From 68598186c67db0144840af7201ecc1db2ff0c0c6 Mon Sep 17 00:00:00 2001 From: Valentin de la Cruz Barquero <6054336+vdelacruzb@users.noreply.github.com> Date: Thu, 28 Dec 2023 16:16:09 +0100 Subject: [PATCH 2/2] fix(bq|h3): fix broken reference in H3_POLYFILL_TABLE (#459) --- .../modules/sql/h3/H3_POLYFILL_TABLE.sql | 2 +- .../modules/test/h3/H3_POLYFILL_TABLE.test.js | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/clouds/bigquery/modules/sql/h3/H3_POLYFILL_TABLE.sql b/clouds/bigquery/modules/sql/h3/H3_POLYFILL_TABLE.sql index 846d3feb6..e0c0df18b 100644 --- a/clouds/bigquery/modules/sql/h3/H3_POLYFILL_TABLE.sql +++ b/clouds/bigquery/modules/sql/h3/H3_POLYFILL_TABLE.sql @@ -29,7 +29,7 @@ AS """ return 'CREATE TABLE `' + output_table + '` CLUSTER BY (h3) AS\\n' + 'WITH __input AS (' + input_query + '),\\n' + '__cells AS (SELECT h3, i.* FROM __input AS i,\\n' + - 'UNNEST(`@@BQ_DATASET@@.__H3_POLYFILL_INIT`(geom,`@@BQ_DATASET@@.__H3_POLYFILL_INIT_Z`(geom,' + resolution + '))) AS parent,\\n' + + 'UNNEST(`@@BQ_DATASET@@.__H3_POLYFILL_INIT_BBOX`(geom,`@@BQ_DATASET@@.__H3_POLYFILL_INIT_Z`(geom,' + resolution + '))) AS parent,\\n' + 'UNNEST(`@@BQ_DATASET@@.H3_TOCHILDREN`(parent,' + resolution + ')) AS h3)\\n' + 'SELECT * EXCEPT (geom) FROM __cells\\n' + 'WHERE ' + containmentFunction + '(geom, `' + cellFunction + '`(h3));' diff --git a/clouds/bigquery/modules/test/h3/H3_POLYFILL_TABLE.test.js b/clouds/bigquery/modules/test/h3/H3_POLYFILL_TABLE.test.js index 9675f27f7..13e8d8e04 100644 --- a/clouds/bigquery/modules/test/h3/H3_POLYFILL_TABLE.test.js +++ b/clouds/bigquery/modules/test/h3/H3_POLYFILL_TABLE.test.js @@ -2,6 +2,24 @@ const { runQuery } = require('../../../common/test-utils'); const BQ_DATASET = process.env.BQ_DATASET; +test('H3_POLYFILL_TABLE should work', async () => { + output_table_name = 'h3_polyfill_table_geom_output' + let query = `DROP TABLE IF EXISTS \`@@BQ_DATASET@@.${output_table_name}\`; + CALL \`@@BQ_DATASET@@.H3_POLYFILL_TABLE\`( + 'SELECT ST_GEOGFROMTEXT("POLYGON ((-3.71219873428345 40.413365349070865, -3.7144088745117 40.40965661286395, -3.70659828186035 40.409525904775634, -3.71219873428345 40.413365349070865))") as geom', + 9, 'center', + '@@BQ_DATASET@@.${output_table_name}' + )`; + await runQuery(query); + + const rows = await runQuery(`SELECT * FROM \`@@BQ_DATASET@@.${output_table_name}\``); + expect(rows.length).toEqual(1); + expect(rows[0].h3).toEqual('89390cb1b4bffff'); + + query = `DROP TABLE IF EXISTS \`@@BQ_DATASET@@.${output_table_name}\``; + await runQuery(query); +}); + test('H3_POLYFILL_TABLE should generate the correct query', async () => { const query = `SELECT \`@@BQ_DATASET@@.__H3_POLYFILL_QUERY\`( 'SELECT geom, name, value FROM \`..\`', @@ -13,7 +31,7 @@ test('H3_POLYFILL_TABLE should generate the correct query', async () => { expect(rows[0].output).toEqual(`CREATE TABLE \`..\` CLUSTER BY (h3) AS WITH __input AS (SELECT geom, name, value FROM \`..
\`), __cells AS (SELECT h3, i.* FROM __input AS i, -UNNEST(\`@@BQ_DATASET@@.__H3_POLYFILL_INIT\`(geom,\`@@BQ_DATASET@@.__H3_POLYFILL_INIT_Z\`(geom,12))) AS parent, +UNNEST(\`@@BQ_DATASET@@.__H3_POLYFILL_INIT_BBOX\`(geom,\`@@BQ_DATASET@@.__H3_POLYFILL_INIT_Z\`(geom,12))) AS parent, UNNEST(\`@@BQ_DATASET@@.H3_TOCHILDREN\`(parent,12)) AS h3) SELECT * EXCEPT (geom) FROM __cells WHERE ST_INTERSECTS(geom, \`@@BQ_DATASET@@.H3_CENTER\`(h3));`.replace(/@@BQ_DATASET@@/g, BQ_DATASET));