This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/csv" | |
"io" | |
"log" | |
"os" | |
) | |
func main () { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/gofiber/fiber/v2" | |
jwtware "github.com/gofiber/jwt/v2" | |
"log" | |
) | |
func main() { | |
// Create new Go Fiber application web server |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Firstname | Lastname | Country | |
---|---|---|---|
Hans | Meier | Germany | |
Franz | Josef | France |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Imports the Google Cloud client library | |
const { BigQuery } = require('@google-cloud/bigquery'); | |
// Defines the location of the dataset and tables | |
const location = 'US'; | |
// Creates a BigQuery client | |
const bigquery = new BigQuery({ | |
// The relative file path to your Service Account key file | |
keyFilename: 'bigquery-sa.json', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Insert a certain set of rows into the passed table | |
* @param {string} datasetId The ID of the parent dataset | |
* @param {string} tableId The ID of the table to insert data in | |
* @returns {Promise<void>} | |
*/ | |
const insertRows = async (datasetId, tableId) => { | |
const rows = [ | |
{ Name: 'Tom', Age: 30 }, | |
{ Name: 'Jane', Age: 32, Weight: 87, IsMagic: true }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Retrieve data from BigQuery | |
* @param {string} projectId The ID of the GCP project the dataset/table is located | |
* @param {string} datasetId The ID of the parent dataset | |
* @param {string} tableId The ID of the table to get data from | |
* @returns {Promise<void>} | |
*/ | |
const getData = async (projectId, datasetId, tableId) => { | |
const query = ` | |
SELECT * from \`${projectId}.${datasetId}.${tableId}\` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
/** | |
const rows = [ | |
// invalid row, there is no "Hello" field in the table schema | |
{ Name: 'Tom', Age: 30, Hello: "string" } | |
], | |
**/ | |
// --> Output of: console.error(JSON.stringify(e.response.insertErrors, null, 2)); | |
[ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const importCSV = async (datasetId, tableId, pathToLocalFile, timePartitioning) => { | |
const metadata = { | |
sourceFormat: 'CSV', | |
// Ignore first row since it contains the column headers | |
skipLeadingRows: 1, | |
schema: { | |
fields: [ | |
{ name: 'date', type: 'DATETIME', mode: 'REQUIRED' }, | |
{ name: 'name', type: 'STRING', mode: 'REQUIRED' }, | |
{ name: 'event', type: 'INT64', mode: 'REQUIRED' }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Run query on BigQuery and print query statistics | |
* @param {string} query The query to run | |
* @param {string} location The location of the dataset | |
* @returns {Promise<void>} | |
*/ | |
const runQueryWithStatistics = async (query, location) => { | |
const options = { | |
query, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- Without Partition --- | |
--- Job Statistics --- | |
┌─────────┬────────────────────────┬──────────┬─────────┐ | |
│ (index) │ Description │ Value │ Unit │ | |
├─────────┼────────────────────────┼──────────┼─────────┤ | |
│ 0 │ 'Cache hit' │ false │ 'Bool' │ | |
│ 1 │ 'Time taken' │ 221 │ 'ms' │ | |
│ 2 │ 'Partitions processed' │ 0 │ 'Count' │ | |
│ 3 │ 'Rows read' │ 73728 │ 'Count' │ | |
│ 4 │ 'Bytes processed' │ 1572864 │ 'Bytes' │ |