Skip to content

Commit f26948d

Browse files
author
Jacob Beck
committed
remove archive blocks
1 parent 3cac2d3 commit f26948d

File tree

7 files changed

+164
-343
lines changed

7 files changed

+164
-343
lines changed

core/dbt/config/runtime.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(self, project_name, version, project_root, source_paths,
6464
self.validate()
6565

6666
@classmethod
67-
def from_parts(cls, project, profile, args):
67+
def from_parts(cls, project, profile, args, allow_archive_blocks=False):
6868
"""Instantiate a RuntimeConfig from its components.
6969
7070
:param profile Profile: A parsed dbt Profile.
@@ -77,6 +77,12 @@ def from_parts(cls, project, profile, args):
7777
.DEFAULTS['quote_policy']
7878
)
7979
quoting.update(project.quoting)
80+
if project.archive and not allow_archive_blocks:
81+
# if the user has an `archive` section, raise an error
82+
raise DbtProjectError(
83+
'Invalid project configuration: "archive" is not allowed'
84+
)
85+
8086
return cls(
8187
project_name=project.project_name,
8288
version=project.version,
@@ -163,12 +169,14 @@ def validate(self):
163169
self.validate_version()
164170

165171
@classmethod
166-
def from_args(cls, args):
172+
def from_args(cls, args, allow_archive_blocks=False):
167173
"""Given arguments, read in dbt_project.yml from the current directory,
168174
read in packages.yml if it exists, and use them to find the profile to
169175
load.
170176
171177
:param args argparse.Namespace: The arguments as parsed from the cli.
178+
:param allow_archive_blocks bool: If True, ignore archive blocks in
179+
configs. This flag exists to enable archive migration.
172180
:raises DbtProjectError: If the project is invalid or missing.
173181
:raises DbtProfileError: If the profile is invalid or missing.
174182
:raises ValidationException: If the cli variables are invalid.
@@ -185,5 +193,6 @@ def from_args(cls, args):
185193
return cls.from_parts(
186194
project=project,
187195
profile=profile,
188-
args=args
196+
args=args,
197+
allow_archive_blocks=allow_archive_blocks
189198
)

core/dbt/contracts/project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from dbt.logger import GLOBAL_LOGGER as logger # noqa
33
from dbt.utils import deep_merge
44

5-
# TODO: add description fields.
5+
66
ARCHIVE_TABLE_CONFIG_CONTRACT = {
77
'type': 'object',
88
'additionalProperties': False,

core/dbt/loader.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from dbt.utils import timestring
1111

1212
from dbt.parser import MacroParser, ModelParser, SeedParser, AnalysisParser, \
13-
DocumentationParser, DataTestParser, HookParser, ArchiveParser, \
14-
SchemaParser, ParserUtils, ArchiveBlockParser
13+
DocumentationParser, DataTestParser, HookParser, SchemaParser, \
14+
ParserUtils, ArchiveBlockParser
1515

1616
from dbt.contracts.project import ProjectList
1717

@@ -63,18 +63,6 @@ def _load_macros(self, internal_manifest=None):
6363
resource_type=NodeType.Macro,
6464
))
6565

66-
def _load_archives_from_project(self):
67-
archive_parser = ArchiveParser(self.root_project, self.all_projects,
68-
self.macro_manifest)
69-
for key, node in archive_parser.load_and_parse().items():
70-
# we have another archive parser, so we have to check for
71-
# collisions
72-
existing = self.nodes.get(key)
73-
if existing:
74-
dbt.exceptions.raise_duplicate_resource_name(existing, node)
75-
else:
76-
self.nodes[key] = node
77-
7866
def _load_seeds(self):
7967
parser = SeedParser(self.root_project, self.all_projects,
8068
self.macro_manifest)
@@ -98,7 +86,6 @@ def _load_nodes(self):
9886
self.macro_manifest)
9987
self.nodes.update(hook_parser.load_and_parse())
10088

101-
self._load_archives_from_project()
10289
self._load_seeds()
10390

10491
def _load_docs(self):

