From f9985ae8d1243836fa94f0f6539f964416fc63d1 Mon Sep 17 00:00:00 2001 From: viragtripathi <15679776+viragtripathi@users.noreply.github.com> Date: Wed, 15 Apr 2020 15:11:13 -0400 Subject: [PATCH] Snowflake example (#16) * Snowflake example Snowflake example * Gears execution for WB with snowflake RedisGears Write-Behind recipe for snowflake database --- examples/snowflake/README.md | 6 ++++++ examples/snowflake/example.py | 39 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 examples/snowflake/README.md create mode 100644 examples/snowflake/example.py diff --git a/examples/snowflake/README.md b/examples/snowflake/README.md new file mode 100644 index 0000000..08078e8 --- /dev/null +++ b/examples/snowflake/README.md @@ -0,0 +1,6 @@ +## Running the recipe +You can use [this utility](https://github.com/RedisGears/RedisGears/blob/master/recipes/gears.py) to send a RedisGears Write-Behind or Write-Through recipe for execution. For example, run this repository's [example.py recipe](https://github.com/rgsync/examples/snowflake/example.py) and install its dependencies with the following command: + +```bash +python gears.py --host --port --password examples/snowflake/example.py REQUIREMENTS rgsync snowflake-sqlalchemy +``` diff --git a/examples/snowflake/example.py b/examples/snowflake/example.py new file mode 100644 index 0000000..2db79f5 --- /dev/null +++ b/examples/snowflake/example.py @@ -0,0 +1,39 @@ +from rgsync import RGWriteBehind, RGWriteThrough +from rgsync.Connectors import SnowflakeSqlConnector, SnowflakeSqlConnection + +''' +Create Snowflake connection object +The connection object will be translated to snowflake://:@/ +''' +connection = SnowflakeSqlConnection('', '', '', '') + +''' +Create Snowflake person1 connector +persons - Snowflake table to put the data +id - primary key +''' +personsConnector = SnowflakeSqlConnector(connection, 'person1', 'id') + +personsMappings = { + 'first_name':'first', + 'last_name':'last', + 'age':'age' +} + +RGWriteBehind(GB, keysPrefix='person', mappings=personsMappings, connector=personsConnector, name='PersonsWriteBehind', version='99.99.99') + +RGWriteThrough(GB, keysPrefix='__', mappings=personsMappings, connector=personsConnector, name='PersonsWriteThrough', version='99.99.99') + +''' +Create Snowflake car connector +car - Snowflake table to put the data +license - primary key +''' +carsConnector = SnowflakeSqlConnector(connection, 'car', 'license') + +carsMappings = { + 'license':'license', + 'color':'color' +} + +RGWriteBehind(GB, keysPrefix='car', mappings=carsMappings, connector=carsConnector, name='CarsWriteBehind', version='99.99.99')