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

remove adapter.get_compiler #9134

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .changes/unreleased/Breaking Changes-20231127-114757.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Breaking Changes
body: Remove adapter.get_compiler interface
time: 2023-11-27T11:47:57.443202-05:00
custom:
Author: michelleark
Issue: "9148"
5 changes: 0 additions & 5 deletions core/dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1370,11 +1370,6 @@ def post_model_hook(self, config: Mapping[str, Any], context: Any) -> None:
"""
pass

def get_compiler(self):
from dbt.compilation import Compiler

return Compiler(self.config)

# Methods used in adapter tests
def update_column_sql(
self,
Expand Down
24 changes: 1 addition & 23 deletions core/dbt/adapters/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,17 @@
Generic,
TypeVar,
Tuple,
Dict,
Any,
)
from typing_extensions import Protocol

import agate

from dbt.adapters.contracts.connection import Connection, AdapterRequiredConfig, AdapterResponse
from dbt.contracts.graph.nodes import ResultNode, ManifestNode
from dbt.contracts.graph.nodes import ResultNode
from dbt.contracts.graph.model_config import BaseConfig
from dbt.contracts.graph.manifest import Manifest
from dbt.contracts.relation import Policy, HasQuoting

from dbt.graph import Graph


@dataclass
class AdapterConfig(BaseConfig):
Expand Down Expand Up @@ -50,24 +46,10 @@ def create_from(cls: Type[Self], config: HasQuoting, node: ResultNode) -> Self:
...


class CompilerProtocol(Protocol):
def compile(self, manifest: Manifest, write=True) -> Graph:
...

def compile_node(
self,
node: ManifestNode,
manifest: Manifest,
extra_context: Optional[Dict[str, Any]] = None,
) -> ManifestNode:
...


AdapterConfig_T = TypeVar("AdapterConfig_T", bound=AdapterConfig)
ConnectionManager_T = TypeVar("ConnectionManager_T", bound=ConnectionManagerProtocol)
Relation_T = TypeVar("Relation_T", bound=RelationProtocol)
Column_T = TypeVar("Column_T", bound=ColumnProtocol)
Compiler_T = TypeVar("Compiler_T", bound=CompilerProtocol)


# TODO CT-211
Expand All @@ -78,7 +60,6 @@ class AdapterProtocol( # type: ignore[misc]
ConnectionManager_T,
Relation_T,
Column_T,
Compiler_T,
],
):
# N.B. Technically these are ClassVars, but mypy doesn't support putting type vars in a
Expand Down Expand Up @@ -153,6 +134,3 @@ def execute(
self, sql: str, auto_begin: bool = False, fetch: bool = False
) -> Tuple[AdapterResponse, agate.Table]:
...

def get_compiler(self) -> Compiler_T:
...
9 changes: 2 additions & 7 deletions core/dbt/compilation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import argparse
import json

import networkx as nx # type: ignore
Expand Down Expand Up @@ -34,7 +33,6 @@
from dbt.node_types import NodeType, ModelLanguage
from dbt.common.events.format import pluralize
import dbt.tracking
import dbt.task.list as list_task
import sqlparse

graph_file_name = "graph.gpickle"
Expand Down Expand Up @@ -485,11 +483,8 @@ def compile(self, manifest: Manifest, write=True, add_test_edges=False) -> Graph
if write:
self.write_graph_file(linker, manifest)

# Do not print these for ListTask's
if not (
self.config.args.__class__ == argparse.Namespace
and self.config.args.cls == list_task.ListTask
):
# Do not print these for list command
if self.config.args.which != "list":
stats = _generate_stats(manifest)
print_compile_stats(stats)

Expand Down
9 changes: 4 additions & 5 deletions core/dbt/task/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from pathlib import Path
from typing import Any, Dict, List, Optional, Type, Union

from dbt.compilation import Compiler
import dbt.common.exceptions.base
import dbt.exceptions
from dbt import tracking
from dbt.adapters.factory import get_adapter
from dbt.config import RuntimeConfig, Project
from dbt.config.profile import read_profile
from dbt.constants import DBT_PROJECT_FILE_NAME
Expand Down Expand Up @@ -161,17 +161,15 @@ def __init__(self, args, config, manifest: Optional[Manifest] = None) -> None:
super().__init__(args, config)
self.graph: Optional[Graph] = None
self.manifest = manifest
self.compiler = Compiler(self.config)

def compile_manifest(self):
if self.manifest is None:
raise DbtInternalError("compile_manifest called before manifest was loaded")

start_compile_manifest = time.perf_counter()

# we cannot get adapter in init since it will break rpc #5579
adapter = get_adapter(self.config)
compiler = adapter.get_compiler()
self.graph = compiler.compile(self.manifest)
self.graph = self.compiler.compile(self.manifest)

compile_time = time.perf_counter() - start_compile_manifest
if dbt.tracking.active_user is not None:
Expand All @@ -196,6 +194,7 @@ def __init__(self, node) -> None:
class BaseRunner(metaclass=ABCMeta):
def __init__(self, config, adapter, node, node_index, num_nodes) -> None:
self.config = config
self.compiler = Compiler(config)
self.adapter = adapter
self.node = node
self.node_index = node_index
Expand Down
5 changes: 1 addition & 4 deletions core/dbt/task/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from .seed import SeedRunner as seed_runner
from .test import TestRunner as test_runner

from dbt.adapters.factory import get_adapter
from dbt.contracts.results import NodeStatus
from dbt.common.exceptions import DbtInternalError
from dbt.graph import ResourceTypeSelector
Expand Down Expand Up @@ -129,6 +128,4 @@ def get_runner_type(self, node):
def compile_manifest(self):
if self.manifest is None:
raise DbtInternalError("compile_manifest called before manifest was loaded")
adapter = get_adapter(self.config)
compiler = adapter.get_compiler()
self.graph = compiler.compile(self.manifest, add_test_edges=True)
self.graph = self.compiler.compile(self.manifest, add_test_edges=True)
3 changes: 1 addition & 2 deletions core/dbt/task/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def execute(self, compiled_node, manifest):
)

def compile(self, manifest):
compiler = self.adapter.get_compiler()
return compiler.compile_node(self.node, manifest, {})
return self.compiler.compile_node(self.node, manifest, {})


class CompileTask(GraphRunnableTask):
Expand Down
6 changes: 4 additions & 2 deletions core/dbt/task/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,10 @@
return False

def get_hook_sql(self, adapter, hook, idx, num_hooks, extra_context) -> str:
compiler = adapter.get_compiler()
compiled = compiler.compile_node(hook, self.manifest, extra_context)
if self.manifest is None:
raise DbtInternalError("compile_node called before manifest was loaded")

Check warning on line 319 in core/dbt/task/run.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/task/run.py#L319

Added line #L319 was not covered by tests

compiled = self.compiler.compile_node(hook, self.manifest, extra_context)
statement = compiled.compiled_code
hook_index = hook.index or num_hooks
hook_obj = get_hook(statement, index=hook_index)
Expand Down
3 changes: 1 addition & 2 deletions core/dbt/task/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
pass

def compile(self, manifest):
compiler = self.adapter.get_compiler()
return compiler.compile_node(self.node, manifest, {}, write=False)
return self.compiler.compile_node(self.node, manifest, {}, write=False)

Check warning on line 40 in core/dbt/task/sql.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/task/sql.py#L40

Added line #L40 was not covered by tests

@abstractmethod
def execute(self, compiled_node, manifest) -> SQLResult:
Expand Down