From 34e0d0403f38d9d4da14f6d78e987afde9de2139 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Thu, 30 Apr 2020 17:01:34 -0600 Subject: [PATCH] added snowflake support, resolves #894 --- content/v2.0/get-started.md | 4 +++ .../query-data/flux/calculate-percentages.md | 2 +- .../query-data/flux/mathematic-operations.md | 2 +- content/v2.0/query-data/flux/sql.md | 19 +++++++++++--- .../v2.0/reference/flux/stdlib/sql/_index.md | 2 +- .../v2.0/reference/flux/stdlib/sql/from.md | 23 ++++++++++++++--- content/v2.0/reference/flux/stdlib/sql/to.md | 25 ++++++++++++++++--- 7 files changed, 64 insertions(+), 13 deletions(-) diff --git a/content/v2.0/get-started.md b/content/v2.0/get-started.md index 21ef2a565..dc25fc8f2 100644 --- a/content/v2.0/get-started.md +++ b/content/v2.0/get-started.md @@ -458,6 +458,10 @@ For details, see [Scrape data](/v2.0/write-data/scrape-data/). For information about using the InfluxDB v2 API, `influx` CLI, and client libraries to write data, see [Write data to InfluxDB](/v2.0/write-data/). +#### Demo data +If using **{{< cloud-name "short" >}}**, [add a demo data bucket](/v2.0/write-data/sample-data/demo-data/) +for quick, _free_ access to time series data. + ### Query data Query data using Flux, the UI, and the `influx` command line interface. diff --git a/content/v2.0/query-data/flux/calculate-percentages.md b/content/v2.0/query-data/flux/calculate-percentages.md index 9b594ea0e..123ff0f73 100644 --- a/content/v2.0/query-data/flux/calculate-percentages.md +++ b/content/v2.0/query-data/flux/calculate-percentages.md @@ -201,7 +201,7 @@ pgHost = secrets.get(key: "POSTGRES_HOST") t1 = sql.from( driverName: "postgres", dataSourceName: "postgresql://${pgUser}:${pgPass}@${pgHost}", - query:"SELECT id, name, available FROM exampleTable" + query:"SELECT id, name, available FROM example_table" ) t2 = from(bucket: "example-bucket") diff --git a/content/v2.0/query-data/flux/mathematic-operations.md b/content/v2.0/query-data/flux/mathematic-operations.md index 284657756..69bbb7924 100644 --- a/content/v2.0/query-data/flux/mathematic-operations.md +++ b/content/v2.0/query-data/flux/mathematic-operations.md @@ -221,7 +221,7 @@ pgHost = secrets.get(key: "POSTGRES_HOST") t1 = sql.from( driverName: "postgres", dataSourceName: "postgresql://${pgUser}:${pgPass}@${pgHost}", - query:"SELECT id, name, available FROM exampleTable" + query:"SELECT id, name, available FROM example_table" ) t2 = from(bucket: "example-bucket") diff --git a/content/v2.0/query-data/flux/sql.md b/content/v2.0/query-data/flux/sql.md index b769145ff..0dd7c4908 100644 --- a/content/v2.0/query-data/flux/sql.md +++ b/content/v2.0/query-data/flux/sql.md @@ -4,7 +4,7 @@ seotitle: Query SQL data sources with InfluxDB list_title: Query SQL data description: > The Flux `sql` package provides functions for working with SQL data sources. - Use `sql.from()` to query SQL databases like PostgreSQL and MySQL + Use `sql.from()` to query SQL databases like PostgreSQL, MySQL, Snowflake, and SQLite. v2.0/tags: [query, flux, sql] menu: v2_0: @@ -30,8 +30,8 @@ list_code_example: | The [Flux](/v2.0/reference/flux) `sql` package provides functions for working with SQL data sources. [`sql.from()`](/v2.0/reference/flux/stdlib/sql/from/) lets you query SQL data sources like [PostgreSQL](https://www.postgresql.org/), [MySQL](https://www.mysql.com/), -and [SQLite](https://www.sqlite.org/index.html), and use the results with InfluxDB -dashboards, tasks, and other operations. +[Snowflake](https://www.snowflake.com/), and [SQLite](https://www.sqlite.org/index.html), +and use the results with InfluxDB dashboards, tasks, and other operations. - [Query a SQL data source](#query-a-sql-data-source) - [Join SQL data with data in InfluxDB](#join-sql-data-with-data-in-influxdb) @@ -54,6 +54,7 @@ To query a SQL data source: {{% code-tabs %}} [PostgreSQL](#) [MySQL](#) +[Snowflake](#) [SQLite](#) {{% /code-tabs %}} @@ -81,6 +82,18 @@ sql.from( ``` {{% /code-tab-content %}} +{{% code-tab-content %}} +```js +import "sql" + +sql.from( + driverName: "snowflake", + dataSourceName: "user:password@account/db/exampleschema?warehouse=wh", + query: "SELECT * FROM example_table" +) +``` +{{% /code-tab-content %}} + {{% code-tab-content %}} ```js // NOTE: InfluxDB OSS and InfluxDB Cloud do not have access to diff --git a/content/v2.0/reference/flux/stdlib/sql/_index.md b/content/v2.0/reference/flux/stdlib/sql/_index.md index 51d3d2c9b..2fd8814e0 100644 --- a/content/v2.0/reference/flux/stdlib/sql/_index.md +++ b/content/v2.0/reference/flux/stdlib/sql/_index.md @@ -18,7 +18,7 @@ related: --- SQL Flux functions provide tools for working with data in SQL databases such as -MySQL, PostgreSQL, and SQLite. +MySQL, PostgreSQL, Snowflake, and SQLite. Import the `sql` package: ```js diff --git a/content/v2.0/reference/flux/stdlib/sql/from.md b/content/v2.0/reference/flux/stdlib/sql/from.md index 7e2518a27..3c231cf74 100644 --- a/content/v2.0/reference/flux/stdlib/sql/from.md +++ b/content/v2.0/reference/flux/stdlib/sql/from.md @@ -37,6 +37,7 @@ The following drivers are available: - mysql - postgres +- snowflake - sqlite3 – _Does not work with InfluxDB OSS or InfluxDB Cloud. More information [below](#query-an-sqlite-database)._ ### dataSourceName @@ -53,6 +54,11 @@ postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full # MySQL Driver DSN username:password@tcp(localhost:3306)/dbname?param=value +# Snowflake Driver DSNs +username[:password]@accountname/dbname/schemaname?param1=value1¶mN=valueN +username[:password]@accountname/dbname?param1=value1¶mN=valueN +username[:password]@hostname:port/dbname/schemaname?account=¶m1=value1¶mN=valueN + # SQLite Driver DSN file:/path/to/test.db?cache=shared&mode=ro ``` @@ -71,7 +77,7 @@ import "sql" sql.from( driverName: "mysql", dataSourceName: "user:password@tcp(localhost:3306)/db", - query:"SELECT * FROM ExampleTable" + query: "SELECT * FROM example_table" ) ``` @@ -82,7 +88,18 @@ import "sql" sql.from( driverName: "postgres", dataSourceName: "postgresql://user:password@localhost", - query:"SELECT * FROM ExampleTable" + query: "SELECT * FROM example_table" +) +``` + +### Query a Snowflake database +```js +import "sql" + +sql.from( + driverName: "snowflake", + dataSourceName: "user:password@account/db/exampleschema?warehouse=wh", + query: "SELECT * FROM example_table" ) ``` @@ -101,6 +118,6 @@ import "sql" sql.from( driverName: "sqlite3", dataSourceName: "file:/path/to/test.db?cache=shared&mode=ro", - query:"SELECT * FROM ExampleTable" + query: "SELECT * FROM example_table" ) ``` diff --git a/content/v2.0/reference/flux/stdlib/sql/to.md b/content/v2.0/reference/flux/stdlib/sql/to.md index 4d4552bf2..754fb6e93 100644 --- a/content/v2.0/reference/flux/stdlib/sql/to.md +++ b/content/v2.0/reference/flux/stdlib/sql/to.md @@ -20,7 +20,7 @@ import "sql" sql.to( driverName: "mysql", dataSourceName: "username:password@tcp(localhost:3306)/dbname?param=value", - table: "ExampleTable", + table: "example_table", batchSize: 10000 ) ``` @@ -36,6 +36,7 @@ The following drivers are available: - mysql - postgres +- snowflake - sqlite3 – _Does not work with InfluxDB OSS or InfluxDB Cloud. More information [below](#write-data-to-an-sqlite-database)._ ### dataSourceName @@ -52,6 +53,11 @@ postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full # MySQL Driver DSN username:password@tcp(localhost:3306)/dbname?param=value +# Snowflake Driver DSNs +username[:password]@accountname/dbname/schemaname?param1=value1¶mN=valueN +username[:password]@accountname/dbname?param1=value1¶mN=valueN +username[:password]@hostname:port/dbname/schemaname?account=¶m1=value1¶mN=valueN + # SQLite Driver DSN file:/path/to/test.db?cache=shared&mode=rw ``` @@ -80,7 +86,7 @@ import "sql" sql.to( driverName: "mysql", dataSourceName: "user:password@tcp(localhost:3306)/db", - table: "ExampleTable" + table: "example_table" ) ``` @@ -91,7 +97,18 @@ import "sql" sql.to( driverName: "postgres", dataSourceName: "postgresql://user:password@localhost", - table: "ExampleTable" + table: "example_table" +) +``` + +### Write data to a Snowflake database +```js +import "sql" + +sql.to( + driverName: "snowflake", + dataSourceName: "user:password@account/db/exampleschema?warehouse=wh", + table: "example_table" ) ``` @@ -110,6 +127,6 @@ import "sql" sql.to( driverName: "sqlite3", dataSourceName: "file:/path/to/test.db?cache=shared&mode=rw", - table: "ExampleTable" + table: "example_table" ) ```