-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adapters: postgres & redshift #259
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great -- going to take it for a spin locally
@@ -0,0 +1,2 @@ | |||
class ValidationException(Exception): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@classmethod | ||
def execute_model(cls, project, target, model): | ||
schema_helper = Schema(project, target) | ||
parts = re.split(r'-- (DBT_OPERATION .*)', model.compiled_contents) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're probably going to rethink how DBT_OPERATION
works in the future. I think it's fine to leave this how it is for now, but let's definitely refrain from copying this logic into future adapters!
@@ -131,6 +134,7 @@ def parse_args(args): | |||
p = argparse.ArgumentParser(prog='dbt: data build tool', formatter_class=argparse.RawTextHelpFormatter) | |||
p.add_argument('--version', action='version', version=dbt.version.get_version_information(), help="Show version information") | |||
p.add_argument('-d', '--debug', action='store_true', help='Display debug logging during dbt execution. Useful for debugging and making bug reports.') | |||
p.add_argument('-S', '--strict', action='store_true', help='Run schema validations at runtime. This will surface bugs in dbt, but may incur a speed penalty.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
handle.commit() | ||
return status | ||
return get_adapter(target).execute_model( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is so good
…n case of multiple invocations in one python process
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read through this PR... there's a lot going on here and it's looking great to me. I'm going to pull this locally and run it against pg/redshift -- I'm assuming you've tested a good amount against Snowflake. 👍 👍 👍 👍 👍 👍
|
||
test-unit: | ||
@echo "Unit test run starting..." | ||
tox -e unit-py27,unit-py35 | ||
@time docker-compose run test tox -e unit-py27,unit-py35,pep8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been meaning to talk to you about this. The reason these tests didn't previously use Docker is because we wanted to run CI tests on Windows (via Appveyor). My understanding is that when these tests now run on Appveyor, we're not actually testing if the code works on Windows. Rather, we're testing if it runs in Docker on Windows. Is that what's happening here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not exactly right, since circle & appveyor don't use the Makefile to run tests -- they just call tox directly. The reason to do it this way is so that the tests always run in the same environment during development.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok makes sense, thanks
schema.""" | ||
|
||
|
||
@contextmanager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is super cool
update "{schema}"."{table}" set "{tmp_column}" = "{old_column}"; | ||
alter table "{schema}"."{table}" drop column "{old_column}" cascade; | ||
alter table "{schema}"."{table}" rename column "{tmp_column}" to "{old_column}"; | ||
""".format(**opts).strip() # noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's noqa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tells pep8 to skip this line / block
from dbt.adapters.postgres import PostgresAdapter | ||
|
||
|
||
class RedshiftAdapter(PostgresAdapter): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
result['handle'] = handle | ||
result['state'] = 'open' | ||
except snowflake.connector.errors.Error as e: | ||
logger.debug("Got an error when attempting to open a snowflake " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this fail silently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might be the case, yeah. You and I should discuss the ideal functionality here. Related: #253
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this does something sane now:
(hosted-test3) ✔ ~/git/hosted-test [master|✚ 1]
08:31 $ dbt run --profile postgres-test
Compiled 1 models, 0 data tests, 0 schema tests, 0 archives, 0 analyses
Loading dependency graph file
Connecting to postgres.
ERROR: Could not connect to the target database. Try `dbt debug` for more information.
FATAL: password authentication failed for user "root"
(hosted-test3) ✘-1 ~/git/hosted-test [master|✚ 1]
08:32 $ echo $?
1
(hosted-test3) ✔ ~/git/hosted-test [master|✚ 1]
08:32 $ dbt run --profile snowflake-test
Compiled 1 models, 0 data tests, 0 schema tests, 0 archives, 0 analyses
Loading dependency graph file
Connecting to snowflake.
ERROR: Could not connect to the target database. Try `dbt debug` for more information.
250001 (08001): failed to connect to DB: kw27752.snowflakecomputing.com:443, proxies=None:None, proxy_user=None, Incorrect username or password was specified.
(hosted-test3) ✘-1 ~/git/hosted-test [master|✚ 1]
08:32 $ echo $?
1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -82,285 +82,3 @@ def string_type(cls, size): | |||
|
|||
def __repr__(self): | |||
return "<Column {} ({})>".format(self.name, self.data_type) | |||
|
|||
|
|||
class Schema(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗑
@@ -143,7 +143,7 @@ def context(self): | |||
|
|||
target_map = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this file anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still used in two places:
(dbt) ✔ ~/git/dbt [adapters/initial|✔]
16:04 $ git grep dbt.targets
dbt/schema_tester.py:import dbt.targets
dbt/schema_tester.py: return dbt.targets.get_target(target_cfg)
dbt/seeder.py:import dbt.targets
dbt/seeder.py: self.target = dbt.targets.get_target(run_environment)
These two just don't support Snowflake. I just tested this and I got kind of a strange error:
✘-1 ~/git/hosted-test [master|✚ 1]
16:13 $ dbt seed --profile snowflake-test
Encountered an error while reading the project:
ERROR Expected project configuration 'host' was not supplied
Did you set the correct --profile? Using: snowflake-test
Valid profiles:
- hosted-test
- snowflake-test
Encountered an error:
Could not run dbt
I'll work on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated so seed exits with this if run on snowflake:
16:51 $ dbt seed --profile snowflake-test
ERROR: `seed` operation is not supported for snowflake.
@@ -5,7 +5,7 @@ psycopg2==2.6.1 | |||
sqlparse==0.1.19 | |||
networkx==1.11 | |||
csvkit==0.9.1 | |||
paramiko==2.0.1 | |||
sshtunnel==0.0.8.2 | |||
snowplow-tracker==0.7.2 | |||
celery==3.1.23 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
celery
is a dependency of snowplow-tracker
-- do we still need to include it? unsure how it got in the requirements file
|
||
# horrible hack to support snowflake for right now | ||
def transform_sql(self, query): | ||
to_return = query |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's going on here haha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than maintain two of each seed file, I just replaced BIGSERIAL
with BIGINT AUTOINCREMENT
hah.... there's definitely a cleaner way & I didn't spend very much time working on this. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I understand. I was thinking about using an ORM for these seed files. That would make it substantially easier to apply existing integration tests to new adapters. SQLAlchemy has dialect support for postgres/redshift/snowflake, for instance. This works for now though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes a lot of sense, we should do that.
@@ -1,3 +1,4 @@ | |||
set -x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't know about this -- that's cool
Great work @cmcarthur -- merge at your convenience |
automatic commit by git-black, original commits: 172c7ce
WIP