Merge pull request #1002 from influxdata/flux/snowflake

Adds Snowflake support to SQL package
pull/971/head^2
Scott Anderson 2020-05-04 08:52:47 -06:00 committed by GitHub
commit b05c5da4bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 60 additions and 13 deletions

View File

@ -201,7 +201,7 @@ pgHost = secrets.get(key: "POSTGRES_HOST")
t1 = sql.from( t1 = sql.from(
driverName: "postgres", driverName: "postgres",
dataSourceName: "postgresql://${pgUser}:${pgPass}@${pgHost}", 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") t2 = from(bucket: "example-bucket")

View File

@ -221,7 +221,7 @@ pgHost = secrets.get(key: "POSTGRES_HOST")
t1 = sql.from( t1 = sql.from(
driverName: "postgres", driverName: "postgres",
dataSourceName: "postgresql://${pgUser}:${pgPass}@${pgHost}", 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") t2 = from(bucket: "example-bucket")

View File

@ -4,7 +4,7 @@ seotitle: Query SQL data sources with InfluxDB
list_title: Query SQL data list_title: Query SQL data
description: > description: >
The Flux `sql` package provides functions for working with SQL data sources. 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] v2.0/tags: [query, flux, sql]
menu: menu:
v2_0: 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. 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 [`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/), 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 [Snowflake](https://www.snowflake.com/), and [SQLite](https://www.sqlite.org/index.html),
dashboards, tasks, and other operations. and use the results with InfluxDB dashboards, tasks, and other operations.
- [Query a SQL data source](#query-a-sql-data-source) - [Query a SQL data source](#query-a-sql-data-source)
- [Join SQL data with data in InfluxDB](#join-sql-data-with-data-in-influxdb) - [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 %}} {{% code-tabs %}}
[PostgreSQL](#) [PostgreSQL](#)
[MySQL](#) [MySQL](#)
[Snowflake](#)
[SQLite](#) [SQLite](#)
{{% /code-tabs %}} {{% /code-tabs %}}
@ -81,6 +82,18 @@ sql.from(
``` ```
{{% /code-tab-content %}} {{% /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 %}} {{% code-tab-content %}}
```js ```js
// NOTE: InfluxDB OSS and InfluxDB Cloud do not have access to // NOTE: InfluxDB OSS and InfluxDB Cloud do not have access to

View File

@ -18,7 +18,7 @@ related:
--- ---
SQL Flux functions provide tools for working with data in SQL databases such as 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: Import the `sql` package:
```js ```js

View File

@ -37,6 +37,7 @@ The following drivers are available:
- mysql - mysql
- postgres - postgres
- snowflake
- sqlite3 _Does not work with InfluxDB OSS or InfluxDB Cloud. More information [below](#query-an-sqlite-database)._ - sqlite3 _Does not work with InfluxDB OSS or InfluxDB Cloud. More information [below](#query-an-sqlite-database)._
### dataSourceName ### dataSourceName
@ -53,6 +54,11 @@ postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full
# MySQL Driver DSN # MySQL Driver DSN
username:password@tcp(localhost:3306)/dbname?param=value username:password@tcp(localhost:3306)/dbname?param=value
# Snowflake Driver DSNs
username[:password]@accountname/dbname/schemaname?param1=value1&paramN=valueN
username[:password]@accountname/dbname?param1=value1&paramN=valueN
username[:password]@hostname:port/dbname/schemaname?account=<your_account>&param1=value1&paramN=valueN
# SQLite Driver DSN # SQLite Driver DSN
file:/path/to/test.db?cache=shared&mode=ro file:/path/to/test.db?cache=shared&mode=ro
``` ```
@ -71,7 +77,7 @@ import "sql"
sql.from( sql.from(
driverName: "mysql", driverName: "mysql",
dataSourceName: "user:password@tcp(localhost:3306)/db", dataSourceName: "user:password@tcp(localhost:3306)/db",
query:"SELECT * FROM ExampleTable" query: "SELECT * FROM example_table"
) )
``` ```
@ -82,7 +88,18 @@ import "sql"
sql.from( sql.from(
driverName: "postgres", driverName: "postgres",
dataSourceName: "postgresql://user:password@localhost", 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( sql.from(
driverName: "sqlite3", driverName: "sqlite3",
dataSourceName: "file:/path/to/test.db?cache=shared&mode=ro", dataSourceName: "file:/path/to/test.db?cache=shared&mode=ro",
query:"SELECT * FROM ExampleTable" query: "SELECT * FROM example_table"
) )
``` ```

View File

@ -20,7 +20,7 @@ import "sql"
sql.to( sql.to(
driverName: "mysql", driverName: "mysql",
dataSourceName: "username:password@tcp(localhost:3306)/dbname?param=value", dataSourceName: "username:password@tcp(localhost:3306)/dbname?param=value",
table: "ExampleTable", table: "example_table",
batchSize: 10000 batchSize: 10000
) )
``` ```
@ -36,6 +36,7 @@ The following drivers are available:
- mysql - mysql
- postgres - postgres
- snowflake
- sqlite3 _Does not work with InfluxDB OSS or InfluxDB Cloud. More information [below](#write-data-to-an-sqlite-database)._ - sqlite3 _Does not work with InfluxDB OSS or InfluxDB Cloud. More information [below](#write-data-to-an-sqlite-database)._
### dataSourceName ### dataSourceName
@ -52,6 +53,11 @@ postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full
# MySQL Driver DSN # MySQL Driver DSN
username:password@tcp(localhost:3306)/dbname?param=value username:password@tcp(localhost:3306)/dbname?param=value
# Snowflake Driver DSNs
username[:password]@accountname/dbname/schemaname?param1=value1&paramN=valueN
username[:password]@accountname/dbname?param1=value1&paramN=valueN
username[:password]@hostname:port/dbname/schemaname?account=<your_account>&param1=value1&paramN=valueN
# SQLite Driver DSN # SQLite Driver DSN
file:/path/to/test.db?cache=shared&mode=rw file:/path/to/test.db?cache=shared&mode=rw
``` ```
@ -80,7 +86,7 @@ import "sql"
sql.to( sql.to(
driverName: "mysql", driverName: "mysql",
dataSourceName: "user:password@tcp(localhost:3306)/db", dataSourceName: "user:password@tcp(localhost:3306)/db",
table: "ExampleTable" table: "example_table"
) )
``` ```
@ -91,7 +97,18 @@ import "sql"
sql.to( sql.to(
driverName: "postgres", driverName: "postgres",
dataSourceName: "postgresql://user:password@localhost", 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( sql.to(
driverName: "sqlite3", driverName: "sqlite3",
dataSourceName: "file:/path/to/test.db?cache=shared&mode=rw", dataSourceName: "file:/path/to/test.db?cache=shared&mode=rw",
table: "ExampleTable" table: "example_table"
) )
``` ```