Giter Site home page Giter Site logo

createdbfromshare's Introduction

CreateDBFromShare

In Snowflake, data sharing is region specific, i.e. you can only share data between accounts in the same region. If you want to share data across regions, you first have to create a local copy of that database, and then replicate that local copy into the target region.

CreateDBFromShare is a Snowflake stored procedure that copies tables from a source database & schema to a target database and schema. Source database & schema and target database and schema are provided via command line parameters.

The target schema will be created in case it doesn't exist. If a table in the source doesn't exist, it first will be created.

One main objective was to ensure that changes to existing tables will not result cause queries to fail that run against a shared database of the replicated copy. Therefore, all changes to existing tables must be atomic.

The following modifications to existing tables are supported

  1. add a column
  2. remove a column
  3. rename a column (implemented via adding and removing a column)

Changing the datatype of a column is not supported

The procedure tracks its progress in an array of strings. That "log" along with a status, date and time of execution, and session id is being stored in the log table with every run.

Setup

Setup of a test environment requires a couple different Snowflake accounts.

  1. Originator: This is the Snowflake account that originally shares a dataset via Snowflake Secure Data Sharing.
  2. Consumer/Replication Source: This is the Snowflake account that consumes the dataset from the Provider. Secondly, this account creates a local copy and replicates the dataset to the replication target. Please review Snowflake's documentation for setting up replication
  3. Replication Target/Provider: This is the Snowflake account that receives the replicated copy from the replication source. It also is the account that shares the dataset, for instance into a VPS environment

Setup on Consumer/Replication Source

  1. Create a new database that will host the local copy for the shared dataset. To do so, open file setup/create_db.sql (or create the database directly in a Snowflake worksheet), update the database name and run all commands.
  2. Create all metadata objects via the files in the metadata directory. The files need to be executed in sequence indicated by the file prefix. Be sure to set the session context to the database you hae created in the previous step. When you get an error message while creating sp_copy_from_shared_db, scroll to the end of the file and then run it again.

Setup on Replication Target/Provider

createdbfromshare's People

Contributors

robertfehrmann avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Forkers

kgtdbx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.