Skip to content
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

Merged
merged 49 commits into from
Jan 20, 2017
Merged

adapters: postgres & redshift #259

merged 49 commits into from
Jan 20, 2017

Conversation

cmcarthur
Copy link
Member

WIP

Copy link
Contributor

@drewbanin drewbanin left a 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):
Copy link
Contributor

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)
Copy link
Contributor

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.')
Copy link
Contributor

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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is so good

Copy link
Contributor

@drewbanin drewbanin left a 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
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's noqa

Copy link
Member Author

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):
Copy link
Contributor

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 "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this fail silently?

Copy link
Member Author

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

Copy link
Member Author

@cmcarthur cmcarthur Jan 16, 2017

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

Copy link
Contributor

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):
Copy link
Contributor

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 = {
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Member Author

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?

Copy link
Contributor

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

Copy link
Member Author

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
Copy link
Contributor

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

@drewbanin
Copy link
Contributor

Great work @cmcarthur -- merge at your convenience

@cmcarthur cmcarthur merged commit 172c7ce into development Jan 20, 2017
@cmcarthur cmcarthur deleted the adapters/initial branch January 20, 2017 19:00
iknox-fa pushed a commit that referenced this pull request Feb 8, 2022
automatic commit by git-black, original commits:
  172c7ce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants