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 as objects (#961) #1010

Merged
merged 6 commits into from
Sep 20, 2018
Merged

Conversation

beckjake
Copy link
Contributor

Create adapters as singleton objects instead of classes, resolves #961.

Adapters now store the config on themselves when they're generated, and the factory returns singleton instances rather than types.

It does seem that the whole relation creation API could be changed to be a bit more streamlined - we could have relation creates go through the adapter directly and then we wouldn't need a proxy, but that would break a lot of existing macros. I don't think it's worth the effort if this proxy is good enough.

Most of this PR is converting method(cls, config, ...) to method(self, ...). The most substantial aspects are the changes to the factory code and the wrapper/relations quoting logic - I spent a lot of time getting quoting-related tests to pass.

@cmcarthur
Copy link
Member

can you elaborate on:

we could have relation creates go through the adapter directly and then we wouldn't need a proxy

Copy link
Member

@cmcarthur cmcarthur left a comment

Choose a reason for hiding this comment

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

i really, really like how this turned out. approved.

if quote_policy is None:
quote_policy = {}

quote_policy = dbt.utils.merge(config.quoting, quote_policy)
Copy link
Member

Choose a reason for hiding this comment

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

this feels so right


adapter = adapter_type(config)
_ADAPTERS[adapter_name] = adapter
return adapter
Copy link
Member

Choose a reason for hiding this comment

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

very into this. since we are getting more into the habit of using static classes as namespaces, should this be AdapterFactory.create() rather than dbt.adapters.factory.get_adapter()?

this PR is big enough, I don't want you to add it to this. but worth considering for the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure. I think this is pretty reasonable to keep as a module-level entity, I don't think making the factory an object would gain much. The interface is pretty simple right now and I think that's very valuable. This kind of model in Python is pretty common (logging.getLogger() is the canonical example, I suppose).

self.quoting_config,
kwargs.pop('quote_policy', {})
)
return self.relation_type.create(*args, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

i think i understand now -- if the primary API for creating relations is on the adapter instead of the relation, then we can seamlessly pass in the quoting config.

i need to think a little bit more about that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, exactly! adapter.create_relation(...) or something.

@beckjake beckjake merged commit 6454a81 into dev/guion-bluford Sep 20, 2018
@beckjake beckjake deleted the feature/adapters-as-objects branch September 20, 2018 15:01
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