We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
deprecate sql_where
See also: 

The `sql_where` config isn't actually useful and people shouldn't use it. We should:
- add a deprecation warning when `sql_where` is provided
- make `sql_where` no longer required
- revamp docs around incremental models (https://github.com/fishtown-analytics/dbt/issues/1036)
- make it easier/faster to do the "advanced" version of incremental models

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `dbt/links.py`
Content:
```
1 
2 SnowflakeQuotingDocs = 'https://docs.getdbt.com/v0.10/docs/configuring-quoting'
3
```

Path: `dbt/compilation.py`
Content:
```
1 import itertools
2 import os
3 import json
4 from collections import OrderedDict, defaultdict
5 import sqlparse
6 
7 import dbt.utils
8 import dbt.include
9 import dbt.tracking
10 
11 from dbt.utils import get_materialization, NodeType, is_type
12 
13 from dbt.linker import Linker
14 
15 import dbt.compat
16 import dbt.context.runtime
17 import dbt.contracts.project
18 import dbt.exceptions
19 import dbt.flags
20 import dbt.loader
21 import dbt.config
22 from dbt.contracts.graph.compiled import CompiledNode, CompiledGraph
23 
24 from dbt.clients.system import write_json
25 from dbt.logger import GLOBAL_LOGGER as logger
26 
27 graph_file_name = 'graph.gpickle'
28 manifest_file_name = 'manifest.json'
29 
30 
31 def print_compile_stats(stats):
32     names = {
33         NodeType.Model: 'models',
34         NodeType.Test: 'tests',
35         NodeType.Archive: 'archives',
36         NodeType.Analysis: 'analyses',
37         NodeType.Macro: 'macros',
38         NodeType.Operation: 'operations',
39         NodeType.Seed: 'seed files',
40     }
41 
42     results = {k: 0 for k in names.keys()}
43     results.update(stats)
44 
45     stat_line = ", ".join(
46         ["{} {}".format(ct, names.get(t)) for t, ct in results.items()])
47 
48     logger.info("Found {}".format(stat_line))
49 
50 
51 def _add_prepended_cte(prepended_ctes, new_cte):
52     for dct in prepended_ctes:
53         if dct['id'] == new_cte['id']:
54             dct['sql'] = new_cte['sql']
55             return
56     prepended_ctes.append(new_cte)
57 
58 
59 def _extend_prepended_ctes(prepended_ctes, new_prepended_ctes):
60     for new_cte in new_prepended_ctes:
61         _add_prepended_cte(prepended_ctes, new_cte)
62 
63 
64 def prepend_ctes(model, manifest):
65     model, _, manifest = recursively_prepend_ctes(model, manifest)
66 
67     return (model, manifest)
68 
69 
70 def recursively_prepend_ctes(model, manifest):
71     if model.extra_ctes_injected:
72         return (model, model.extra_ctes, manifest)
73 
74     if dbt.flags.STRICT_MODE:
75         # ensure that all the nodes in this manifest are compiled
76         CompiledGraph(**manifest.to_flat_graph())
77 
78     prepended_ctes = []
79 
80     for cte in model.extra_ctes:
81         cte_id = cte['id']
82         cte_to_add = manifest.nodes.get(cte_id)
83         cte_to_add, new_prepended_ctes, manifest = recursively_prepend_ctes(
84             cte_to_add, manifest)
85 
86         _extend_prepended_ctes(prepended_ctes, new_prepended_ctes)
87         new_cte_name = '__dbt__CTE__{}'.format(cte_to_add.get('name'))
88         sql = ' {} as (\n{}\n)'.format(new_cte_name, cte_to_add.compiled_sql)
89         _add_prepended_cte(prepended_ctes, {'id': cte_id, 'sql': sql})
90 
91     model.prepend_ctes(prepended_ctes)
92 
93     manifest.nodes[model.unique_id] = model
94 
95     return (model, prepended_ctes, manifest)
96 
97 
98 class Compiler(object):
99     def __init__(self, config):
100         self.config = config
101 
102     def initialize(self):
103         dbt.clients.system.make_directory(self.config.target_path)
104         dbt.clients.system.make_directory(self.config.modules_path)
105 
106     def compile_node(self, node, manifest, extra_context=None):
107         if extra_context is None:
108             extra_context = {}
109 
110         logger.debug("Compiling {}".format(node.get('unique_id')))
111 
112         data = node.to_dict()
113         data.update({
114             'compiled': False,
115             'compiled_sql': None,
116             'extra_ctes_injected': False,
117             'extra_ctes': [],
118             'injected_sql': None,
119         })
120         compiled_node = CompiledNode(**data)
121 
122         context = dbt.context.runtime.generate(
123             compiled_node, self.config, manifest)
124         context.update(extra_context)
125 
126         compiled_node.compiled_sql = dbt.clients.jinja.get_rendered(
127             node.get('raw_sql'),
128             context,
129             node)
130 
131         compiled_node.compiled = True
132 
133         injected_node, _ = prepend_ctes(compiled_node, manifest)
134 
135         should_wrap = {NodeType.Test, NodeType.Operation}
136         if injected_node.resource_type in should_wrap:
137             # data tests get wrapped in count(*)
138             # TODO : move this somewhere more reasonable
139             if 'data' in injected_node.tags and \
140                is_type(injected_node, NodeType.Test):
141                 injected_node.wrapped_sql = (
142                     "select count(*) from (\n{test_sql}\n) sbq").format(
143                         test_sql=injected_node.injected_sql)
144             else:
145                 # don't wrap schema tests or analyses.
146                 injected_node.wrapped_sql = injected_node.injected_sql
147 
148         elif is_type(injected_node, NodeType.Archive):
149             # unfortunately we do everything automagically for
150             # archives. in the future it'd be nice to generate
151             # the SQL at the parser level.
152             pass
153 
154         elif(is_type(injected_node, NodeType.Model) and
155              get_materialization(injected_node) == 'ephemeral'):
156             pass
157 
158         else:
159             injected_node.wrapped_sql = None
160 
161         return injected_node
162 
163     def write_manifest_file(self, manifest):
164         """Write the manifest file to disk.
165 
166         manifest should be a Manifest.
167         """
168         filename = manifest_file_name
169         manifest_path = os.path.join(self.config.target_path, filename)
170         write_json(manifest_path, manifest.serialize())
171 
172     def write_graph_file(self, linker, manifest):
173         filename = graph_file_name
174         graph_path = os.path.join(self.config.target_path, filename)
175         linker.write_graph(graph_path, manifest)
176 
177     def link_node(self, linker, node, manifest):
178         linker.add_node(node.unique_id)
179 
180         for dependency in node.depends_on_nodes:
181             if manifest.nodes.get(dependency):
182                 linker.dependency(
183                     node.unique_id,
184                     (manifest.nodes.get(dependency).unique_id))
185 
186             else:
187                 dbt.exceptions.dependency_not_found(node, dependency)
188 
189     def link_graph(self, linker, manifest):
190         for node in manifest.nodes.values():
191             self.link_node(linker, node, manifest)
192 
193         cycle = linker.find_cycles()
194 
195         if cycle:
196             raise RuntimeError("Found a cycle: {}".format(cycle))
197 
198     def get_all_projects(self):
199         all_projects = {self.config.project_name: self.config}
200         dependency_projects = dbt.utils.dependency_projects(self.config)
201 
202         for project_cfg in dependency_projects:
203             name = project_cfg.project_name
204             all_projects[name] = project_cfg
205 
206         if dbt.flags.STRICT_MODE:
207             dbt.contracts.project.ProjectList(**all_projects)
208 
209         return all_projects
210 
211     def _check_resource_uniqueness(cls, manifest):
212         names_resources = {}
213         alias_resources = {}
214 
215         for resource, node in manifest.nodes.items():
216             if node.resource_type not in NodeType.refable():
217                 continue
218 
219             name = node.name
220             alias = "{}.{}".format(node.schema, node.alias)
221 
222             existing_node = names_resources.get(name)
223             if existing_node is not None:
224                 dbt.exceptions.raise_duplicate_resource_name(
225                         existing_node, node)
226 
227             existing_alias = alias_resources.get(alias)
228             if existing_alias is not None:
229                 dbt.exceptions.raise_ambiguous_alias(
230                         existing_alias, node)
231 
232             names_resources[name] = node
233             alias_resources[alias] = node
234 
235     def compile(self):
236         linker = Linker()
237 
238         all_projects = self.get_all_projects()
239 
240         manifest = dbt.loader.GraphLoader.load_all(self.config, all_projects)
241 
242         self.write_manifest_file(manifest)
243 
244         self._check_resource_uniqueness(manifest)
245 
246         resource_fqns = manifest.get_resource_fqns()
247         disabled_fqns = [n.fqn for n in manifest.disabled]
248         self.config.warn_for_unused_resource_config_paths(resource_fqns,
249                                                           disabled_fqns)
250 
251         self.link_graph(linker, manifest)
252 
253         stats = defaultdict(int)
254 
255         for node_name, node in itertools.chain(
256                 manifest.nodes.items(),
257                 manifest.macros.items()):
258             stats[node.resource_type] += 1
259 
260         self.write_graph_file(linker, manifest)
261         print_compile_stats(stats)
262 
263         return manifest, linker
264
```

Path: `dbt/deprecations.py`
Content:
```
1 from dbt.logger import GLOBAL_LOGGER as logger
2 
3 
4 class DBTDeprecation(object):
5     name = None
6     description = None
7 
8     def show(self, *args, **kwargs):
9         if self.name not in active_deprecations:
10             desc = self.description.format(**kwargs)
11             logger.info("* Deprecation Warning: {}\n".format(desc))
12             active_deprecations.add(self.name)
13 
14 
15 class DBTRepositoriesDeprecation(DBTDeprecation):
16     name = "repositories"
17     description = """The dbt_project.yml configuration option 'repositories' is
18   deprecated. Please place dependencies in the `packages.yml` file instead.
19   The 'repositories' option will be removed in a future version of dbt.
20 
21   For more information, see: https://docs.getdbt.com/docs/package-management
22 
23   # Example packages.yml contents:
24 
25 {recommendation}
26   """
27 
28 
29 class SeedDropExistingDeprecation(DBTDeprecation):
30     name = 'drop-existing'
31     description = """The --drop-existing argument to `dbt seed` has been
32   deprecated. Please use --full-refresh instead. The --drop-existing option
33   will be removed in a future version of dbt."""
34 
35 
36 def warn(name, *args, **kwargs):
37     if name not in deprecations:
38         # this should (hopefully) never happen
39         raise RuntimeError(
40             "Error showing deprecation warning: {}".format(name)
41         )
42 
43     deprecations[name].show(*args, **kwargs)
44 
45 
46 # these are globally available
47 # since modules are only imported once, active_deprecations is a singleton
48 
49 active_deprecations = set()
50 
51 deprecations_list = [
52     DBTRepositoriesDeprecation(),
53     SeedDropExistingDeprecation()
54 ]
55 
56 deprecations = {d.name: d for d in deprecations_list}
57 
58 
59 def reset_deprecations():
60     active_deprecations.clear()
61
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/dbt/compilation.py b/dbt/compilation.py
--- a/dbt/compilation.py
+++ b/dbt/compilation.py
@@ -232,6 +232,12 @@
             names_resources[name] = node
             alias_resources[alias] = node
 
+    def warn_for_deprecated_configs(self, manifest):
+        for unique_id, node in manifest.nodes.items():
+            is_model = node.resource_type == NodeType.Model
+            if is_model and 'sql_where' in node.config:
+                dbt.deprecations.warn('sql_where')
+
     def compile(self):
         linker = Linker()
 
@@ -247,6 +253,7 @@
         disabled_fqns = [n.fqn for n in manifest.disabled]
         self.config.warn_for_unused_resource_config_paths(resource_fqns,
                                                           disabled_fqns)
+        self.warn_for_deprecated_configs(manifest)
 
         self.link_graph(linker, manifest)
 
diff --git a/dbt/deprecations.py b/dbt/deprecations.py
--- a/dbt/deprecations.py
+++ b/dbt/deprecations.py
@@ -1,4 +1,5 @@
 from dbt.logger import GLOBAL_LOGGER as logger
+import dbt.links
 
 
 class DBTDeprecation(object):
@@ -26,6 +27,16 @@
   """
 
 
+class SqlWhereDeprecation(DBTDeprecation):
+    name = "sql_where"
+    description = """\
+The `sql_where` option for incremental models is deprecated and will be
+  removed in a future release. Check the docs for more information
+
+  {}
+  """.format(dbt.links.IncrementalDocs)
+
+
 class SeedDropExistingDeprecation(DBTDeprecation):
     name = 'drop-existing'
     description = """The --drop-existing argument to `dbt seed` has been
@@ -50,7 +61,8 @@
 
 deprecations_list = [
     DBTRepositoriesDeprecation(),
-    SeedDropExistingDeprecation()
+    SeedDropExistingDeprecation(),
+    SqlWhereDeprecation(),
 ]
 
 deprecations = {d.name: d for d in deprecations_list}
diff --git a/dbt/links.py b/dbt/links.py
--- a/dbt/links.py
+++ b/dbt/links.py
@@ -1,2 +1,3 @@
 
 SnowflakeQuotingDocs = 'https://docs.getdbt.com/v0.10/docs/configuring-quoting'
+IncrementalDocs = 'https://docs.getdbt.com/docs/configuring-incremental-models'

{"golden_diff": "diff --git a/dbt/compilation.py b/dbt/compilation.py\n--- a/dbt/compilation.py\n+++ b/dbt/compilation.py\n@@ -232,6 +232,12 @@\n             names_resources[name] = node\n             alias_resources[alias] = node\n \n+    def warn_for_deprecated_configs(self, manifest):\n+        for unique_id, node in manifest.nodes.items():\n+            is_model = node.resource_type == NodeType.Model\n+            if is_model and 'sql_where' in node.config:\n+                dbt.deprecations.warn('sql_where')\n+\n     def compile(self):\n         linker = Linker()\n \n@@ -247,6 +253,7 @@\n         disabled_fqns = [n.fqn for n in manifest.disabled]\n         self.config.warn_for_unused_resource_config_paths(resource_fqns,\n                                                           disabled_fqns)\n+        self.warn_for_deprecated_configs(manifest)\n \n         self.link_graph(linker, manifest)\n \ndiff --git a/dbt/deprecations.py b/dbt/deprecations.py\n--- a/dbt/deprecations.py\n+++ b/dbt/deprecations.py\n@@ -1,4 +1,5 @@\n from dbt.logger import GLOBAL_LOGGER as logger\n+import dbt.links\n \n \n class DBTDeprecation(object):\n@@ -26,6 +27,16 @@\n   \"\"\"\n \n \n+class SqlWhereDeprecation(DBTDeprecation):\n+    name = \"sql_where\"\n+    description = \"\"\"\\\n+The `sql_where` option for incremental models is deprecated and will be\n+  removed in a future release. Check the docs for more information\n+\n+  {}\n+  \"\"\".format(dbt.links.IncrementalDocs)\n+\n+\n class SeedDropExistingDeprecation(DBTDeprecation):\n     name = 'drop-existing'\n     description = \"\"\"The --drop-existing argument to `dbt seed` has been\n@@ -50,7 +61,8 @@\n \n deprecations_list = [\n     DBTRepositoriesDeprecation(),\n-    SeedDropExistingDeprecation()\n+    SeedDropExistingDeprecation(),\n+    SqlWhereDeprecation(),\n ]\n \n deprecations = {d.name: d for d in deprecations_list}\ndiff --git a/dbt/links.py b/dbt/links.py\n--- a/dbt/links.py\n+++ b/dbt/links.py\n@@ -1,2 +1,3 @@\n \n SnowflakeQuotingDocs = 'https://docs.getdbt.com/v0.10/docs/configuring-quoting'\n+IncrementalDocs = 'https://docs.getdbt.com/docs/configuring-incremental-models'\n", "issue": "deprecate sql_where\nSee also: \r\n\r\nThe `sql_where` config isn't actually useful and people shouldn't use it. We should:\r\n- add a deprecation warning when `sql_where` is provided\r\n- make `sql_where` no longer required\r\n- revamp docs around incremental models (https://github.com/fishtown-analytics/dbt/issues/1036)\r\n- make it easier/faster to do the \"advanced\" version of incremental models\n", "before_files": [{"content": "\nSnowflakeQuotingDocs = 'https://docs.getdbt.com/v0.10/docs/configuring-quoting'\n", "path": "dbt/links.py"}, {"content": "import itertools\nimport os\nimport json\nfrom collections import OrderedDict, defaultdict\nimport sqlparse\n\nimport dbt.utils\nimport dbt.include\nimport dbt.tracking\n\nfrom dbt.utils import get_materialization, NodeType, is_type\n\nfrom dbt.linker import Linker\n\nimport dbt.compat\nimport dbt.context.runtime\nimport dbt.contracts.project\nimport dbt.exceptions\nimport dbt.flags\nimport dbt.loader\nimport dbt.config\nfrom dbt.contracts.graph.compiled import CompiledNode, CompiledGraph\n\nfrom dbt.clients.system import write_json\nfrom dbt.logger import GLOBAL_LOGGER as logger\n\ngraph_file_name = 'graph.gpickle'\nmanifest_file_name = 'manifest.json'\n\n\ndef print_compile_stats(stats):\n    names = {\n        NodeType.Model: 'models',\n        NodeType.Test: 'tests',\n        NodeType.Archive: 'archives',\n        NodeType.Analysis: 'analyses',\n        NodeType.Macro: 'macros',\n        NodeType.Operation: 'operations',\n        NodeType.Seed: 'seed files',\n    }\n\n    results = {k: 0 for k in names.keys()}\n    results.update(stats)\n\n    stat_line = \", \".join(\n        [\"{} {}\".format(ct, names.get(t)) for t, ct in results.items()])\n\n    logger.info(\"Found {}\".format(stat_line))\n\n\ndef _add_prepended_cte(prepended_ctes, new_cte):\n    for dct in prepended_ctes:\n        if dct['id'] == new_cte['id']:\n            dct['sql'] = new_cte['sql']\n            return\n    prepended_ctes.append(new_cte)\n\n\ndef _extend_prepended_ctes(prepended_ctes, new_prepended_ctes):\n    for new_cte in new_prepended_ctes:\n        _add_prepended_cte(prepended_ctes, new_cte)\n\n\ndef prepend_ctes(model, manifest):\n    model, _, manifest = recursively_prepend_ctes(model, manifest)\n\n    return (model, manifest)\n\n\ndef recursively_prepend_ctes(model, manifest):\n    if model.extra_ctes_injected:\n        return (model, model.extra_ctes, manifest)\n\n    if dbt.flags.STRICT_MODE:\n        # ensure that all the nodes in this manifest are compiled\n        CompiledGraph(**manifest.to_flat_graph())\n\n    prepended_ctes = []\n\n    for cte in model.extra_ctes:\n        cte_id = cte['id']\n        cte_to_add = manifest.nodes.get(cte_id)\n        cte_to_add, new_prepended_ctes, manifest = recursively_prepend_ctes(\n            cte_to_add, manifest)\n\n        _extend_prepended_ctes(prepended_ctes, new_prepended_ctes)\n        new_cte_name = '__dbt__CTE__{}'.format(cte_to_add.get('name'))\n        sql = ' {} as (\\n{}\\n)'.format(new_cte_name, cte_to_add.compiled_sql)\n        _add_prepended_cte(prepended_ctes, {'id': cte_id, 'sql': sql})\n\n    model.prepend_ctes(prepended_ctes)\n\n    manifest.nodes[model.unique_id] = model\n\n    return (model, prepended_ctes, manifest)\n\n\nclass Compiler(object):\n    def __init__(self, config):\n        self.config = config\n\n    def initialize(self):\n        dbt.clients.system.make_directory(self.config.target_path)\n        dbt.clients.system.make_directory(self.config.modules_path)\n\n    def compile_node(self, node, manifest, extra_context=None):\n        if extra_context is None:\n            extra_context = {}\n\n        logger.debug(\"Compiling {}\".format(node.get('unique_id')))\n\n        data = node.to_dict()\n        data.update({\n            'compiled': False,\n            'compiled_sql': None,\n            'extra_ctes_injected': False,\n            'extra_ctes': [],\n            'injected_sql': None,\n        })\n        compiled_node = CompiledNode(**data)\n\n        context = dbt.context.runtime.generate(\n            compiled_node, self.config, manifest)\n        context.update(extra_context)\n\n        compiled_node.compiled_sql = dbt.clients.jinja.get_rendered(\n            node.get('raw_sql'),\n            context,\n            node)\n\n        compiled_node.compiled = True\n\n        injected_node, _ = prepend_ctes(compiled_node, manifest)\n\n        should_wrap = {NodeType.Test, NodeType.Operation}\n        if injected_node.resource_type in should_wrap:\n            # data tests get wrapped in count(*)\n            # TODO : move this somewhere more reasonable\n            if 'data' in injected_node.tags and \\\n               is_type(injected_node, NodeType.Test):\n                injected_node.wrapped_sql = (\n                    \"select count(*) from (\\n{test_sql}\\n) sbq\").format(\n                        test_sql=injected_node.injected_sql)\n            else:\n                # don't wrap schema tests or analyses.\n                injected_node.wrapped_sql = injected_node.injected_sql\n\n        elif is_type(injected_node, NodeType.Archive):\n            # unfortunately we do everything automagically for\n            # archives. in the future it'd be nice to generate\n            # the SQL at the parser level.\n            pass\n\n        elif(is_type(injected_node, NodeType.Model) and\n             get_materialization(injected_node) == 'ephemeral'):\n            pass\n\n        else:\n            injected_node.wrapped_sql = None\n\n        return injected_node\n\n    def write_manifest_file(self, manifest):\n        \"\"\"Write the manifest file to disk.\n\n        manifest should be a Manifest.\n        \"\"\"\n        filename = manifest_file_name\n        manifest_path = os.path.join(self.config.target_path, filename)\n        write_json(manifest_path, manifest.serialize())\n\n    def write_graph_file(self, linker, manifest):\n        filename = graph_file_name\n        graph_path = os.path.join(self.config.target_path, filename)\n        linker.write_graph(graph_path, manifest)\n\n    def link_node(self, linker, node, manifest):\n        linker.add_node(node.unique_id)\n\n        for dependency in node.depends_on_nodes:\n            if manifest.nodes.get(dependency):\n                linker.dependency(\n                    node.unique_id,\n                    (manifest.nodes.get(dependency).unique_id))\n\n            else:\n                dbt.exceptions.dependency_not_found(node, dependency)\n\n    def link_graph(self, linker, manifest):\n        for node in manifest.nodes.values():\n            self.link_node(linker, node, manifest)\n\n        cycle = linker.find_cycles()\n\n        if cycle:\n            raise RuntimeError(\"Found a cycle: {}\".format(cycle))\n\n    def get_all_projects(self):\n        all_projects = {self.config.project_name: self.config}\n        dependency_projects = dbt.utils.dependency_projects(self.config)\n\n        for project_cfg in dependency_projects:\n            name = project_cfg.project_name\n            all_projects[name] = project_cfg\n\n        if dbt.flags.STRICT_MODE:\n            dbt.contracts.project.ProjectList(**all_projects)\n\n        return all_projects\n\n    def _check_resource_uniqueness(cls, manifest):\n        names_resources = {}\n        alias_resources = {}\n\n        for resource, node in manifest.nodes.items():\n            if node.resource_type not in NodeType.refable():\n                continue\n\n            name = node.name\n            alias = \"{}.{}\".format(node.schema, node.alias)\n\n            existing_node = names_resources.get(name)\n            if existing_node is not None:\n                dbt.exceptions.raise_duplicate_resource_name(\n                        existing_node, node)\n\n            existing_alias = alias_resources.get(alias)\n            if existing_alias is not None:\n                dbt.exceptions.raise_ambiguous_alias(\n                        existing_alias, node)\n\n            names_resources[name] = node\n            alias_resources[alias] = node\n\n    def compile(self):\n        linker = Linker()\n\n        all_projects = self.get_all_projects()\n\n        manifest = dbt.loader.GraphLoader.load_all(self.config, all_projects)\n\n        self.write_manifest_file(manifest)\n\n        self._check_resource_uniqueness(manifest)\n\n        resource_fqns = manifest.get_resource_fqns()\n        disabled_fqns = [n.fqn for n in manifest.disabled]\n        self.config.warn_for_unused_resource_config_paths(resource_fqns,\n                                                          disabled_fqns)\n\n        self.link_graph(linker, manifest)\n\n        stats = defaultdict(int)\n\n        for node_name, node in itertools.chain(\n                manifest.nodes.items(),\n                manifest.macros.items()):\n            stats[node.resource_type] += 1\n\n        self.write_graph_file(linker, manifest)\n        print_compile_stats(stats)\n\n        return manifest, linker\n", "path": "dbt/compilation.py"}, {"content": "from dbt.logger import GLOBAL_LOGGER as logger\n\n\nclass DBTDeprecation(object):\n    name = None\n    description = None\n\n    def show(self, *args, **kwargs):\n        if self.name not in active_deprecations:\n            desc = self.description.format(**kwargs)\n            logger.info(\"* Deprecation Warning: {}\\n\".format(desc))\n            active_deprecations.add(self.name)\n\n\nclass DBTRepositoriesDeprecation(DBTDeprecation):\n    name = \"repositories\"\n    description = \"\"\"The dbt_project.yml configuration option 'repositories' is\n  deprecated. Please place dependencies in the `packages.yml` file instead.\n  The 'repositories' option will be removed in a future version of dbt.\n\n  For more information, see: https://docs.getdbt.com/docs/package-management\n\n  # Example packages.yml contents:\n\n{recommendation}\n  \"\"\"\n\n\nclass SeedDropExistingDeprecation(DBTDeprecation):\n    name = 'drop-existing'\n    description = \"\"\"The --drop-existing argument to `dbt seed` has been\n  deprecated. Please use --full-refresh instead. The --drop-existing option\n  will be removed in a future version of dbt.\"\"\"\n\n\ndef warn(name, *args, **kwargs):\n    if name not in deprecations:\n        # this should (hopefully) never happen\n        raise RuntimeError(\n            \"Error showing deprecation warning: {}\".format(name)\n        )\n\n    deprecations[name].show(*args, **kwargs)\n\n\n# these are globally available\n# since modules are only imported once, active_deprecations is a singleton\n\nactive_deprecations = set()\n\ndeprecations_list = [\n    DBTRepositoriesDeprecation(),\n    SeedDropExistingDeprecation()\n]\n\ndeprecations = {d.name: d for d in deprecations_list}\n\n\ndef reset_deprecations():\n    active_deprecations.clear()\n", "path": "dbt/deprecations.py"}], "after_files": [{"content": "\nSnowflakeQuotingDocs = 'https://docs.getdbt.com/v0.10/docs/configuring-quoting'\nIncrementalDocs = 'https://docs.getdbt.com/docs/configuring-incremental-models'\n", "path": "dbt/links.py"}, {"content": "import itertools\nimport os\nimport json\nfrom collections import OrderedDict, defaultdict\nimport sqlparse\n\nimport dbt.utils\nimport dbt.include\nimport dbt.tracking\n\nfrom dbt.utils import get_materialization, NodeType, is_type\n\nfrom dbt.linker import Linker\n\nimport dbt.compat\nimport dbt.context.runtime\nimport dbt.contracts.project\nimport dbt.exceptions\nimport dbt.flags\nimport dbt.loader\nimport dbt.config\nfrom dbt.contracts.graph.compiled import CompiledNode, CompiledGraph\n\nfrom dbt.clients.system import write_json\nfrom dbt.logger import GLOBAL_LOGGER as logger\n\ngraph_file_name = 'graph.gpickle'\nmanifest_file_name = 'manifest.json'\n\n\ndef print_compile_stats(stats):\n    names = {\n        NodeType.Model: 'models',\n        NodeType.Test: 'tests',\n        NodeType.Archive: 'archives',\n        NodeType.Analysis: 'analyses',\n        NodeType.Macro: 'macros',\n        NodeType.Operation: 'operations',\n        NodeType.Seed: 'seed files',\n    }\n\n    results = {k: 0 for k in names.keys()}\n    results.update(stats)\n\n    stat_line = \", \".join(\n        [\"{} {}\".format(ct, names.get(t)) for t, ct in results.items()])\n\n    logger.info(\"Found {}\".format(stat_line))\n\n\ndef _add_prepended_cte(prepended_ctes, new_cte):\n    for dct in prepended_ctes:\n        if dct['id'] == new_cte['id']:\n            dct['sql'] = new_cte['sql']\n            return\n    prepended_ctes.append(new_cte)\n\n\ndef _extend_prepended_ctes(prepended_ctes, new_prepended_ctes):\n    for new_cte in new_prepended_ctes:\n        _add_prepended_cte(prepended_ctes, new_cte)\n\n\ndef prepend_ctes(model, manifest):\n    model, _, manifest = recursively_prepend_ctes(model, manifest)\n\n    return (model, manifest)\n\n\ndef recursively_prepend_ctes(model, manifest):\n    if model.extra_ctes_injected:\n        return (model, model.extra_ctes, manifest)\n\n    if dbt.flags.STRICT_MODE:\n        # ensure that all the nodes in this manifest are compiled\n        CompiledGraph(**manifest.to_flat_graph())\n\n    prepended_ctes = []\n\n    for cte in model.extra_ctes:\n        cte_id = cte['id']\n        cte_to_add = manifest.nodes.get(cte_id)\n        cte_to_add, new_prepended_ctes, manifest = recursively_prepend_ctes(\n            cte_to_add, manifest)\n\n        _extend_prepended_ctes(prepended_ctes, new_prepended_ctes)\n        new_cte_name = '__dbt__CTE__{}'.format(cte_to_add.get('name'))\n        sql = ' {} as (\\n{}\\n)'.format(new_cte_name, cte_to_add.compiled_sql)\n        _add_prepended_cte(prepended_ctes, {'id': cte_id, 'sql': sql})\n\n    model.prepend_ctes(prepended_ctes)\n\n    manifest.nodes[model.unique_id] = model\n\n    return (model, prepended_ctes, manifest)\n\n\nclass Compiler(object):\n    def __init__(self, config):\n        self.config = config\n\n    def initialize(self):\n        dbt.clients.system.make_directory(self.config.target_path)\n        dbt.clients.system.make_directory(self.config.modules_path)\n\n    def compile_node(self, node, manifest, extra_context=None):\n        if extra_context is None:\n            extra_context = {}\n\n        logger.debug(\"Compiling {}\".format(node.get('unique_id')))\n\n        data = node.to_dict()\n        data.update({\n            'compiled': False,\n            'compiled_sql': None,\n            'extra_ctes_injected': False,\n            'extra_ctes': [],\n            'injected_sql': None,\n        })\n        compiled_node = CompiledNode(**data)\n\n        context = dbt.context.runtime.generate(\n            compiled_node, self.config, manifest)\n        context.update(extra_context)\n\n        compiled_node.compiled_sql = dbt.clients.jinja.get_rendered(\n            node.get('raw_sql'),\n            context,\n            node)\n\n        compiled_node.compiled = True\n\n        injected_node, _ = prepend_ctes(compiled_node, manifest)\n\n        should_wrap = {NodeType.Test, NodeType.Operation}\n        if injected_node.resource_type in should_wrap:\n            # data tests get wrapped in count(*)\n            # TODO : move this somewhere more reasonable\n            if 'data' in injected_node.tags and \\\n               is_type(injected_node, NodeType.Test):\n                injected_node.wrapped_sql = (\n                    \"select count(*) from (\\n{test_sql}\\n) sbq\").format(\n                        test_sql=injected_node.injected_sql)\n            else:\n                # don't wrap schema tests or analyses.\n                injected_node.wrapped_sql = injected_node.injected_sql\n\n        elif is_type(injected_node, NodeType.Archive):\n            # unfortunately we do everything automagically for\n            # archives. in the future it'd be nice to generate\n            # the SQL at the parser level.\n            pass\n\n        elif(is_type(injected_node, NodeType.Model) and\n             get_materialization(injected_node) == 'ephemeral'):\n            pass\n\n        else:\n            injected_node.wrapped_sql = None\n\n        return injected_node\n\n    def write_manifest_file(self, manifest):\n        \"\"\"Write the manifest file to disk.\n\n        manifest should be a Manifest.\n        \"\"\"\n        filename = manifest_file_name\n        manifest_path = os.path.join(self.config.target_path, filename)\n        write_json(manifest_path, manifest.serialize())\n\n    def write_graph_file(self, linker, manifest):\n        filename = graph_file_name\n        graph_path = os.path.join(self.config.target_path, filename)\n        linker.write_graph(graph_path, manifest)\n\n    def link_node(self, linker, node, manifest):\n        linker.add_node(node.unique_id)\n\n        for dependency in node.depends_on_nodes:\n            if manifest.nodes.get(dependency):\n                linker.dependency(\n                    node.unique_id,\n                    (manifest.nodes.get(dependency).unique_id))\n\n            else:\n                dbt.exceptions.dependency_not_found(node, dependency)\n\n    def link_graph(self, linker, manifest):\n        for node in manifest.nodes.values():\n            self.link_node(linker, node, manifest)\n\n        cycle = linker.find_cycles()\n\n        if cycle:\n            raise RuntimeError(\"Found a cycle: {}\".format(cycle))\n\n    def get_all_projects(self):\n        all_projects = {self.config.project_name: self.config}\n        dependency_projects = dbt.utils.dependency_projects(self.config)\n\n        for project_cfg in dependency_projects:\n            name = project_cfg.project_name\n            all_projects[name] = project_cfg\n\n        if dbt.flags.STRICT_MODE:\n            dbt.contracts.project.ProjectList(**all_projects)\n\n        return all_projects\n\n    def _check_resource_uniqueness(cls, manifest):\n        names_resources = {}\n        alias_resources = {}\n\n        for resource, node in manifest.nodes.items():\n            if node.resource_type not in NodeType.refable():\n                continue\n\n            name = node.name\n            alias = \"{}.{}\".format(node.schema, node.alias)\n\n            existing_node = names_resources.get(name)\n            if existing_node is not None:\n                dbt.exceptions.raise_duplicate_resource_name(\n                        existing_node, node)\n\n            existing_alias = alias_resources.get(alias)\n            if existing_alias is not None:\n                dbt.exceptions.raise_ambiguous_alias(\n                        existing_alias, node)\n\n            names_resources[name] = node\n            alias_resources[alias] = node\n\n    def warn_for_deprecated_configs(self, manifest):\n        for unique_id, node in manifest.nodes.items():\n            is_model = node.resource_type == NodeType.Model\n            if is_model and 'sql_where' in node.config:\n                dbt.deprecations.warn('sql_where')\n\n    def compile(self):\n        linker = Linker()\n\n        all_projects = self.get_all_projects()\n\n        manifest = dbt.loader.GraphLoader.load_all(self.config, all_projects)\n\n        self.write_manifest_file(manifest)\n\n        self._check_resource_uniqueness(manifest)\n\n        resource_fqns = manifest.get_resource_fqns()\n        disabled_fqns = [n.fqn for n in manifest.disabled]\n        self.config.warn_for_unused_resource_config_paths(resource_fqns,\n                                                          disabled_fqns)\n        self.warn_for_deprecated_configs(manifest)\n\n        self.link_graph(linker, manifest)\n\n        stats = defaultdict(int)\n\n        for node_name, node in itertools.chain(\n                manifest.nodes.items(),\n                manifest.macros.items()):\n            stats[node.resource_type] += 1\n\n        self.write_graph_file(linker, manifest)\n        print_compile_stats(stats)\n\n        return manifest, linker\n", "path": "dbt/compilation.py"}, {"content": "from dbt.logger import GLOBAL_LOGGER as logger\nimport dbt.links\n\n\nclass DBTDeprecation(object):\n    name = None\n    description = None\n\n    def show(self, *args, **kwargs):\n        if self.name not in active_deprecations:\n            desc = self.description.format(**kwargs)\n            logger.info(\"* Deprecation Warning: {}\\n\".format(desc))\n            active_deprecations.add(self.name)\n\n\nclass DBTRepositoriesDeprecation(DBTDeprecation):\n    name = \"repositories\"\n    description = \"\"\"The dbt_project.yml configuration option 'repositories' is\n  deprecated. Please place dependencies in the `packages.yml` file instead.\n  The 'repositories' option will be removed in a future version of dbt.\n\n  For more information, see: https://docs.getdbt.com/docs/package-management\n\n  # Example packages.yml contents:\n\n{recommendation}\n  \"\"\"\n\n\nclass SqlWhereDeprecation(DBTDeprecation):\n    name = \"sql_where\"\n    description = \"\"\"\\\nThe `sql_where` option for incremental models is deprecated and will be\n  removed in a future release. Check the docs for more information\n\n  {}\n  \"\"\".format(dbt.links.IncrementalDocs)\n\n\nclass SeedDropExistingDeprecation(DBTDeprecation):\n    name = 'drop-existing'\n    description = \"\"\"The --drop-existing argument to `dbt seed` has been\n  deprecated. Please use --full-refresh instead. The --drop-existing option\n  will be removed in a future version of dbt.\"\"\"\n\n\ndef warn(name, *args, **kwargs):\n    if name not in deprecations:\n        # this should (hopefully) never happen\n        raise RuntimeError(\n            \"Error showing deprecation warning: {}\".format(name)\n        )\n\n    deprecations[name].show(*args, **kwargs)\n\n\n# these are globally available\n# since modules are only imported once, active_deprecations is a singleton\n\nactive_deprecations = set()\n\ndeprecations_list = [\n    DBTRepositoriesDeprecation(),\n    SeedDropExistingDeprecation(),\n    SqlWhereDeprecation(),\n]\n\ndeprecations = {d.name: d for d in deprecations_list}\n\n\ndef reset_deprecations():\n    active_deprecations.clear()\n", "path": "dbt/deprecations.py"}]}