Skip to content

Commit 8496ef7

Browse files
added snowflake services to their own folder
1 parent 11e008f commit 8496ef7

File tree

11 files changed

+906
-0
lines changed

11 files changed

+906
-0
lines changed
File renamed without changes.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
title: Cross-Database Resource Sharing
3+
description: Get started with cross-database resource sharing in the Snowflake emulator
4+
---
5+
6+
{{< preview-notice >}}
7+
8+
## Introduction
9+
10+
Snowflake data providers can easily share data from various databases using secure views. These views can include schemas, tables, and other views from one or more databases, as long as they're part of the same account.
11+
12+
The Snowflake emulator supports cross-database resource sharing, allowing you to share a secure view that references objects from multiple databases. This guide walks you through the process of creating databases, schemas, tables, and views, and sharing them with other databases.
13+
14+
## Getting started
15+
16+
This guide is designed for users new to cross-database resource sharing and assumes basic knowledge of SQL and Snowflake. Start your Snowflake emulator and connect to the Snowflake emulator using an SQL client.
17+
18+
In this guide, we'll walk through a series of Snowflake SQL statements to create databases, schemas, tables, views, and a share.
19+
20+
### Create databases
21+
22+
Create three databases to represent the three different organizations that will share resources. In this example, we'll create databases for `db_name1`, `db_name2`, and `db_name3`.
23+
24+
```sql
25+
CREATE DATABASE db_name1_actual;
26+
CREATE DATABASE db_name2_actual;
27+
CREATE DATABASE db_name3_actual;
28+
```
29+
30+
### Create schemas
31+
32+
Create a schema in each database to represent the shared resources. In this example, you can create a schema called `sch` in each database.
33+
34+
```sql
35+
CREATE SCHEMA db_name1_actual.sch;
36+
CREATE SCHEMA db_name2_actual.sch;
37+
CREATE SCHEMA db_name3_actual.sch;
38+
```
39+
40+
### Create tables
41+
42+
Create a table in each schema to represent the shared resources. In this example, you can create a table called `table1` in `db_name1_actual.sch`, `table2` in `db_name2_actual.sch`, and `table3` in `db_name3_actual.sch`.
43+
44+
```sql
45+
CREATE TABLE db_name1_actual.sch.table1 (id INT);
46+
CREATE TABLE db_name2_actual.sch.table2 (id INT);
47+
CREATE TABLE db_name3_actual.sch.table3 (id INT);
48+
```
49+
50+
### Insert Data into Tables
51+
52+
You can now insert data into the tables to represent the shared resources. In this example, we'll insert a single row into each table.
53+
54+
```sql
55+
INSERT INTO db_name1_actual.sch.table1 (id) VALUES (1);
56+
INSERT INTO db_name2_actual.sch.table2 (id) VALUES (2);
57+
INSERT INTO db_name3_actual.sch.table3 (id) VALUES (3);
58+
```
59+
60+
### Create Views
61+
62+
You can create a view `view1` based on `table1` in `db_name1_actual`.
63+
64+
```sql
65+
CREATE VIEW db_name1_actual.sch.view1 AS SELECT * FROM db_name1_actual.sch.table1;
66+
```
67+
68+
### Create Secure View
69+
70+
You can creates a secure view `view3` in `db_name3_actual.sch` by joining data from different tables.
71+
72+
```sql
73+
CREATE SECURE VIEW db_name3_actual.sch.view3 AS
74+
SELECT view1.id AS View1Id, table2.id AS table2id, table3.id AS table3id
75+
FROM db_name1_actual.sch.view1 view1, db_name2_actual.sch.table2 table2, db_name3_actual.sch.table3 table3;
76+
```
77+
78+
### Create Share and Grant Permissions
79+
80+
You can create a share `s_actual` and grant usage permissions on the `db_name3_actual` database and its schema.
81+
82+
```sql
83+
CREATE SHARE s_actual;
84+
GRANT USAGE ON DATABASE db_name3_actual TO SHARE s_actual;
85+
GRANT USAGE ON SCHEMA db_name3_actual.sch TO SHARE s_actual;
86+
```
87+
88+
### Query Data from Secure View
89+
90+
You can now query data from the secure view `view3` in `db_name3_actual.sch`.
91+
92+
```sql
93+
SELECT * FROM db_name3_actual.sch.view3;
94+
```
95+
96+
The expected output is:
97+
98+
```plaintext
99+
(1, 2, 3)
100+
```
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: Dynamic Tables
3+
description: Get started with Dynamic Tables in LocalStack for Snowflake
4+
---
5+
6+
{{< preview-notice >}}
7+
8+
## Introduction
9+
10+
Snowflake Dynamic Tables enable a background process to continuously load new data from sources into the table, supporting both delta and full load operations. A dynamic table automatically updates to reflect query results, removing the need for a separate target table and custom code for data transformation. This table is kept current through regularly scheduled refreshes by an automated process.
11+
12+
The Snowflake emulator supports Dynamic tables, allowing you to create and manage Dynamic tables locally. The following operations are supported:
13+
14+
* [`CREATE DYNAMIC TABLE`](https://docs.snowflake.com/en/sql-reference/sql/create-dynamic-table)
15+
* [`DROP DYNAMIC TABLE`](https://docs.snowflake.com/en/sql-reference/sql/drop-dynamic-table)
16+
17+
## Getting started
18+
19+
This guide is designed for users new to Dynamic tables and assumes basic knowledge of SQL and Snowflake. Start your Snowflake emulator and connect to it using an SQL client in order to execute the queries further below.
20+
21+
In this guide, you will create a table, create a dynamic table, insert data into the table, and query the dynamic table.
22+
23+
### Create a table
24+
25+
You can create a table using the `CREATE TABLE` statement. Run the following query to create a table:
26+
27+
```sql
28+
CREATE TABLE example_table_name (id int, name text);
29+
```
30+
31+
The output should be:
32+
33+
```sql
34+
+-----------------------------------------------+
35+
| status |
36+
| ----------------------------------------------+
37+
| Table EXAMPLE_TABLE_NAME successfully created.|
38+
+-----------------------------------------------+
39+
```
40+
41+
### Create a dynamic table
42+
43+
You can create a dynamic table using the `CREATE DYNAMIC TABLE` statement. Run the following query to create a dynamic table:
44+
45+
```sql
46+
CREATE OR REPLACE DYNAMIC TABLE t_12345
47+
TARGET_LAG = '1 minute' WAREHOUSE = 'test' REFRESH_MODE = auto INITIALIZE = on_create
48+
AS SELECT id, name FROM example_table_name;
49+
```
50+
51+
The output should be:
52+
53+
```sql
54+
+-----------------------------------------------+
55+
| result |
56+
| ----------------------------------------------+
57+
Dynamic table T_12345 successfully created. |
58+
+-----------------------------------------------+
59+
```
60+
61+
### Insert data into the table
62+
63+
You can insert data into the table using the `INSERT INTO` statement. Run the following query to insert data into the table:
64+
65+
```sql
66+
INSERT INTO example_table_name(id, name) VALUES (1, 'foo'), (2, 'bar');
67+
```
68+
69+
The output should be:
70+
71+
```sql
72+
| count |
73+
| -----+ |
74+
| 2 |
75+
```
76+
77+
### Query the dynamic table
78+
79+
You can query the dynamic table using the `SELECT` statement. Run the following query to query the dynamic table:
80+
81+
```sql
82+
SELECT * FROM t_12345;
83+
```
84+
85+
The output should be:
86+
87+
```sql
88+
+----+------+
89+
| ID | NAME |
90+
| ---+------+
91+
| 1 | foo |
92+
| 2 | bar |
93+
+----+------+
94+
```
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: Hybrid Tables
3+
description: Get started with Hybrid Tables in LocalStack for Snowflake
4+
---
5+
6+
{{< preview-notice >}}
7+
8+
## Introduction
9+
10+
Snowflake Hybrid tables, also known as Unistore hybrid tables, support fast, single-row operations by enforcing unique constraints for required primary keys and including indexes to speed up data retrieval. These tables are designed to optimize support for both analytical and transactional workloads simultaneously, underpinning Snowflake's Unistore architecture.
11+
12+
The Snowflake emulator supports Hybrid tables, allowing you to create and manage Hybrid tables locally. The following operations are supported:
13+
14+
* [`CREATE HYBRID TABLE`](https://docs.snowflake.com/en/sql-reference/sql/create-hybrid-table)
15+
* [`DROP HYBRID TABLE`](https://docs.snowflake.com/en/sql-reference/sql/drop-hybrid-table)
16+
* [`SHOW HYBRID TABLES`](https://docs.snowflake.com/en/sql-reference/sql/show-hybrid-tables)
17+
18+
## Getting started
19+
20+
This guide is designed for users new to Hybird tables and assumes basic knowledge of SQL and Snowflake. Start your Snowflake emulator and connect to it using an SQL client in order to execute the queries further below.
21+
22+
In this guide, you will create a Hybrid table, display the Hybrid tables, and drop the Hybrid table.
23+
24+
### Create a Hybrid table
25+
26+
You can create a Hybrid table using the `CREATE HYBRID TABLE` statement. In this example, you can create a Hybrid table called `test-table`:
27+
28+
```sql
29+
CREATE HYBRID TABLE "test-table"(id int, name TEXT, PRIMARY KEY(id));
30+
```
31+
32+
The output should be:
33+
34+
```sql
35+
+------------------------------------------+
36+
| status |
37+
|------------------------------------------|
38+
| Table "test-table" successfully created. |
39+
+------------------------------------------+
40+
```
41+
42+
### Show Hybrid tables
43+
44+
You can display the Hybrid tables using the `SHOW HYBRID TABLES` statement:
45+
46+
```sql
47+
SHOW HYBRID TABLES LIKE 'test-table';
48+
```
49+
50+
The output should be:
51+
52+
```sql
53+
+-----------------------------------------------------------------------------------------------------+
54+
created_on |name |database_name|schema_name|comment|rows|bytes|owner |owner_role_type|
55+
-----------------------+----------+-------------+-----------+-------+----+-----+------+---------------+
56+
1970-01-01 05:30:00.000|test-table|TEST |PUBLIC | |1000| 1000|PUBLIC|ROLE |
57+
+-----------------------------------------------------------------------------------------------------+
58+
```
59+
60+
### Drop Hybrid table
61+
62+
You can drop the Hybrid table using the `DROP HYBRID TABLE` statement:
63+
64+
```sql
65+
DROP TABLE "test-table";
66+
```
67+
68+
The output should be:
69+
70+
```sql
71+
+------------------------------------------+
72+
| status |
73+
| -----------------------------------------+
74+
| TEST-TABLE successfully dropped. |
75+
+------------------------------------------+
76+
```
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
title: Iceberg Tables
3+
description:
4+
---
5+
6+
{{< preview-notice >}}
7+
8+
## Introduction
9+
10+
Iceberg tables uses [Apache Iceberg](https://iceberg.apache.org/) open table format specification to provide an abstraction layer on data files stored in open formats. Iceberg tables for Snowflake offer schema evolution, partitioning, and snapshot isolation to manage the table data efficiently.
11+
12+
The Snowflake emulator supports Iceberg tables, allowing you to create and manage Iceberg tables locally. You can use Iceberg tables to query data in Snowflake tables using the Iceberg table format by using external volumes, with data stored in local/remote S3 buckets.
13+
14+
## Getting started
15+
16+
This guide is designed for users new to Iceberg tables and assumes basic knowledge of SQL and Snowflake. Start your Snowflake emulator and connect to it using an SQL client in order to execute the queries further below.
17+
18+
In this guide, you will create an external volume, and an Iceberg table to store and query data using the Iceberg table format.
19+
20+
### Create an S3 bucket
21+
22+
You can create a local S3 bucket using the `mb` command with the `awslocal` CLI.
23+
24+
```bash
25+
$ awslocal s3 mb s3://test-bucket
26+
```
27+
28+
### Create an external volume
29+
30+
You can create an external volume using the `CREATE OR REPLACE EXTERNAL VOLUME` statement. The external volume is used to define the location of the files that Iceberg will use to store the table data.
31+
32+
```sql
33+
CREATE OR REPLACE EXTERNAL VOLUME test_volume
34+
STORAGE_LOCATIONS = (
35+
(
36+
NAME = 'aws-s3-test'
37+
STORAGE_PROVIDER = 'S3'
38+
STORAGE_BASE_URL = 's3://test-bucket/'
39+
STORAGE_AWS_ROLE_ARN = 'arn:aws:iam::000000000000:role/s3-role'
40+
ENCRYPTION=(TYPE='AWS_SSE_S3')
41+
)
42+
)
43+
```
44+
45+
### Grant access to Snowflake role
46+
47+
You can grant access to the Snowflake role using the `GRANT USAGE ON EXTERNAL VOLUME` statement.
48+
49+
```sql
50+
GRANT USAGE ON EXTERNAL VOLUME test_volume TO ROLE PUBLIC
51+
```
52+
53+
### Create Iceberg table
54+
55+
You can create an Iceberg table using the `CREATE ICEBERG TABLE` statement. The Iceberg table is used to define the schema and location of the table data.
56+
57+
```sql
58+
CREATE ICEBERG TABLE test_table (c1 TEXT)
59+
CATALOG='SNOWFLAKE', EXTERNAL_VOLUME='test_volume', BASE_LOCATION='test'
60+
```
61+
62+
### Insert and select data
63+
64+
You can insert and select data from the Iceberg table using the `INSERT INTO` and `SELECT` statements.
65+
66+
```sql
67+
INSERT INTO test_table(c1) VALUES ('test'), ('foobar')
68+
SELECT * FROM test_table
69+
```
70+
71+
The output should be:
72+
73+
```plaintext
74+
+------+
75+
| C1 |
76+
|------|
77+
| test |
78+
| foobar |
79+
+------+
80+
```
81+
82+
You can also list the content of the S3 bucket:
83+
84+
{{< command >}}
85+
$ awslocal s3 ls --recursive s3://test-bucket/
86+
{{< / command >}}

0 commit comments

Comments
 (0)