dvt-core 0.58.6__cp311-cp311-macosx_10_9_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (324) hide show
  1. dbt/__init__.py +7 -0
  2. dbt/_pydantic_shim.py +26 -0
  3. dbt/artifacts/__init__.py +0 -0
  4. dbt/artifacts/exceptions/__init__.py +1 -0
  5. dbt/artifacts/exceptions/schemas.py +31 -0
  6. dbt/artifacts/resources/__init__.py +116 -0
  7. dbt/artifacts/resources/base.py +67 -0
  8. dbt/artifacts/resources/types.py +93 -0
  9. dbt/artifacts/resources/v1/analysis.py +10 -0
  10. dbt/artifacts/resources/v1/catalog.py +23 -0
  11. dbt/artifacts/resources/v1/components.py +274 -0
  12. dbt/artifacts/resources/v1/config.py +277 -0
  13. dbt/artifacts/resources/v1/documentation.py +11 -0
  14. dbt/artifacts/resources/v1/exposure.py +51 -0
  15. dbt/artifacts/resources/v1/function.py +52 -0
  16. dbt/artifacts/resources/v1/generic_test.py +31 -0
  17. dbt/artifacts/resources/v1/group.py +21 -0
  18. dbt/artifacts/resources/v1/hook.py +11 -0
  19. dbt/artifacts/resources/v1/macro.py +29 -0
  20. dbt/artifacts/resources/v1/metric.py +172 -0
  21. dbt/artifacts/resources/v1/model.py +145 -0
  22. dbt/artifacts/resources/v1/owner.py +10 -0
  23. dbt/artifacts/resources/v1/saved_query.py +111 -0
  24. dbt/artifacts/resources/v1/seed.py +41 -0
  25. dbt/artifacts/resources/v1/semantic_layer_components.py +72 -0
  26. dbt/artifacts/resources/v1/semantic_model.py +314 -0
  27. dbt/artifacts/resources/v1/singular_test.py +14 -0
  28. dbt/artifacts/resources/v1/snapshot.py +91 -0
  29. dbt/artifacts/resources/v1/source_definition.py +84 -0
  30. dbt/artifacts/resources/v1/sql_operation.py +10 -0
  31. dbt/artifacts/resources/v1/unit_test_definition.py +77 -0
  32. dbt/artifacts/schemas/__init__.py +0 -0
  33. dbt/artifacts/schemas/base.py +191 -0
  34. dbt/artifacts/schemas/batch_results.py +24 -0
  35. dbt/artifacts/schemas/catalog/__init__.py +11 -0
  36. dbt/artifacts/schemas/catalog/v1/__init__.py +0 -0
  37. dbt/artifacts/schemas/catalog/v1/catalog.py +59 -0
  38. dbt/artifacts/schemas/freshness/__init__.py +1 -0
  39. dbt/artifacts/schemas/freshness/v3/__init__.py +0 -0
  40. dbt/artifacts/schemas/freshness/v3/freshness.py +158 -0
  41. dbt/artifacts/schemas/manifest/__init__.py +2 -0
  42. dbt/artifacts/schemas/manifest/v12/__init__.py +0 -0
  43. dbt/artifacts/schemas/manifest/v12/manifest.py +211 -0
  44. dbt/artifacts/schemas/results.py +147 -0
  45. dbt/artifacts/schemas/run/__init__.py +2 -0
  46. dbt/artifacts/schemas/run/v5/__init__.py +0 -0
  47. dbt/artifacts/schemas/run/v5/run.py +184 -0
  48. dbt/artifacts/schemas/upgrades/__init__.py +4 -0
  49. dbt/artifacts/schemas/upgrades/upgrade_manifest.py +174 -0
  50. dbt/artifacts/schemas/upgrades/upgrade_manifest_dbt_version.py +2 -0
  51. dbt/artifacts/utils/validation.py +153 -0
  52. dbt/cli/__init__.py +1 -0
  53. dbt/cli/context.py +17 -0
  54. dbt/cli/exceptions.py +57 -0
  55. dbt/cli/flags.py +560 -0
  56. dbt/cli/main.py +2403 -0
  57. dbt/cli/option_types.py +121 -0
  58. dbt/cli/options.py +80 -0
  59. dbt/cli/params.py +844 -0
  60. dbt/cli/requires.py +490 -0
  61. dbt/cli/resolvers.py +50 -0
  62. dbt/cli/types.py +40 -0
  63. dbt/clients/__init__.py +0 -0
  64. dbt/clients/checked_load.py +83 -0
  65. dbt/clients/git.py +164 -0
  66. dbt/clients/jinja.py +206 -0
  67. dbt/clients/jinja_static.py +245 -0
  68. dbt/clients/registry.py +192 -0
  69. dbt/clients/yaml_helper.py +68 -0
  70. dbt/compilation.py +876 -0
  71. dbt/compute/__init__.py +14 -0
  72. dbt/compute/engines/__init__.py +12 -0
  73. dbt/compute/engines/spark_engine.cpython-311-darwin.so +0 -0
  74. dbt/compute/engines/spark_engine.py +642 -0
  75. dbt/compute/federated_executor.cpython-311-darwin.so +0 -0
  76. dbt/compute/federated_executor.py +1080 -0
  77. dbt/compute/filter_pushdown.cpython-311-darwin.so +0 -0
  78. dbt/compute/filter_pushdown.py +273 -0
  79. dbt/compute/jar_provisioning.cpython-311-darwin.so +0 -0
  80. dbt/compute/jar_provisioning.py +255 -0
  81. dbt/compute/java_compat.cpython-311-darwin.so +0 -0
  82. dbt/compute/java_compat.py +689 -0
  83. dbt/compute/jdbc_utils.cpython-311-darwin.so +0 -0
  84. dbt/compute/jdbc_utils.py +678 -0
  85. dbt/compute/metadata/__init__.py +40 -0
  86. dbt/compute/metadata/adapters_registry.cpython-311-darwin.so +0 -0
  87. dbt/compute/metadata/adapters_registry.py +370 -0
  88. dbt/compute/metadata/registry.cpython-311-darwin.so +0 -0
  89. dbt/compute/metadata/registry.py +674 -0
  90. dbt/compute/metadata/store.cpython-311-darwin.so +0 -0
  91. dbt/compute/metadata/store.py +1499 -0
  92. dbt/compute/smart_selector.cpython-311-darwin.so +0 -0
  93. dbt/compute/smart_selector.py +377 -0
  94. dbt/compute/strategies/__init__.py +55 -0
  95. dbt/compute/strategies/base.cpython-311-darwin.so +0 -0
  96. dbt/compute/strategies/base.py +165 -0
  97. dbt/compute/strategies/dataproc.cpython-311-darwin.so +0 -0
  98. dbt/compute/strategies/dataproc.py +207 -0
  99. dbt/compute/strategies/emr.cpython-311-darwin.so +0 -0
  100. dbt/compute/strategies/emr.py +203 -0
  101. dbt/compute/strategies/local.cpython-311-darwin.so +0 -0
  102. dbt/compute/strategies/local.py +443 -0
  103. dbt/compute/strategies/standalone.cpython-311-darwin.so +0 -0
  104. dbt/compute/strategies/standalone.py +262 -0
  105. dbt/config/__init__.py +4 -0
  106. dbt/config/catalogs.py +94 -0
  107. dbt/config/compute.cpython-311-darwin.so +0 -0
  108. dbt/config/compute.py +513 -0
  109. dbt/config/dvt_profile.cpython-311-darwin.so +0 -0
  110. dbt/config/dvt_profile.py +342 -0
  111. dbt/config/profile.py +422 -0
  112. dbt/config/project.py +873 -0
  113. dbt/config/project_utils.py +28 -0
  114. dbt/config/renderer.py +231 -0
  115. dbt/config/runtime.py +553 -0
  116. dbt/config/selectors.py +208 -0
  117. dbt/config/utils.py +77 -0
  118. dbt/constants.py +28 -0
  119. dbt/context/__init__.py +0 -0
  120. dbt/context/base.py +745 -0
  121. dbt/context/configured.py +135 -0
  122. dbt/context/context_config.py +382 -0
  123. dbt/context/docs.py +82 -0
  124. dbt/context/exceptions_jinja.py +178 -0
  125. dbt/context/macro_resolver.py +195 -0
  126. dbt/context/macros.py +171 -0
  127. dbt/context/manifest.py +72 -0
  128. dbt/context/providers.py +2249 -0
  129. dbt/context/query_header.py +13 -0
  130. dbt/context/secret.py +58 -0
  131. dbt/context/target.py +74 -0
  132. dbt/contracts/__init__.py +0 -0
  133. dbt/contracts/files.py +413 -0
  134. dbt/contracts/graph/__init__.py +0 -0
  135. dbt/contracts/graph/manifest.py +1904 -0
  136. dbt/contracts/graph/metrics.py +97 -0
  137. dbt/contracts/graph/model_config.py +70 -0
  138. dbt/contracts/graph/node_args.py +42 -0
  139. dbt/contracts/graph/nodes.py +1806 -0
  140. dbt/contracts/graph/semantic_manifest.py +232 -0
  141. dbt/contracts/graph/unparsed.py +811 -0
  142. dbt/contracts/project.py +417 -0
  143. dbt/contracts/results.py +53 -0
  144. dbt/contracts/selection.py +23 -0
  145. dbt/contracts/sql.py +85 -0
  146. dbt/contracts/state.py +68 -0
  147. dbt/contracts/util.py +46 -0
  148. dbt/deprecations.py +348 -0
  149. dbt/deps/__init__.py +0 -0
  150. dbt/deps/base.py +152 -0
  151. dbt/deps/git.py +195 -0
  152. dbt/deps/local.py +79 -0
  153. dbt/deps/registry.py +130 -0
  154. dbt/deps/resolver.py +149 -0
  155. dbt/deps/tarball.py +120 -0
  156. dbt/docs/source/_ext/dbt_click.py +119 -0
  157. dbt/docs/source/conf.py +32 -0
  158. dbt/env_vars.py +64 -0
  159. dbt/event_time/event_time.py +40 -0
  160. dbt/event_time/sample_window.py +60 -0
  161. dbt/events/__init__.py +15 -0
  162. dbt/events/base_types.py +36 -0
  163. dbt/events/core_types_pb2.py +2 -0
  164. dbt/events/logging.py +108 -0
  165. dbt/events/types.py +2516 -0
  166. dbt/exceptions.py +1486 -0
  167. dbt/flags.py +89 -0
  168. dbt/graph/__init__.py +11 -0
  169. dbt/graph/cli.py +249 -0
  170. dbt/graph/graph.py +172 -0
  171. dbt/graph/queue.py +214 -0
  172. dbt/graph/selector.py +374 -0
  173. dbt/graph/selector_methods.py +975 -0
  174. dbt/graph/selector_spec.py +222 -0
  175. dbt/graph/thread_pool.py +18 -0
  176. dbt/hooks.py +21 -0
  177. dbt/include/README.md +49 -0
  178. dbt/include/__init__.py +3 -0
  179. dbt/include/data/adapters_registry.duckdb +0 -0
  180. dbt/include/data/build_registry.py +242 -0
  181. dbt/include/data/csv/adapter_queries.csv +33 -0
  182. dbt/include/data/csv/syntax_rules.csv +9 -0
  183. dbt/include/data/csv/type_mappings_bigquery.csv +28 -0
  184. dbt/include/data/csv/type_mappings_databricks.csv +30 -0
  185. dbt/include/data/csv/type_mappings_mysql.csv +40 -0
  186. dbt/include/data/csv/type_mappings_oracle.csv +30 -0
  187. dbt/include/data/csv/type_mappings_postgres.csv +56 -0
  188. dbt/include/data/csv/type_mappings_redshift.csv +33 -0
  189. dbt/include/data/csv/type_mappings_snowflake.csv +38 -0
  190. dbt/include/data/csv/type_mappings_sqlserver.csv +35 -0
  191. dbt/include/starter_project/.gitignore +4 -0
  192. dbt/include/starter_project/README.md +15 -0
  193. dbt/include/starter_project/__init__.py +3 -0
  194. dbt/include/starter_project/analyses/.gitkeep +0 -0
  195. dbt/include/starter_project/dbt_project.yml +36 -0
  196. dbt/include/starter_project/macros/.gitkeep +0 -0
  197. dbt/include/starter_project/models/example/my_first_dbt_model.sql +27 -0
  198. dbt/include/starter_project/models/example/my_second_dbt_model.sql +6 -0
  199. dbt/include/starter_project/models/example/schema.yml +21 -0
  200. dbt/include/starter_project/seeds/.gitkeep +0 -0
  201. dbt/include/starter_project/snapshots/.gitkeep +0 -0
  202. dbt/include/starter_project/tests/.gitkeep +0 -0
  203. dbt/internal_deprecations.py +26 -0
  204. dbt/jsonschemas/__init__.py +3 -0
  205. dbt/jsonschemas/jsonschemas.py +309 -0
  206. dbt/jsonschemas/project/0.0.110.json +4717 -0
  207. dbt/jsonschemas/project/0.0.85.json +2015 -0
  208. dbt/jsonschemas/resources/0.0.110.json +2636 -0
  209. dbt/jsonschemas/resources/0.0.85.json +2536 -0
  210. dbt/jsonschemas/resources/latest.json +6773 -0
  211. dbt/links.py +4 -0
  212. dbt/materializations/__init__.py +0 -0
  213. dbt/materializations/incremental/__init__.py +0 -0
  214. dbt/materializations/incremental/microbatch.py +236 -0
  215. dbt/mp_context.py +8 -0
  216. dbt/node_types.py +37 -0
  217. dbt/parser/__init__.py +23 -0
  218. dbt/parser/analysis.py +21 -0
  219. dbt/parser/base.py +548 -0
  220. dbt/parser/common.py +266 -0
  221. dbt/parser/docs.py +52 -0
  222. dbt/parser/fixtures.py +51 -0
  223. dbt/parser/functions.py +30 -0
  224. dbt/parser/generic_test.py +100 -0
  225. dbt/parser/generic_test_builders.py +333 -0
  226. dbt/parser/hooks.py +118 -0
  227. dbt/parser/macros.py +137 -0
  228. dbt/parser/manifest.py +2204 -0
  229. dbt/parser/models.py +573 -0
  230. dbt/parser/partial.py +1178 -0
  231. dbt/parser/read_files.py +445 -0
  232. dbt/parser/schema_generic_tests.py +422 -0
  233. dbt/parser/schema_renderer.py +111 -0
  234. dbt/parser/schema_yaml_readers.py +935 -0
  235. dbt/parser/schemas.py +1466 -0
  236. dbt/parser/search.py +149 -0
  237. dbt/parser/seeds.py +28 -0
  238. dbt/parser/singular_test.py +20 -0
  239. dbt/parser/snapshots.py +44 -0
  240. dbt/parser/sources.py +558 -0
  241. dbt/parser/sql.py +62 -0
  242. dbt/parser/unit_tests.py +621 -0
  243. dbt/plugins/__init__.py +20 -0
  244. dbt/plugins/contracts.py +9 -0
  245. dbt/plugins/exceptions.py +2 -0
  246. dbt/plugins/manager.py +163 -0
  247. dbt/plugins/manifest.py +21 -0
  248. dbt/profiler.py +20 -0
  249. dbt/py.typed +1 -0
  250. dbt/query_analyzer.cpython-311-darwin.so +0 -0
  251. dbt/query_analyzer.py +410 -0
  252. dbt/runners/__init__.py +2 -0
  253. dbt/runners/exposure_runner.py +7 -0
  254. dbt/runners/no_op_runner.py +45 -0
  255. dbt/runners/saved_query_runner.py +7 -0
  256. dbt/selected_resources.py +8 -0
  257. dbt/task/__init__.py +0 -0
  258. dbt/task/base.py +503 -0
  259. dbt/task/build.py +197 -0
  260. dbt/task/clean.py +56 -0
  261. dbt/task/clone.py +161 -0
  262. dbt/task/compile.py +150 -0
  263. dbt/task/compute.cpython-311-darwin.so +0 -0
  264. dbt/task/compute.py +458 -0
  265. dbt/task/debug.py +505 -0
  266. dbt/task/deps.py +280 -0
  267. dbt/task/docs/__init__.py +3 -0
  268. dbt/task/docs/api/__init__.py +23 -0
  269. dbt/task/docs/api/catalog.cpython-311-darwin.so +0 -0
  270. dbt/task/docs/api/catalog.py +204 -0
  271. dbt/task/docs/api/lineage.cpython-311-darwin.so +0 -0
  272. dbt/task/docs/api/lineage.py +234 -0
  273. dbt/task/docs/api/profile.cpython-311-darwin.so +0 -0
  274. dbt/task/docs/api/profile.py +204 -0
  275. dbt/task/docs/api/spark.cpython-311-darwin.so +0 -0
  276. dbt/task/docs/api/spark.py +186 -0
  277. dbt/task/docs/generate.py +947 -0
  278. dbt/task/docs/index.html +250 -0
  279. dbt/task/docs/serve.cpython-311-darwin.so +0 -0
  280. dbt/task/docs/serve.py +174 -0
  281. dbt/task/dvt_output.py +362 -0
  282. dbt/task/dvt_run.py +204 -0
  283. dbt/task/freshness.py +322 -0
  284. dbt/task/function.py +121 -0
  285. dbt/task/group_lookup.py +46 -0
  286. dbt/task/init.cpython-311-darwin.so +0 -0
  287. dbt/task/init.py +604 -0
  288. dbt/task/java.cpython-311-darwin.so +0 -0
  289. dbt/task/java.py +316 -0
  290. dbt/task/list.py +236 -0
  291. dbt/task/metadata.cpython-311-darwin.so +0 -0
  292. dbt/task/metadata.py +804 -0
  293. dbt/task/printer.py +175 -0
  294. dbt/task/profile.cpython-311-darwin.so +0 -0
  295. dbt/task/profile.py +1307 -0
  296. dbt/task/profile_serve.py +615 -0
  297. dbt/task/retract.py +438 -0
  298. dbt/task/retry.py +175 -0
  299. dbt/task/run.py +1387 -0
  300. dbt/task/run_operation.py +141 -0
  301. dbt/task/runnable.py +758 -0
  302. dbt/task/seed.py +103 -0
  303. dbt/task/show.py +149 -0
  304. dbt/task/snapshot.py +56 -0
  305. dbt/task/spark.cpython-311-darwin.so +0 -0
  306. dbt/task/spark.py +414 -0
  307. dbt/task/sql.py +110 -0
  308. dbt/task/target_sync.cpython-311-darwin.so +0 -0
  309. dbt/task/target_sync.py +766 -0
  310. dbt/task/test.py +464 -0
  311. dbt/tests/fixtures/__init__.py +1 -0
  312. dbt/tests/fixtures/project.py +620 -0
  313. dbt/tests/util.py +651 -0
  314. dbt/tracking.py +529 -0
  315. dbt/utils/__init__.py +3 -0
  316. dbt/utils/artifact_upload.py +151 -0
  317. dbt/utils/utils.py +408 -0
  318. dbt/version.py +270 -0
  319. dvt_cli/__init__.py +72 -0
  320. dvt_core-0.58.6.dist-info/METADATA +288 -0
  321. dvt_core-0.58.6.dist-info/RECORD +324 -0
  322. dvt_core-0.58.6.dist-info/WHEEL +5 -0
  323. dvt_core-0.58.6.dist-info/entry_points.txt +2 -0
  324. dvt_core-0.58.6.dist-info/top_level.txt +2 -0
