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

wrap models using macros #356

Merged
merged 39 commits into from
Apr 5, 2017
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c591815
code cleanup + fix full-refresh opt
drewbanin Mar 26, 2017
3d4d72d
make integration tests actually test flags
drewbanin Mar 26, 2017
f651568
accidently create operations
drewbanin Mar 26, 2017
e080f73
Handle concurrent `DROP ... CASCADE`s in Redshift (#349)
cmcarthur Mar 26, 2017
fe79e07
working with a few rough edges
Mar 26, 2017
da6c467
Fix/full refresh (#350)
drewbanin Mar 27, 2017
f94f455
Merge branch 'development' into feature/already-exists-compilation-co…
drewbanin Mar 27, 2017
7f54175
test that should be green if macro parsing works the right way
Mar 27, 2017
23d42d2
wip
drewbanin Mar 28, 2017
cacf5c9
Merge branch 'feature/already-exists-compilation-context' into contex…
drewbanin Mar 28, 2017
b43be9e
validate macros don't use context vars
drewbanin Mar 28, 2017
ace4b49
fix tests
drewbanin Mar 28, 2017
bc0e1c2
working with a few rough edges
Mar 26, 2017
694d07b
test that should be green if macro parsing works the right way
Mar 27, 2017
c55ff34
inject into jinja with custom extension
drewbanin Mar 26, 2017
8537229
wip
drewbanin Mar 28, 2017
4846515
validate macros don't use context vars
drewbanin Mar 28, 2017
c06ae6d
fix tests
drewbanin Mar 28, 2017
e03f804
Merge branch 'contextless-macros' of github.com:fishtown-analytics/db…
drewbanin Mar 28, 2017
2b3f46e
add test for `target` in macros, disallow target
drewbanin Mar 28, 2017
e2c279b
add license to RTD
drewbanin Mar 28, 2017
ce96825
wip - materialize via macros
drewbanin Mar 29, 2017
5ffe4a5
always release connections at the end of execute_node (#354)
cmcarthur Mar 29, 2017
d907fca
merged development
Mar 30, 2017
ab4d5a3
tests passing
Mar 30, 2017
a266308
integration tests passing, again
Mar 31, 2017
e533b36
unit tests & pep8 passing
Apr 3, 2017
d3d2da5
merge contextless macros branch
Apr 3, 2017
cb2bba4
functional test tweaks
Apr 4, 2017
f1f39c1
remove extra raise
Apr 4, 2017
0b810c6
fix integration tests
Apr 4, 2017
4f663a0
allow global project macros to be referenced without a namespace
Apr 4, 2017
837bff4
handle compilation errors
Apr 4, 2017
0574958
add manifest file
drewbanin Apr 4, 2017
1063500
include global project files in dbt dist
drewbanin Apr 4, 2017
161d70c
Merge pull request #361 from fishtown-analytics/include-global-project
drewbanin Apr 4, 2017
8b59748
rename funcs to adapter
Apr 4, 2017
b7044d9
remove compile task
Apr 4, 2017
2921a00
don't throw compilr error for this/target in macro
drewbanin Apr 5, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- Ignore commented-out schema tests ([#330](https://github.com/fishtown-analytics/dbt/pull/330), [#328](https://github.com/fishtown-analytics/dbt/issues/328))
- Fix run levels ([#343](https://github.com/fishtown-analytics/dbt/pull/343), [#340](https://github.com/fishtown-analytics/dbt/issues/340), [#338](https://github.com/fishtown-analytics/dbt/issues/338))
- Fix concurrency, open a unique transaction per model ([#345](https://github.com/fishtown-analytics/dbt/pull/345), [#336](https://github.com/fishtown-analytics/dbt/issues/336))
- Handle concurrent `DROP ... CASCADE`s in Redshift ([#349](https://github.com/fishtown-analytics/dbt/pull/349))
- Always release connections (use `try .. finally`) ([#354](https://github.com/fishtown-analytics/dbt/pull/354))

### Changes

Expand Down
23 changes: 15 additions & 8 deletions dbt/adapters/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,17 +366,17 @@ def release_connection(cls, profile, name):
def cleanup_connections(cls):
global connections_in_use, connections_available

for name, connection in connections_in_use.items():
if connection.get('state') != 'closed':
logger.debug("Connection '{}' was left open."
.format(name))
else:
logger.debug("Connection '{}' was properly closed."
.format(name))

try:
lock.acquire()

for name, connection in connections_in_use.items():
if connection.get('state') != 'closed':
logger.debug("Connection '{}' was left open."
.format(name))
else:
logger.debug("Connection '{}' was properly closed."
.format(name))

# garbage collect, but don't close them in case someone
# still has a handle
connections_in_use = {}
Expand Down Expand Up @@ -525,3 +525,10 @@ def table_exists(cls, profile, schema, table, model_name=None):
tables = cls.query_for_existing(profile, schema, model_name)
exists = tables.get(table) is not None
return exists

@classmethod
def already_exists(cls, profile, schema, table, model_name=None):
"""
Alias for `table_exists`.
"""
return cls.table_exists(profile, schema, table, model_name)
33 changes: 32 additions & 1 deletion dbt/adapters/redshift.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import multiprocessing

from dbt.adapters.postgres import PostgresAdapter
from dbt.logger import GLOBAL_LOGGER as logger # noqa
from dbt.compat import basestring


drop_lock = multiprocessing.Lock()


class RedshiftAdapter(PostgresAdapter):
Expand Down Expand Up @@ -30,7 +36,7 @@ def sort_qualifier(cls, sort_type, sort):
.format(sort_type, valid_sort_types)
)

if type(sort) == str:
Copy link
Member

Choose a reason for hiding this comment

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

great catch

if isinstance(sort, basestring):
sort_keys = [sort]
else:
sort_keys = sort
Expand All @@ -42,3 +48,28 @@ def sort_qualifier(cls, sort_type, sort):
return "{sort_type} sortkey({keys_csv})".format(
sort_type=sort_type, keys_csv=keys_csv
)

@classmethod
def drop(cls, profile, relation, relation_type, model_name=None):
global drop_lock

to_return = None

try:
drop_lock.acquire()

connection = cls.get_connection(profile, model_name)

cls.commit(connection)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cmcarthur is there any problem with committing if there is no open transaction?

cls.begin(profile, connection.get('name'))

to_return = super(PostgresAdapter, cls).drop(
profile, relation, relation_type, model_name)

cls.commit(connection)
cls.begin(profile, connection.get('name'))

return to_return

finally:
drop_lock.release()
Loading