core/dbt/parser/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
from .analysis import AnalysisParser
3-
from .archives import ArchiveParser
43
from .archives import ArchiveBlockParser
54
from .data_test import DataTestParser
65
from .docs import DocumentationParser
@@ -14,7 +13,6 @@
1413

1514
__all__ = [
1615
'AnalysisParser',
17-
'ArchiveParser',
1816
'ArchiveBlockParser',
1917
'DataTestParser',
2018
'DocumentationParser',

core/dbt/parser/archives.py

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
from dbt.contracts.graph.unparsed import UnparsedNode
1+
22
from dbt.contracts.graph.parsed import ParsedArchiveNode
33
from dbt.node_types import NodeType
4-
from dbt.parser.base import MacrosKnownParser
54
from dbt.parser.base_sql import BaseSqlParser, SQLParseResult
6-
from dbt.adapters.factory import get_adapter
75
import dbt.clients.jinja
86
import dbt.exceptions
97
import dbt.utils
108

11-
import os
12-
139

1410
def set_archive_attributes(node):
1511
config_keys = {
@@ -24,93 +20,6 @@ def set_archive_attributes(node):
2420
return node
2521

2622

27-
class ArchiveParser(MacrosKnownParser):
28-
@classmethod
29-
def parse_archives_from_project(cls, config):
30-
archives = []
31-
archive_configs = config.archive
32-
33-
for archive_config in archive_configs:
34-
tables = archive_config.get('tables')
35-
36-
if tables is None:
37-
continue
38-
39-
for table in tables:
40-
cfg = table.copy()
41-
source_database = archive_config.get(
42-
'source_database',
43-
config.credentials.database
44-
)
45-
cfg['target_database'] = archive_config.get(
46-
'target_database',
47-
config.credentials.database
48-
)
49-
50-
source_schema = archive_config['source_schema']
51-
cfg['target_schema'] = archive_config.get('target_schema')
52-
# project-defined archives always use the 'timestamp' strategy.
53-
cfg['strategy'] = 'timestamp'
54-
55-
fake_path = [cfg['target_database'], cfg['target_schema'],
56-
cfg['target_table']]
57-
58-
relation = get_adapter(config).Relation.create(
59-
database=source_database,
60-
schema=source_schema,
61-
identifier=table['source_table'],
62-
type='table'
63-
)
64-
65-
raw_sql = '{{ config(materialized="archive") }}' + \
66-
'select * from {!s}'.format(relation)
67-
68-
archives.append({
69-
'name': table.get('target_table'),
70-
'root_path': config.project_root,
71-
'resource_type': NodeType.Archive,
72-
'path': os.path.join('archive', *fake_path),
73-
'original_file_path': 'dbt_project.yml',
74-
'package_name': config.project_name,
75-
'config': cfg,
76-
'raw_sql': raw_sql
77-
})
78-
79-
return archives
80-
81-
def load_and_parse(self):
82-
"""Load and parse archives in a list of projects. Returns a dict
83-
that maps unique ids onto ParsedNodes"""
84-
85-
archives = []
86-
to_return = {}
87-
88-
for name, project in self.all_projects.items():
89-
archives = archives + self.parse_archives_from_project(project)
90-
91-
# We're going to have a similar issue with parsed nodes, if we want to
92-
# make parse_node return those.
93-
for a in archives:
94-
# archives have a config, but that would make for an invalid
95-
# UnparsedNode, so remove it and pass it along to parse_node as an
96-
# argument.
97-
archive_config = a.pop('config')
98-
archive = UnparsedNode(**a)
99-
node_path = self.get_path(archive.resource_type,
100-
archive.package_name,
101-
archive.name)
102-
103-
parsed_node = self.parse_node(
104-
archive,
105-
node_path,
106-
self.all_projects.get(archive.package_name),
107-
archive_config=archive_config)
108-
109-
to_return[node_path] = set_archive_attributes(parsed_node)
110-
111-
return to_return
112-
113-
11423
class ArchiveBlockParser(BaseSqlParser):
11524
def parse_archives_from_file(self, file_node, tags=None):
11625
# the file node has a 'raw_sql' field that contains the jinja data with

0 commit comments

Comments
 (0)