dbt/task/run.py ADDED
@@ -0,0 +1,1387 @@
1
+ from __future__ import annotations
2
+
3
+ import functools
4
+ import threading
5
+ import time
6
+ from copy import deepcopy
7
+ from dataclasses import asdict
8
+ from datetime import datetime, timezone
9
+ from typing import AbstractSet, Any, Dict, Iterable, List, Optional, Set, Tuple, Type
10
+
11
+ from dbt import tracking, utils
12
+ from dbt.adapters.base import BaseAdapter, BaseRelation
13
+ from dbt.adapters.capability import Capability
14
+ from dbt.adapters.events.types import FinishedRunningStats
15
+ from dbt.adapters.exceptions import MissingMaterializationError
16
+ from dbt.artifacts.resources import Hook
17
+ from dbt.artifacts.schemas.batch_results import BatchResults, BatchType
18
+ from dbt.artifacts.schemas.results import (
19
+ NodeStatus,
20
+ RunningStatus,
21
+ RunStatus,
22
+ TimingInfo,
23
+ collect_timing_info,
24
+ )
25
+ from dbt.artifacts.schemas.run import RunResult
26
+ from dbt.cli.flags import Flags
27
+ from dbt.clients.jinja import MacroGenerator
28
+ from dbt.config import RuntimeConfig
29
+ from dbt.context.providers import generate_runtime_model_context
30
+ from dbt.contracts.graph.manifest import Manifest
31
+ from dbt.contracts.graph.nodes import BatchContext, HookNode, ModelNode, ResultNode
32
+ from dbt.events.types import (
33
+ GenericExceptionOnRun,
34
+ LogBatchResult,
35
+ LogHookEndLine,
36
+ LogHookStartLine,
37
+ LogModelResult,
38
+ LogStartBatch,
39
+ LogStartLine,
40
+ MicrobatchExecutionDebug,
41
+ )
42
+ from dbt.exceptions import CompilationError, DbtInternalError, DbtRuntimeError, DbtValidationError
43
+ from dbt.graph import ResourceTypeSelector
44
+ from dbt.graph.thread_pool import DbtThreadPool
45
+ from dbt.hooks import get_hook_dict
46
+ from dbt.materializations.incremental.microbatch import MicrobatchBuilder
47
+ from dbt.node_types import NodeType, RunHookType
48
+ from dbt.task import group_lookup
49
+ from dbt.task.base import BaseRunner
50
+ from dbt.task.compile import CompileRunner, CompileTask
51
+ # DVT: Import query analysis and federated execution components
52
+ from dbt.query_analyzer import QueryAnalyzer
53
+ from dbt.compute.federated_executor import FederatedExecutor
54
+ from dbt.compute.smart_selector import SmartComputeSelector
55
+ from dbt.task.printer import get_counts, print_run_end_messages
56
+ from dbt.utils.artifact_upload import add_artifact_produced
57
+ from dbt_common.clients.jinja import MacroProtocol
58
+ from dbt_common.dataclass_schema import dbtClassMixin
59
+ from dbt_common.events.base_types import EventLevel
60
+ from dbt_common.events.contextvars import log_contextvars
61
+ from dbt_common.events.functions import fire_event, get_invocation_id
62
+ from dbt_common.events.types import Formatting
63
+ from dbt_common.exceptions import DbtValidationError
64
+ from dbt_common.invocation import get_invocation_started_at
65
+
66
+
67
+ @functools.total_ordering
68
+ class BiggestName(str):
69
+ def __lt__(self, other):
70
+ return True
71
+
72
+ def __eq__(self, other):
73
+ return isinstance(other, self.__class__)
74
+
75
+
76
+ def _hook_list() -> List[HookNode]:
77
+ return []
78
+
79
+
80
+ def get_hooks_by_tags(
81
+ nodes: Iterable[ResultNode],
82
+ match_tags: Set[str],
83
+ ) -> List[HookNode]:
84
+ matched_nodes = []
85
+ for node in nodes:
86
+ if not isinstance(node, HookNode):
87
+ continue
88
+ node_tags = node.tags
89
+ if len(set(node_tags) & match_tags):
90
+ matched_nodes.append(node)
91
+ return matched_nodes
92
+
93
+
94
+ def get_hook(source, index):
95
+ hook_dict = get_hook_dict(source)
96
+ hook_dict.setdefault("index", index)
97
+ Hook.validate(hook_dict)
98
+ return Hook.from_dict(hook_dict)
99
+
100
+
101
+ def get_execution_status(sql: str, adapter: BaseAdapter) -> Tuple[RunStatus, str]:
102
+ if not sql.strip():
103
+ return RunStatus.Success, "OK"
104
+
105
+ try:
106
+ response, _ = adapter.execute(sql, auto_begin=False, fetch=False)
107
+ status = RunStatus.Success
108
+ message = response._message
109
+ except (KeyboardInterrupt, SystemExit):
110
+ raise
111
+ except DbtRuntimeError as exc:
112
+ status = RunStatus.Error
113
+ message = exc.msg
114
+ except Exception as exc:
115
+ status = RunStatus.Error
116
+ message = str(exc)
117
+
118
+ return (status, message)
119
+
120
+
121
+ def _get_adapter_info(adapter, run_model_result) -> Dict[str, Any]:
122
+ """Each adapter returns a dataclass with a flexible dictionary for
123
+ adapter-specific fields. Only the non-'model_adapter_details' fields
124
+ are guaranteed cross adapter."""
125
+ return asdict(adapter.get_adapter_run_info(run_model_result.node.config)) if adapter else {}
126
+
127
+
128
+ def track_model_run(index, num_nodes, run_model_result, adapter=None):
129
+ if tracking.active_user is None:
130
+ raise DbtInternalError("cannot track model run with no active user")
131
+ invocation_id = get_invocation_id()
132
+ node = run_model_result.node
133
+ has_group = True if hasattr(node, "group") and node.group else False
134
+ if node.resource_type == NodeType.Model:
135
+ access = node.access.value if node.access is not None else None
136
+ contract_enforced = node.contract.enforced
137
+ versioned = True if node.version else False
138
+ incremental_strategy = node.config.incremental_strategy
139
+ else:
140
+ access = None
141
+ contract_enforced = False
142
+ versioned = False
143
+ incremental_strategy = None
144
+
145
+ tracking.track_model_run(
146
+ {
147
+ "invocation_id": invocation_id,
148
+ "index": index,
149
+ "total": num_nodes,
150
+ "execution_time": run_model_result.execution_time,
151
+ "run_status": str(run_model_result.status).upper(),
152
+ "run_skipped": run_model_result.status == NodeStatus.Skipped,
153
+ "run_error": run_model_result.status == NodeStatus.Error,
154
+ "model_materialization": node.get_materialization(),
155
+ "model_incremental_strategy": incremental_strategy,
156
+ "model_id": utils.get_hash(node),
157
+ "hashed_contents": utils.get_hashed_contents(node),
158
+ "timing": [t.to_dict(omit_none=True) for t in run_model_result.timing],
159
+ "language": str(node.language),
160
+ "has_group": has_group,
161
+ "contract_enforced": contract_enforced,
162
+ "access": access,
163
+ "versioned": versioned,
164
+ "adapter_info": _get_adapter_info(adapter, run_model_result),
165
+ }
166
+ )
167
+
168
+
169
+ # make sure that we got an ok result back from a materialization
170
+ def _validate_materialization_relations_dict(inp: Dict[Any, Any], model) -> List[BaseRelation]:
171
+ try:
172
+ relations_value = inp["relations"]
173
+ except KeyError:
174
+ msg = (
175
+ 'Invalid return value from materialization, "relations" '
176
+ "not found, got keys: {}".format(list(inp))
177
+ )
178
+ raise CompilationError(msg, node=model) from None
179
+
180
+ if not isinstance(relations_value, list):
181
+ msg = (
182
+ 'Invalid return value from materialization, "relations" '
183
+ "not a list, got: {}".format(relations_value)
184
+ )
185
+ raise CompilationError(msg, node=model) from None
186
+
187
+ relations: List[BaseRelation] = []
188
+ for relation in relations_value:
189
+ if not isinstance(relation, BaseRelation):
190
+ msg = (
191
+ "Invalid return value from materialization, "
192
+ '"relations" contains non-Relation: {}'.format(relation)
193
+ )
194
+ raise CompilationError(msg, node=model)
195
+
196
+ assert isinstance(relation, BaseRelation)
197
+ relations.append(relation)
198
+ return relations
199
+
200
+
201
+ class ModelRunner(CompileRunner):
202
+ def get_node_representation(self):
203
+ display_quote_policy = {"database": False, "schema": False, "identifier": False}
204
+ relation = self.adapter.Relation.create_from(
205
+ self.config, self.node, quote_policy=display_quote_policy
206
+ )
207
+ # exclude the database from output if it's the default
208
+ if self.node.database == self.config.credentials.database:
209
+ relation = relation.include(database=False)
210
+ return str(relation)
211
+
212
+ def describe_node(self) -> str:
213
+ # TODO CL 'language' will be moved to node level when we change representation
214
+ return f"{self.node.language} {self.node.get_materialization()} model {self.get_node_representation()}"
215
+
216
+ def print_start_line(self):
217
+ fire_event(
218
+ LogStartLine(
219
+ description=self.describe_node(),
220
+ index=self.node_index,
221
+ total=self.num_nodes,
222
+ node_info=self.node.node_info,
223
+ )
224
+ )
225
+
226
+ def print_result_line(self, result):
227
+ description = self.describe_node()
228
+ group = group_lookup.get(self.node.unique_id)
229
+ if result.status == NodeStatus.Error:
230
+ status = result.status
231
+ level = EventLevel.ERROR
232
+ else:
233
+ status = result.message
234
+ level = EventLevel.INFO
235
+ fire_event(
236
+ LogModelResult(
237
+ description=description,
238
+ status=status,
239
+ index=self.node_index,
240
+ total=self.num_nodes,
241
+ execution_time=result.execution_time,
242
+ node_info=self.node.node_info,
243
+ group=group,
244
+ ),
245
+ level=level,
246
+ )
247
+
248
+ def before_execute(self) -> None:
249
+ self.print_start_line()
250
+
251
+ def after_execute(self, result) -> None:
252
+ track_model_run(self.node_index, self.num_nodes, result, adapter=self.adapter)
253
+ self.print_result_line(result)
254
+
255
+ def _build_run_model_result(self, model, context, elapsed_time: float = 0.0):
256
+ result = context["load_result"]("main")
257
+ if not result:
258
+ raise DbtRuntimeError("main is not being called during running model")
259
+ adapter_response = {}
260
+ if isinstance(result.response, dbtClassMixin):
261
+ adapter_response = result.response.to_dict(omit_none=True)
262
+ return RunResult(
263
+ node=model,
264
+ status=RunStatus.Success,
265
+ timing=[],
266
+ thread_id=threading.current_thread().name,
267
+ execution_time=elapsed_time,
268
+ message=str(result.response),
269
+ adapter_response=adapter_response,
270
+ failures=result.get("failures"),
271
+ batch_results=None,
272
+ )
273
+
274
+ def _materialization_relations(self, result: Any, model) -> List[BaseRelation]:
275
+ if isinstance(result, str):
276
+ msg = (
277
+ 'The materialization ("{}") did not explicitly return a '
278
+ "list of relations to add to the cache.".format(str(model.get_materialization()))
279
+ )
280
+ raise CompilationError(msg, node=model)
281
+
282
+ if isinstance(result, dict):
283
+ return _validate_materialization_relations_dict(result, model)
284
+
285
+ msg = (
286
+ "Invalid return value from materialization, expected a dict "
287
+ 'with key "relations", got: {}'.format(str(result))
288
+ )
289
+ raise CompilationError(msg, node=model)
290
+
291
+ def _execute_model(
292
+ self,
293
+ hook_ctx: Any,
294
+ context_config: Any,
295
+ model: ModelNode,
296
+ context: Dict[str, Any],
297
+ materialization_macro: MacroProtocol,
298
+ ) -> RunResult:
299
+ try:
300
+ result = MacroGenerator(
301
+ materialization_macro, context, stack=context["context_macro_stack"]
302
+ )()
303
+ finally:
304
+ self.adapter.post_model_hook(context_config, hook_ctx)
305
+
306
+ for relation in self._materialization_relations(result, model):
307
+ self.adapter.cache_added(relation.incorporate(dbt_created=True))
308
+
309
+ return self._build_run_model_result(model, context)
310
+
311
+ def execute(self, model, manifest):
312
+ # DVT: Analyze query for execution strategy
313
+ analyzer = QueryAnalyzer(manifest)
314
+
315
+ # DVT v0.51.1: Fix --target-compute logic
316
+ # CLI --target-compute should ONLY override models that:
317
+ # 1. Already have compute= config in their model definition, OR
318
+ # 2. Require federated execution (multi-source)
319
+ #
320
+ # Models without compute= config should ALWAYS favor pushdown
321
+ # (adapter-native execution) when possible.
322
+ cli_compute = getattr(self.config.args, 'TARGET_COMPUTE', None)
323
+ model_compute = model.config.compute if hasattr(model.config, 'compute') else None
324
+
325
+ # DVT v0.51.6: Target Hierarchy (Rule 2.1):
326
+ # Level 1 (Lowest): profiles.yml default target
327
+ # Level 2: Model-specific target config
328
+ # Level 3 (Highest): CLI --target argument (Forces Global Target Override)
329
+ #
330
+ # Rule 2.2: If CLI --target is used, ALL models are forced to materialize in this target.
331
+ cli_target = getattr(self.config.args, 'TARGET', None)
332
+ model_target = model.config.target if hasattr(model.config, 'target') else None
333
+
334
+ # CLI --target (Level 3) overrides model config (Level 2) which overrides profile default (Level 1)
335
+ if cli_target:
336
+ target_connection = cli_target # CLI always wins
337
+ elif model_target:
338
+ target_connection = model_target # Model config
339
+ else:
340
+ target_connection = self.config.target_name # Profile default
341
+
342
+ # First, analyze WITHOUT any compute override to see if federation is required
343
+ # Pass target_connection to detect cross-adapter scenarios
344
+ natural_analysis = analyzer.analyze(
345
+ model,
346
+ user_compute_override=None,
347
+ target_connection=target_connection
348
+ )
349
+
350
+ # DVT v0.51.6: Rule 3.C.3 - View coercion in cross-target scenarios
351
+ # Views are SQL definitions that reference tables by name.
352
+ # You CANNOT create a cross-database view - it's physically impossible.
353
+ # If federation is required, views MUST be coerced to tables with a warning.
354
+ materialization = model.get_materialization()
355
+ convert_view_to_table = False
356
+ if materialization == 'view' and natural_analysis.is_federated:
357
+ convert_view_to_table = True
358
+ # Rule 3.C.3: Log warning about view coercion
359
+ import sys
360
+ print(
361
+ f"[DVT Warning] Model '{model.name}' is configured as 'view' but requires federation. "
362
+ f"Materializing as TABLE instead. (Cross-database views are not supported)",
363
+ file=sys.stderr
364
+ )
365
+
366
+ # DVT v0.51.6: Rule 1.5 - Compute engine only applies to Federation path
367
+ # Compute Selection Hierarchy (Rule 1.3):
368
+ # Level 1: Default compute in computes.yml
369
+ # Level 2: Model-specific compute config
370
+ # Level 3: CLI --compute argument
371
+ # BUT: Compute settings are IGNORED for Pushdown-eligible models (Rule 1.5)
372
+
373
+ if natural_analysis.is_federated:
374
+ # Federation required - apply compute hierarchy
375
+ if cli_compute:
376
+ user_compute = cli_compute # Level 3 (highest)
377
+ elif model_compute:
378
+ user_compute = model_compute # Level 2
379
+ else:
380
+ user_compute = None # Will use Level 1 default from selector
381
+ else:
382
+ # Pushdown-eligible - Rule 1.5: IGNORE compute settings
383
+ user_compute = None
384
+
385
+ # Use the natural analysis (compute override doesn't change pushdown/federation decision)
386
+ analysis = natural_analysis
387
+
388
+ # Get target adapter (for materialization)
389
+ # DVT v0.51.6: Use target_connection which follows Rule 2.1 hierarchy
390
+ target_adapter = self.config.get_adapter(target_connection)
391
+
392
+ if analysis.is_pushdown:
393
+ # Pushdown execution: Use source adapter directly
394
+ execution_adapter = self.config.get_adapter(analysis.primary_connection)
395
+
396
+ context = generate_runtime_model_context(model, self.config, manifest)
397
+
398
+ # Execute using existing path but with correct adapter
399
+ materialization_macro = manifest.find_materialization_macro_by_name(
400
+ self.config.project_name,
401
+ model.get_materialization(),
402
+ execution_adapter.type()
403
+ )
404
+
405
+ if materialization_macro is None:
406
+ raise MissingMaterializationError(
407
+ materialization=model.get_materialization(), adapter_type=execution_adapter.type()
408
+ )
409
+
410
+ if "config" not in context:
411
+ raise DbtInternalError(
412
+ "Invalid materialization context generated, missing config: {}".format(context)
413
+ )
414
+ context_config = context["config"]
415
+
416
+ mat_has_supported_langs = hasattr(materialization_macro, "supported_languages")
417
+ model_lang_supported = model.language in materialization_macro.supported_languages
418
+ if mat_has_supported_langs and not model_lang_supported:
419
+ str_langs = [str(lang) for lang in materialization_macro.supported_languages]
420
+ raise DbtValidationError(
421
+ f'Materialization "{materialization_macro.name}" only supports languages {str_langs}; '
422
+ f'got "{model.language}"'
423
+ )
424
+
425
+ # Run hooks
426
+ hook_ctx = execution_adapter.pre_model_hook(context_config)
427
+ result = self._execute_model(hook_ctx, context_config, model, context, materialization_macro)
428
+
429
+ return result
430
+ else:
431
+ # Federated execution: Use compute layer
432
+ executor = FederatedExecutor(
433
+ manifest=manifest,
434
+ adapters=self.config.adapters or {},
435
+ default_compute_engine='spark-local'
436
+ )
437
+
438
+ # Select compute engine
439
+ if user_compute:
440
+ compute_engine = user_compute
441
+ else:
442
+ selector = SmartComputeSelector(manifest)
443
+ compute_engine = selector.select_engine(model, analysis)
444
+
445
+ # Execute federally (pass target adapter type for JDBC materialization)
446
+ # DVT v0.51.6: Pass view coercion flag so executor treats view as table
447
+ fed_result = executor.execute(
448
+ node=model,
449
+ analysis_result=analysis,
450
+ compute_engine_override=compute_engine,
451
+ target_adapter_type=target_adapter.type() if target_adapter else None,
452
+ coerce_view_to_table=convert_view_to_table,
453
+ )
454
+
455
+ try:
456
+ # Materialize to target via Spark JDBC
457
+ # DVT v0.51.7: Use 3-part naming (database.schema.table) for adapters like Databricks
458
+ if hasattr(model, 'database') and model.database:
459
+ target_table = f"{model.database}.{model.schema}.{model.alias}"
460
+ else:
461
+ target_table = f"{model.schema}.{model.alias}"
462
+
463
+ # Get Spark DataFrame from result
464
+ spark_df = fed_result.spark_dataframe
465
+
466
+ # DVT v0.58.6: Inline JDBC write to avoid segfault with FederatedExecutor method call
467
+ # This is a known issue with PySpark 4.0 + Java 21 on macOS
468
+ from dbt.compute.jdbc_utils import build_jdbc_config
469
+ from dbt.adapters.contracts.connection import AdapterResponse
470
+
471
+ target_credentials = target_adapter.config.credentials
472
+ jdbc_url, jdbc_properties = build_jdbc_config(target_credentials)
473
+
474
+ # Write to target via Spark JDBC
475
+ spark_df.write.jdbc(
476
+ jdbc_url,
477
+ target_table,
478
+ mode="overwrite",
479
+ properties=jdbc_properties
480
+ )
481
+
482
+ adapter_response = AdapterResponse(_message="DVT: Federated JDBC write completed")
483
+
484
+ # Return result in expected format
485
+ rows_affected = getattr(adapter_response, 'rows_affected', 0)
486
+ rows_msg = f"{rows_affected} rows" if rows_affected else "completed"
487
+ # DVT v0.51.5: Note when view was materialized as table
488
+ exec_msg = f"Federated execution: {rows_msg}"
489
+ if convert_view_to_table:
490
+ exec_msg = f"Federated (view→table): {rows_msg}"
491
+ return RunResult(
492
+ status=RunStatus.Success,
493
+ timing=[],
494
+ thread_id='main',
495
+ execution_time=fed_result.execution_time_ms / 1000.0,
496
+ adapter_response=adapter_response._asdict() if hasattr(adapter_response, '_asdict') else {},
497
+ message=exec_msg,
498
+ failures=None,
499
+ node=model,
500
+ agate_table=None,
501
+ )
502
+ finally:
503
+ # Always close Spark session after materialization
504
+ if fed_result.engine:
505
+ try:
506
+ fed_result.engine.close()
507
+ except Exception as e:
508
+ # Log but don't fail on cleanup errors
509
+ import sys
510
+ print(f"[DVT] Warning: Failed to close Spark session: {e}", file=sys.stderr)
511
+
512
+
513
+ class MicrobatchBatchRunner(ModelRunner):
514
+ """Handles the running of individual batches"""
515
+
516
+ def __init__(
517
+ self,
518
+ config,
519
+ adapter,
520
+ node,
521
+ node_index: int,
522
+ num_nodes: int,
523
+ batch_idx: int,
524
+ batches: Dict[int, BatchType],
525
+ relation_exists: bool,
526
+ incremental_batch: bool,
527
+ ):
528
+ super().__init__(config, adapter, node, node_index, num_nodes)
529
+
530
+ self.batch_idx = batch_idx
531
+ self.batches = batches
532
+ self.relation_exists = relation_exists
533
+ self.incremental_batch = incremental_batch
534
+
535
+ def describe_batch(self) -> str:
536
+ batch_start = self.batches[self.batch_idx][0]
537
+ formatted_batch_start = MicrobatchBuilder.format_batch_start(
538
+ batch_start, self.node.config.batch_size
539
+ )
540
+ return f"batch {formatted_batch_start} of {self.get_node_representation()}"
541
+
542
+ def print_result_line(self, result: RunResult):
543
+ if result.status == NodeStatus.Error:
544
+ status = result.status
545
+ level = EventLevel.ERROR
546
+ elif result.status == NodeStatus.Skipped:
547
+ status = result.status
548
+ level = EventLevel.INFO
549
+ else:
550
+ status = result.message
551
+ level = EventLevel.INFO
552
+
553
+ fire_event(
554
+ LogBatchResult(
555
+ description=self.describe_batch(),
556
+ status=status,
557
+ batch_index=self.batch_idx + 1,
558
+ total_batches=len(self.batches),
559
+ execution_time=result.execution_time,
560
+ node_info=self.node.node_info,
561
+ group=group_lookup.get(self.node.unique_id),
562
+ ),
563
+ level=level,
564
+ )
565
+
566
+ def print_start_line(self) -> None:
567
+ fire_event(
568
+ LogStartBatch(
569
+ description=self.describe_batch(),
570
+ batch_index=self.batch_idx + 1,
571
+ total_batches=len(self.batches),
572
+ node_info=self.node.node_info,
573
+ )
574
+ )
575
+
576
+ def should_run_in_parallel(self) -> bool:
577
+ if not self.adapter.supports(Capability.MicrobatchConcurrency):
578
+ run_in_parallel = False
579
+ elif not self.relation_exists:
580
+ # If the relation doesn't exist, we can't run in parallel
581
+ run_in_parallel = False
582
+ elif self.node.config.concurrent_batches is not None:
583
+ # If the relation exists and the `concurrent_batches` config isn't None, use the config value
584
+ run_in_parallel = self.node.config.concurrent_batches
585
+ else:
586
+ # If the relation exists, the `concurrent_batches` config is None, check if the model self references `this`.
587
+ # If the model self references `this` then we assume the model batches _can't_ be run in parallel
588
+ run_in_parallel = not self.node.has_this
589
+
590
+ return run_in_parallel
591
+
592
+ def on_skip(self):
593
+ result = RunResult(
594
+ node=self.node,
595
+ status=RunStatus.Skipped,
596
+ timing=[],
597
+ thread_id=threading.current_thread().name,
598
+ execution_time=0.0,
599
+ message="SKIPPED",
600
+ adapter_response={},
601
+ failures=1,
602
+ batch_results=BatchResults(failed=[self.batches[self.batch_idx]]),
603
+ )
604
+ self.print_result_line(result=result)
605
+ return result
606
+
607
+ def error_result(self, node, message, start_time, timing_info):
608
+ """Necessary to return a result with a batch result
609
+
610
+ Called by `BaseRunner.safe_run` when an error occurs
611
+ """
612
+ return self._build_run_result(
613
+ node=node,
614
+ start_time=start_time,
615
+ status=RunStatus.Error,
616
+ timing_info=timing_info,
617
+ message=message,
618
+ batch_results=BatchResults(failed=[self.batches[self.batch_idx]]),
619
+ )
620
+
621
+ def compile(self, manifest: Manifest):
622
+ batch = self.batches[self.batch_idx]
623
+
624
+ # LEGACY: Set start/end in context prior to re-compiling (Will be removed for 1.10+)
625
+ # TODO: REMOVE before 1.10 GA
626
+ self.node.config["__dbt_internal_microbatch_event_time_start"] = batch[0]
627
+ self.node.config["__dbt_internal_microbatch_event_time_end"] = batch[1]
628
+ # Create batch context on model node prior to re-compiling
629
+ self.node.batch = BatchContext(
630
+ id=MicrobatchBuilder.batch_id(batch[0], self.node.config.batch_size),
631
+ event_time_start=batch[0],
632
+ event_time_end=batch[1],
633
+ )
634
+ # Recompile node to re-resolve refs with event time filters rendered, update context
635
+ self.compiler.compile_node(
636
+ self.node,
637
+ manifest,
638
+ {},
639
+ split_suffix=MicrobatchBuilder.format_batch_start(
640
+ batch[0], self.node.config.batch_size
641
+ ),
642
+ )
643
+
644
+ return self.node
645
+
646
+ def _build_succesful_run_batch_result(
647
+ self,
648
+ model: ModelNode,
649
+ context: Dict[str, Any],
650
+ batch: BatchType,
651
+ elapsed_time: float = 0.0,
652
+ ) -> RunResult:
653
+ run_result = self._build_run_model_result(model, context, elapsed_time)
654
+ run_result.batch_results = BatchResults(successful=[batch])
655
+ return run_result
656
+
657
+ def _build_failed_run_batch_result(
658
+ self,
659
+ model: ModelNode,
660
+ batch: BatchType,
661
+ elapsed_time: float = 0.0,
662
+ ) -> RunResult:
663
+ return RunResult(
664
+ node=model,
665
+ status=RunStatus.Error,
666
+ timing=[],
667
+ thread_id=threading.current_thread().name,
668
+ execution_time=elapsed_time,
669
+ message="ERROR",
670
+ adapter_response={},
671
+ failures=1,
672
+ batch_results=BatchResults(failed=[batch]),
673
+ )
674
+
675
+ def _execute_microbatch_materialization(
676
+ self,
677
+ model: ModelNode,
678
+ context: Dict[str, Any],
679
+ materialization_macro: MacroProtocol,
680
+ ) -> RunResult:
681
+
682
+ batch = self.batches[self.batch_idx]
683
+ # call materialization_macro to get a batch-level run result
684
+ start_time = time.perf_counter()
685
+ try:
686
+ # Update jinja context with batch context members
687
+ jinja_context = MicrobatchBuilder.build_jinja_context_for_batch(
688
+ model=model,
689
+ incremental_batch=self.incremental_batch,
690
+ )
691
+ context.update(jinja_context)
692
+
693
+ # Materialize batch and cache any materialized relations
694
+ result = MacroGenerator(
695
+ materialization_macro, context, stack=context["context_macro_stack"]
696
+ )()
697
+ for relation in self._materialization_relations(result, model):
698
+ self.adapter.cache_added(relation.incorporate(dbt_created=True))
699
+
700
+ # Build result of executed batch
701
+ batch_run_result = self._build_succesful_run_batch_result(
702
+ model, context, batch, time.perf_counter() - start_time
703
+ )
704
+ batch_result = batch_run_result
705
+
706
+ # At least one batch has been inserted successfully!
707
+ # Can proceed incrementally + in parallel
708
+ self.relation_exists = True
709
+
710
+ except (KeyboardInterrupt, SystemExit):
711
+ # reraise it for GraphRunnableTask.execute_nodes to handle
712
+ raise
713
+ except Exception as e:
714
+ fire_event(
715
+ GenericExceptionOnRun(
716
+ unique_id=self.node.unique_id,
717
+ exc=f"Exception on worker thread. {str(e)}",
718
+ node_info=self.node.node_info,
719
+ )
720
+ )
721
+ batch_run_result = self._build_failed_run_batch_result(
722
+ model, batch, time.perf_counter() - start_time
723
+ )
724
+
725
+ batch_result = batch_run_result
726
+
727
+ return batch_result
728
+
729
+ def _execute_model(
730
+ self,
731
+ hook_ctx: Any,
732
+ context_config: Any,
733
+ model: ModelNode,
734
+ context: Dict[str, Any],
735
+ materialization_macro: MacroProtocol,
736
+ ) -> RunResult:
737
+ try:
738
+ batch_result = self._execute_microbatch_materialization(
739
+ model, context, materialization_macro
740
+ )
741
+ finally:
742
+ self.adapter.post_model_hook(context_config, hook_ctx)
743
+
744
+ return batch_result
745
+
746
+
747
+ class MicrobatchModelRunner(ModelRunner):
748
+ """Handles the orchestration of batches to run for a given microbatch model"""
749
+
750
+ def __init__(self, config, adapter, node, node_index: int, num_nodes: int):
751
+ super().__init__(config, adapter, node, node_index, num_nodes)
752
+
753
+ # The parent task is necessary because we need access to the `_submit_batch` and `submit` methods
754
+ self._parent_task: Optional[RunTask] = None
755
+ # The pool is necessary because we need to batches to be executed within the same thread pool
756
+ self._pool: Optional[DbtThreadPool] = None
757
+
758
+ def set_parent_task(self, parent_task: RunTask) -> None:
759
+ self._parent_task = parent_task
760
+
761
+ def set_pool(self, pool: DbtThreadPool) -> None:
762
+ self._pool = pool
763
+
764
+ @property
765
+ def parent_task(self) -> RunTask:
766
+ if self._parent_task is None:
767
+ raise DbtInternalError(
768
+ msg="Tried to access `parent_task` of `MicrobatchModelRunner` before it was set"
769
+ )
770
+
771
+ return self._parent_task
772
+
773
+ @property
774
+ def pool(self) -> DbtThreadPool:
775
+ if self._pool is None:
776
+ raise DbtInternalError(
777
+ msg="Tried to access `pool` of `MicrobatchModelRunner` before it was set"
778
+ )
779
+
780
+ return self._pool
781
+
782
+ def _has_relation(self, model: ModelNode) -> bool:
783
+ """Check whether the relation for the model exists in the data warehouse"""
784
+ relation_info = self.adapter.Relation.create_from(self.config, model)
785
+ relation = self.adapter.get_relation(
786
+ relation_info.database, relation_info.schema, relation_info.name
787
+ )
788
+ return relation is not None
789
+
790
+ def _is_incremental(self, model) -> bool:
791
+ """Check whether the model should be run `incrementally` or as `full refresh`"""
792
+ # TODO: Remove this whole function. This should be a temporary method. We're working with adapters on
793
+ # a strategy to ensure we can access the `is_incremental` logic without drift
794
+ relation_info = self.adapter.Relation.create_from(self.config, model)
795
+ relation = self.adapter.get_relation(
796
+ relation_info.database, relation_info.schema, relation_info.name
797
+ )
798
+ if (
799
+ relation is not None
800
+ and relation.type == "table"
801
+ and model.config.materialized == "incremental"
802
+ ):
803
+ if model.config.full_refresh is not None:
804
+ return not model.config.full_refresh
805
+ else:
806
+ return not getattr(self.config.args, "FULL_REFRESH", False)
807
+ else:
808
+ return False
809
+
810
+ def _initial_run_microbatch_model_result(self, model: ModelNode) -> RunResult:
811
+ return RunResult(
812
+ node=model,
813
+ status=RunStatus.Success,
814
+ timing=[],
815
+ thread_id=threading.current_thread().name,
816
+ # The execution_time here doesn't get propagated to logs because
817
+ # `safe_run_hooks` handles the elapsed time at the node level
818
+ execution_time=0,
819
+ message="",
820
+ adapter_response={},
821
+ failures=0,
822
+ batch_results=BatchResults(),
823
+ )
824
+
825
+ def describe_node(self) -> str:
826
+ return f"{self.node.language} microbatch model {self.get_node_representation()}"
827
+
828
+ def merge_batch_results(self, result: RunResult, batch_results: List[RunResult]):
829
+ """merge batch_results into result"""
830
+ if result.batch_results is None:
831
+ result.batch_results = BatchResults()
832
+
833
+ for batch_result in batch_results:
834
+ if batch_result.batch_results is not None:
835
+ result.batch_results += batch_result.batch_results
836
+ result.execution_time += batch_result.execution_time
837
+
838
+ num_successes = len(result.batch_results.successful)
839
+ num_failures = len(result.batch_results.failed)
840
+ if num_failures == 0:
841
+ status = RunStatus.Success
842
+ msg = "SUCCESS"
843
+ elif num_successes == 0:
844
+ status = RunStatus.Error
845
+ msg = "ERROR"
846
+ else:
847
+ status = RunStatus.PartialSuccess
848
+ msg = f"PARTIAL SUCCESS ({num_successes}/{num_successes + num_failures})"
849
+ result.status = status
850
+ result.message = msg
851
+
852
+ result.batch_results.successful = sorted(result.batch_results.successful)
853
+ result.batch_results.failed = sorted(result.batch_results.failed)
854
+
855
+ # # If retrying, propagate previously successful batches into final result, even thoguh they were not run in this invocation
856
+ if self.node.previous_batch_results is not None:
857
+ result.batch_results.successful += self.node.previous_batch_results.successful
858
+
859
+ def _update_result_with_unfinished_batches(
860
+ self, result: RunResult, batches: Dict[int, BatchType]
861
+ ) -> None:
862
+ """This method is really only to be used when the execution of a microbatch model is halted before all batches have had a chance to run"""
863
+ batches_finished: Set[BatchType] = set()
864
+
865
+ if result.batch_results:
866
+ # build list of finished batches
867
+ batches_finished = batches_finished.union(set(result.batch_results.successful))
868
+ batches_finished = batches_finished.union(set(result.batch_results.failed))
869
+ else:
870
+ # instantiate `batch_results` if it was `None`
871
+ result.batch_results = BatchResults()
872
+
873
+ # skipped batches are any batch that was expected but didn't finish
874
+ batches_expected = {batch for _, batch in batches.items()}
875
+ skipped_batches = batches_expected.difference(batches_finished)
876
+
877
+ result.batch_results.failed.extend(list(skipped_batches))
878
+
879
+ # We call this method, even though we are merging no new results, as it updates
880
+ # the result witht he appropriate status (Success/Partial/Failed)
881
+ self.merge_batch_results(result, [])
882
+
883
+ def get_microbatch_builder(self, model: ModelNode) -> MicrobatchBuilder:
884
+ # Intially set the start/end to values from args
885
+ event_time_start = getattr(self.config.args, "EVENT_TIME_START", None)
886
+ event_time_end = getattr(self.config.args, "EVENT_TIME_END", None)
887
+
888
+ # If we're in sample mode, alter start/end to sample values
889
+ if getattr(self.config.args, "SAMPLE", None) is not None:
890
+ event_time_start = self.config.args.sample.start
891
+ event_time_end = self.config.args.sample.end
892
+
893
+ return MicrobatchBuilder(
894
+ model=model,
895
+ is_incremental=self._is_incremental(model),
896
+ event_time_start=event_time_start,
897
+ event_time_end=event_time_end,
898
+ default_end_time=get_invocation_started_at(),
899
+ )
900
+
901
+ def get_batches(self, model: ModelNode) -> Dict[int, BatchType]:
902
+ """Get the batches that should be run for the model"""
903
+
904
+ # Note currently (02/23/2025) model.previous_batch_results is only ever _not_ `None`
905
+ # IFF `dbt retry` is being run and the microbatch model had batches which
906
+ # failed on the run of the model (which is being retried)
907
+ if model.previous_batch_results is None:
908
+ microbatch_builder = self.get_microbatch_builder(model)
909
+ end = microbatch_builder.build_end_time()
910
+ start = microbatch_builder.build_start_time(end)
911
+ batches = microbatch_builder.build_batches(start, end)
912
+ else:
913
+ batches = model.previous_batch_results.failed
914
+
915
+ return {batch_idx: batches[batch_idx] for batch_idx in range(len(batches))}
916
+
917
+ def compile(self, manifest: Manifest):
918
+ """Don't do anything here because this runner doesn't need to compile anything"""
919
+ return self.node
920
+
921
+ def execute(self, model: ModelNode, manifest: Manifest) -> RunResult:
922
+ # Execution really means orchestration in this case
923
+
924
+ batches = self.get_batches(model=model)
925
+ relation_exists = self._has_relation(model=model)
926
+ result = self._initial_run_microbatch_model_result(model=model)
927
+
928
+ # No batches to run, so return initial result
929
+ if len(batches) == 0:
930
+ return result
931
+
932
+ batch_results: List[RunResult] = []
933
+ batch_idx = 0
934
+
935
+ # Run first batch not in parallel
936
+ relation_exists = self.parent_task._submit_batch(
937
+ node=model,
938
+ adapter=self.adapter,
939
+ relation_exists=relation_exists,
940
+ batches=batches,
941
+ batch_idx=batch_idx,
942
+ batch_results=batch_results,
943
+ pool=self.pool,
944
+ force_sequential_run=True,
945
+ incremental_batch=self._is_incremental(model=model),
946
+ )
947
+ batch_idx += 1
948
+ skip_batches = batch_results[0].status != RunStatus.Success
949
+
950
+ # Run all batches except first and last batch, in parallel if possible
951
+ while batch_idx < len(batches) - 1:
952
+ relation_exists = self.parent_task._submit_batch(
953
+ node=model,
954
+ adapter=self.adapter,
955
+ relation_exists=relation_exists,
956
+ batches=batches,
957
+ batch_idx=batch_idx,
958
+ batch_results=batch_results,
959
+ pool=self.pool,
960
+ skip=skip_batches,
961
+ )
962
+ batch_idx += 1
963
+
964
+ # Wait until all submitted batches have completed
965
+ while len(batch_results) != batch_idx:
966
+ # Check if the pool was closed, because if it was, then the main thread is trying to exit.
967
+ # If the main thread is trying to exit, we need to shutdown. If we _don't_ shutdown, then
968
+ # batches will continue to execute and we'll delay the run from stopping
969
+ if self.pool.is_closed():
970
+ # It's technically possible for more results to come in while we clean up
971
+ # instead we're going to say the didn't finish, regardless of if they finished
972
+ # or not. Thus, lets get a copy of the results as they exist right "now".
973
+ frozen_batch_results = deepcopy(batch_results)
974
+ self.merge_batch_results(result, frozen_batch_results)
975
+ self._update_result_with_unfinished_batches(result, batches)
976
+ return result
977
+
978
+ # breifly sleep so that this thread doesn't go brrrrr while waiting
979
+ time.sleep(0.1)
980
+
981
+ # Only run "last" batch if there is more than one batch
982
+ if len(batches) != 1:
983
+ # Final batch runs once all others complete to ensure post_hook runs at the end
984
+ self.parent_task._submit_batch(
985
+ node=model,
986
+ adapter=self.adapter,
987
+ relation_exists=relation_exists,
988
+ batches=batches,
989
+ batch_idx=batch_idx,
990
+ batch_results=batch_results,
991
+ pool=self.pool,
992
+ force_sequential_run=True,
993
+ skip=skip_batches,
994
+ )
995
+
996
+ # Finalize run: merge results, track model run, and print final result line
997
+ self.merge_batch_results(result, batch_results)
998
+
999
+ return result
1000
+
1001
+
1002
+ class RunTask(CompileTask):
1003
+ def __init__(
1004
+ self,
1005
+ args: Flags,
1006
+ config: RuntimeConfig,
1007
+ manifest: Manifest,
1008
+ batch_map: Optional[Dict[str, BatchResults]] = None,
1009
+ ) -> None:
1010
+ super().__init__(args, config, manifest)
1011
+ self.batch_map = batch_map
1012
+
1013
+ def raise_on_first_error(self) -> bool:
1014
+ return False
1015
+
1016
+ def get_hook_sql(self, adapter, hook, idx, num_hooks, extra_context) -> str:
1017
+ if self.manifest is None:
1018
+ raise DbtInternalError("compile_node called before manifest was loaded")
1019
+
1020
+ compiled = self.compiler.compile_node(hook, self.manifest, extra_context)
1021
+ statement = compiled.compiled_code
1022
+ hook_index = hook.index or num_hooks
1023
+ hook_obj = get_hook(statement, index=hook_index)
1024
+ return hook_obj.sql or ""
1025
+
1026
+ def handle_job_queue(self, pool, callback):
1027
+ node = self.job_queue.get()
1028
+ self._raise_set_error()
1029
+ runner = self.get_runner(node)
1030
+ # we finally know what we're running! Make sure we haven't decided
1031
+ # to skip it due to upstream failures
1032
+ if runner.node.unique_id in self._skipped_children:
1033
+ cause = self._skipped_children.pop(runner.node.unique_id)
1034
+ runner.do_skip(cause=cause)
1035
+
1036
+ if isinstance(runner, MicrobatchModelRunner):
1037
+ runner.set_parent_task(self)
1038
+ runner.set_pool(pool)
1039
+
1040
+ args = [runner]
1041
+ self._submit(pool, args, callback)
1042
+
1043
+ def _submit_batch(
1044
+ self,
1045
+ node: ModelNode,
1046
+ adapter: BaseAdapter,
1047
+ relation_exists: bool,
1048
+ batches: Dict[int, BatchType],
1049
+ batch_idx: int,
1050
+ batch_results: List[RunResult],
1051
+ pool: DbtThreadPool,
1052
+ force_sequential_run: bool = False,
1053
+ skip: bool = False,
1054
+ incremental_batch: bool = True,
1055
+ ):
1056
+ node_copy = deepcopy(node)
1057
+ # Only run pre_hook(s) for first batch
1058
+ if batch_idx != 0:
1059
+ node_copy.config.pre_hook = []
1060
+
1061
+ # Only run post_hook(s) for last batch
1062
+ if batch_idx != len(batches) - 1:
1063
+ node_copy.config.post_hook = []
1064
+
1065
+ # TODO: We should be doing self.get_runner, however doing so
1066
+ # currently causes the tracking of how many nodes there are to
1067
+ # increment when we don't want it to
1068
+ batch_runner = MicrobatchBatchRunner(
1069
+ self.config,
1070
+ adapter,
1071
+ node_copy,
1072
+ self.run_count,
1073
+ self.num_nodes,
1074
+ batch_idx,
1075
+ batches,
1076
+ relation_exists,
1077
+ incremental_batch,
1078
+ )
1079
+
1080
+ if skip:
1081
+ batch_runner.do_skip()
1082
+
1083
+ if not pool.is_closed():
1084
+ if not force_sequential_run and batch_runner.should_run_in_parallel():
1085
+ fire_event(
1086
+ MicrobatchExecutionDebug(
1087
+ msg=f"{batch_runner.describe_batch()} is being run concurrently"
1088
+ )
1089
+ )
1090
+ self._submit(pool, [batch_runner], batch_results.append)
1091
+ else:
1092
+ fire_event(
1093
+ MicrobatchExecutionDebug(
1094
+ msg=f"{batch_runner.describe_batch()} is being run sequentially"
1095
+ )
1096
+ )
1097
+ batch_results.append(self.call_runner(batch_runner))
1098
+ relation_exists = batch_runner.relation_exists
1099
+ else:
1100
+ batch_results.append(
1101
+ batch_runner._build_failed_run_batch_result(node_copy, batches[batch_idx])
1102
+ )
1103
+
1104
+ return relation_exists
1105
+
1106
+ def _hook_keyfunc(self, hook: HookNode) -> Tuple[str, Optional[int]]:
1107
+ package_name = hook.package_name
1108
+ if package_name == self.config.project_name:
1109
+ package_name = BiggestName("")
1110
+ return package_name, hook.index
1111
+
1112
+ def get_hooks_by_type(self, hook_type: RunHookType) -> List[HookNode]:
1113
+
1114
+ if self.manifest is None:
1115
+ raise DbtInternalError("self.manifest was None in get_hooks_by_type")
1116
+
1117
+ nodes = self.manifest.nodes.values()
1118
+ # find all hooks defined in the manifest (could be multiple projects)
1119
+ hooks: List[HookNode] = get_hooks_by_tags(nodes, {hook_type})
1120
+ hooks.sort(key=self._hook_keyfunc)
1121
+ return hooks
1122
+
1123
+ def safe_run_hooks(
1124
+ self, adapter: BaseAdapter, hook_type: RunHookType, extra_context: Dict[str, Any]
1125
+ ) -> RunStatus:
1126
+ ordered_hooks = self.get_hooks_by_type(hook_type)
1127
+
1128
+ if hook_type == RunHookType.End and ordered_hooks:
1129
+ fire_event(Formatting(""))
1130
+
1131
+ # on-run-* hooks should run outside a transaction. This happens because psycopg2 automatically begins a transaction when a connection is created.
1132
+ adapter.clear_transaction()
1133
+ if not ordered_hooks:
1134
+ return RunStatus.Success
1135
+
1136
+ status = RunStatus.Success
1137
+ failed = False
1138
+ num_hooks = len(ordered_hooks)
1139
+
1140
+ for idx, hook in enumerate(ordered_hooks, 1):
1141
+ with log_contextvars(node_info=hook.node_info):
1142
+ hook.index = idx
1143
+ hook_name = f"{hook.package_name}.{hook_type}.{hook.index - 1}"
1144
+ execution_time = 0.0
1145
+ timing: List[TimingInfo] = []
1146
+ failures = 1
1147
+
1148
+ if not failed:
1149
+ with collect_timing_info("compile", timing.append):
1150
+ sql = self.get_hook_sql(
1151
+ adapter, hook, hook.index, num_hooks, extra_context
1152
+ )
1153
+
1154
+ started_at = timing[0].started_at or datetime.now(timezone.utc).replace(
1155
+ tzinfo=None
1156
+ )
1157
+ hook.update_event_status(
1158
+ started_at=started_at.isoformat(), node_status=RunningStatus.Started
1159
+ )
1160
+
1161
+ fire_event(
1162
+ LogHookStartLine(
1163
+ statement=hook_name,
1164
+ index=hook.index,
1165
+ total=num_hooks,
1166
+ node_info=hook.node_info,
1167
+ )
1168
+ )
1169
+
1170
+ with collect_timing_info("execute", timing.append):
1171
+ status, message = get_execution_status(sql, adapter)
1172
+
1173
+ finished_at = timing[1].completed_at or datetime.now(timezone.utc).replace(
1174
+ tzinfo=None
1175
+ )
1176
+ hook.update_event_status(finished_at=finished_at.isoformat())
1177
+ execution_time = (finished_at - started_at).total_seconds()
1178
+ failures = 0 if status == RunStatus.Success else 1
1179
+
1180
+ if status == RunStatus.Success:
1181
+ message = f"{hook_name} passed"
1182
+ else:
1183
+ message = f"{hook_name} failed, error:\n {message}"
1184
+ failed = True
1185
+ else:
1186
+ status = RunStatus.Skipped
1187
+ message = f"{hook_name} skipped"
1188
+
1189
+ hook.update_event_status(node_status=status)
1190
+
1191
+ self.node_results.append(
1192
+ RunResult(
1193
+ status=status,
1194
+ thread_id="main",
1195
+ timing=timing,
1196
+ message=message,
1197
+ adapter_response={},
1198
+ execution_time=execution_time,
1199
+ failures=failures,
1200
+ node=hook,
1201
+ )
1202
+ )
1203
+
1204
+ fire_event(
1205
+ LogHookEndLine(
1206
+ statement=hook_name,
1207
+ status=status,
1208
+ index=hook.index,
1209
+ total=num_hooks,
1210
+ execution_time=execution_time,
1211
+ node_info=hook.node_info,
1212
+ )
1213
+ )
1214
+
1215
+ if hook_type == RunHookType.Start and ordered_hooks:
1216
+ fire_event(Formatting(""))
1217
+
1218
+ return status
1219
+
1220
+ def print_results_line(self, results, execution_time) -> None:
1221
+ nodes = [r.node for r in results if hasattr(r, "node")]
1222
+ stat_line = get_counts(nodes)
1223
+
1224
+ execution = ""
1225
+
1226
+ if execution_time is not None:
1227
+ execution = utils.humanize_execution_time(execution_time=execution_time)
1228
+
1229
+ fire_event(Formatting(""))
1230
+ fire_event(
1231
+ FinishedRunningStats(
1232
+ stat_line=stat_line, execution=execution, execution_time=execution_time
1233
+ )
1234
+ )
1235
+
1236
+ def populate_microbatch_batches(self, selected_uids: AbstractSet[str]):
1237
+ if self.batch_map is not None and self.manifest is not None:
1238
+ for uid in selected_uids:
1239
+ if uid in self.batch_map:
1240
+ node = self.manifest.ref_lookup.perform_lookup(uid, self.manifest)
1241
+ if isinstance(node, ModelNode):
1242
+ node.previous_batch_results = self.batch_map[uid]
1243
+
1244
+ def before_run(self, adapter: BaseAdapter, selected_uids: AbstractSet[str]) -> RunStatus:
1245
+ with adapter.connection_named("master"):
1246
+ self.defer_to_manifest()
1247
+ required_schemas = self.get_model_schemas(adapter, selected_uids)
1248
+ self.create_schemas(adapter, required_schemas)
1249
+ self.populate_adapter_cache(adapter, required_schemas)
1250
+ self.populate_microbatch_batches(selected_uids)
1251
+ group_lookup.init(self.manifest, selected_uids)
1252
+
1253
+ # DVT v0.57.0: Auto-snapshot metadata on first run or --full-refresh
1254
+ self._ensure_source_metadata()
1255
+
1256
+ run_hooks_status = self.safe_run_hooks(adapter, RunHookType.Start, {})
1257
+ return run_hooks_status
1258
+
1259
+ def _ensure_source_metadata(self) -> None:
1260
+ """
1261
+ Auto-capture source metadata if not present or on --full-refresh.
1262
+
1263
+ DVT v0.57.0: Ensures metadata is available for type propagation
1264
+ across federated paths. Called automatically before every run.
1265
+ """
1266
+ from pathlib import Path
1267
+
1268
+ try:
1269
+ from dbt.compute.metadata import ProjectMetadataStore
1270
+ except ImportError:
1271
+ # DuckDB not available - skip metadata capture
1272
+ return
1273
+
1274
+ # Get project root
1275
+ project_dir = getattr(self.config, 'project_root', None)
1276
+ if not project_dir:
1277
+ return
1278
+
1279
+ project_root = Path(project_dir).resolve()
1280
+
1281
+ # Check if --full-refresh is set
1282
+ full_refresh = getattr(self.config.args, 'FULL_REFRESH', False)
1283
+
1284
+ try:
1285
+ with ProjectMetadataStore(project_root) as store:
1286
+ store.initialize()
1287
+ has_metadata = store.has_source_metadata()
1288
+
1289
+ # Re-capture on first run OR --full-refresh
1290
+ if full_refresh or not has_metadata:
1291
+ from dbt.task.metadata import MetadataTask
1292
+
1293
+ # Create args for metadata task
1294
+ class MetadataArgs:
1295
+ def __init__(self):
1296
+ self.subcommand = 'snapshot'
1297
+ self.project_dir = str(project_root)
1298
+
1299
+ # Run snapshot silently
1300
+ task = MetadataTask(MetadataArgs())
1301
+
1302
+ # Capture without verbose output (run silently)
1303
+ import io
1304
+ import sys
1305
+ old_stdout = sys.stdout
1306
+ sys.stdout = io.StringIO()
1307
+ try:
1308
+ task.run_snapshot()
1309
+ finally:
1310
+ sys.stdout = old_stdout
1311
+ except Exception:
1312
+ # Silently skip metadata capture if it fails
1313
+ pass
1314
+
1315
+ def after_run(self, adapter, results) -> None:
1316
+ # DVT v0.58.4: Clean up all Spark sessions BEFORE thread pool terminates
1317
+ # This prevents semaphore leaks and segfaults from JVM cleanup issues
1318
+ try:
1319
+ from dbt.compute.strategies.local import cleanup_all_spark_sessions
1320
+ cleanup_all_spark_sessions()
1321
+ except ImportError:
1322
+ pass # PySpark not installed, nothing to clean up
1323
+
1324
+ # in on-run-end hooks, provide the value 'database_schemas', which is a
1325
+ # list of unique (database, schema) pairs that successfully executed
1326
+ # models were in. For backwards compatibility, include the old
1327
+ # 'schemas', which did not include database information.
1328
+
1329
+ database_schema_set: Set[Tuple[Optional[str], str]] = {
1330
+ (r.node.database, r.node.schema)
1331
+ for r in results
1332
+ if (hasattr(r, "node") and r.node.is_relational)
1333
+ and r.status not in (NodeStatus.Error, NodeStatus.Fail, NodeStatus.Skipped)
1334
+ }
1335
+
1336
+ extras = {
1337
+ "schemas": list({s for _, s in database_schema_set}),
1338
+ "results": [
1339
+ r for r in results if r.thread_id != "main" or r.status == RunStatus.Error
1340
+ ], # exclude that didn't fail to preserve backwards compatibility
1341
+ "database_schemas": list(database_schema_set),
1342
+ }
1343
+
1344
+ try:
1345
+ with adapter.connection_named("master"):
1346
+ self.safe_run_hooks(adapter, RunHookType.End, extras)
1347
+ except (KeyboardInterrupt, SystemExit, DbtRuntimeError):
1348
+ run_result = self.get_result(
1349
+ results=self.node_results,
1350
+ elapsed_time=time.time() - self.started_at,
1351
+ generated_at=datetime.now(timezone.utc).replace(tzinfo=None),
1352
+ )
1353
+
1354
+ if self.args.write_json and hasattr(run_result, "write"):
1355
+ run_result.write(self.result_path())
1356
+ add_artifact_produced(self.result_path())
1357
+
1358
+ print_run_end_messages(self.node_results, keyboard_interrupt=True)
1359
+
1360
+ raise
1361
+
1362
+ def get_node_selector(self) -> ResourceTypeSelector:
1363
+ if self.manifest is None or self.graph is None:
1364
+ raise DbtInternalError("manifest and graph must be set to get perform node selection")
1365
+ return ResourceTypeSelector(
1366
+ graph=self.graph,
1367
+ manifest=self.manifest,
1368
+ previous_state=self.previous_state,
1369
+ resource_types=[NodeType.Model],
1370
+ )
1371
+
1372
+ def get_runner_type(self, node) -> Optional[Type[BaseRunner]]:
1373
+ if self.manifest is None:
1374
+ raise DbtInternalError("manifest must be set prior to calling get_runner_type")
1375
+
1376
+ if (
1377
+ node.config.materialized == "incremental"
1378
+ and node.config.incremental_strategy == "microbatch"
1379
+ and self.manifest.use_microbatch_batches(project_name=self.config.project_name)
1380
+ ):
1381
+ return MicrobatchModelRunner
1382
+ else:
1383
+ return ModelRunner
1384
+
1385
+ def task_end_messages(self, results) -> None:
1386
+ if results:
1387
+ print_run_end_messages(results)