11"""
2- Copyright (c) 2023 , Oracle and/or its affiliates.
2+ Copyright (c) 2024 , Oracle and/or its affiliates.
33Copyright (c) 2020, Vitor Avancini
44
55 Licensed under the Apache License, Version 2.0 (the "License");
1616"""
1717import datetime
1818from typing import (
19- Optional , List , Set
19+ Optional , List , Set , FrozenSet , Tuple , Iterable
2020)
2121from itertools import chain
2222from typing import (
2727import agate
2828import requests
2929
30- import dbt .exceptions
30+ import dbt_common .exceptions
31+ from dbt_common .contracts .constraints import ConstraintType
32+ from dbt_common .utils import filter_null_values
33+
3134from dbt .adapters .base .relation import BaseRelation , InformationSchema
3235from dbt .adapters .base .impl import GET_CATALOG_MACRO_NAME , ConstraintSupport , GET_CATALOG_RELATIONS_MACRO_NAME , _expect_row_value
36+ from dbt .adapters .contracts .relation import RelationConfig
37+ from dbt .adapters .events .logging import AdapterLogger
3338from dbt .adapters .sql import SQLAdapter
3439from dbt .adapters .base .meta import available
3540from dbt .adapters .capability import CapabilityDict , CapabilitySupport , Support , Capability
41+
3642from dbt .adapters .oracle import OracleAdapterConnectionManager
3743from dbt .adapters .oracle .column import OracleColumn
3844from dbt .adapters .oracle .relation import OracleRelation
39- from dbt .contracts .graph .manifest import Manifest
40- from dbt .contracts .graph .nodes import ConstraintType
41- from dbt .events import AdapterLogger
42-
43- from dbt .utils import filter_null_values
44-
4545from dbt .adapters .oracle .keyword_catalog import KEYWORDS
4646from dbt .adapters .oracle .python_submissions import OracleADBSPythonJob
47- from dbt .adapters .oracle .connections import AdapterResponse
4847
4948logger = AdapterLogger ("oracle" )
5049
@@ -139,7 +138,7 @@ def verify_database(self, database):
139138 database = database .strip ('"' )
140139 expected = self .config .credentials .database
141140 if expected and database .lower () != expected .lower ():
142- raise dbt .exceptions .DbtRuntimeError (
141+ raise dbt_common .exceptions .DbtRuntimeError (
143142 'Cross-db references not allowed in {} ({} vs {})'
144143 .format (self .type (), database , expected )
145144 )
@@ -210,67 +209,56 @@ def _get_one_catalog(
210209 self ,
211210 information_schema : InformationSchema ,
212211 schemas : Set [str ],
213- manifest : Manifest ,
212+ used_schemas : FrozenSet [ Tuple [ str , str ]] ,
214213 ) -> agate .Table :
215-
214+ logger .info (f"GET ONE CATALOG =====> { schemas } " )
215+ logger .info (f"GET ONE CATALOG =====> { information_schema } " )
216+ logger .info (f"GET ONE CATALOG =====> { used_schemas } " )
216217 kwargs = {"information_schema" : information_schema , "schemas" : schemas }
217- table = self .execute_macro (
218- GET_CATALOG_MACRO_NAME ,
219- kwargs = kwargs ,
220- # pass in the full manifest so we get any local project
221- # overrides
222- manifest = manifest ,
223- )
224- # In case database is not defined, we can use the the configured database which we set as part of credentials
225- for node in chain (manifest .nodes .values (), manifest .sources .values ()):
226- if not node .database or node .database == 'None' :
227- node .database = self .config .credentials .database
228-
229- results = self ._catalog_filter_table (table , manifest )
218+ table = self .execute_macro (GET_CATALOG_MACRO_NAME , kwargs = kwargs )
219+ results = self ._catalog_filter_table (table , used_schemas = used_schemas )
220+ logger .info (f"GET ONE CATALOG =====> { results } " )
230221 return results
231222
232223 def _get_one_catalog_by_relations (
233224 self ,
234225 information_schema : InformationSchema ,
235226 relations : List [BaseRelation ],
236- manifest : Manifest ,
227+ used_schemas : FrozenSet [ Tuple [ str , str ]] ,
237228 ) -> agate .Table :
238-
229+ logger .info (f"GET ONE _get_one_catalog_by_relations =====> { relations } " )
230+ logger .info (f"GET ONE _get_one_catalog_by_relations =====> { information_schema } " )
231+ logger .info (f"GET ONE _get_one_catalog_by_relations =====> { used_schemas } " )
239232 kwargs = {
240233 "information_schema" : information_schema ,
241234 "relations" : relations ,
242235 }
243- table = self .execute_macro (
244- GET_CATALOG_RELATIONS_MACRO_NAME ,
245- kwargs = kwargs ,
246- # pass in the full manifest, so we get any local project
247- # overrides
248- manifest = manifest ,
249- )
250-
251- # In case database is not defined, we can use the the configured database which we set as part of credentials
252- for node in chain (manifest .nodes .values (), manifest .sources .values ()):
253- if not node .database or node .database == 'None' :
254- node .database = self .config .credentials .database
255-
256- results = self ._catalog_filter_table (table , manifest ) # type: ignore[arg-type]
236+ table = self .execute_macro (GET_CATALOG_RELATIONS_MACRO_NAME , kwargs = kwargs )
237+ results = self ._catalog_filter_table (table , used_schemas ) # type: ignore[arg-type]
238+ logger .info (f"GET ONE _get_one_catalog_by_relations =====> { results } " )
257239 return results
258240
259241 def get_filtered_catalog (
260- self , manifest : Manifest , relations : Optional [Set [BaseRelation ]] = None
242+ self ,
243+ relation_configs : Iterable [RelationConfig ],
244+ used_schemas : FrozenSet [Tuple [str , str ]],
245+ relations : Optional [Set [BaseRelation ]] = None
261246 ):
247+ logger .info (f"GET ONE get_filtered_catalog =====> { relations } " )
248+ logger .info (f"GET ONE get_filtered_catalog =====> { relations } " )
249+ logger .info (f"GET ONE get_filtered_catalog =====> { used_schemas } " )
262250 catalogs : agate .Table
263251 if (
264252 relations is None
265253 or len (relations ) > 100
266254 or not self .supports (Capability .SchemaMetadataByRelations )
267255 ):
268256 # Do it the traditional way. We get the full catalog.
269- catalogs , exceptions = self .get_catalog (manifest )
257+ catalogs , exceptions = self .get_catalog (relation_configs , used_schemas )
270258 else :
271259 # Do it the new way. We try to save time by selecting information
272260 # only for the exact set of relations we are interested in.
273- catalogs , exceptions = self .get_catalog_by_relations (manifest , relations )
261+ catalogs , exceptions = self .get_catalog_by_relations (used_schemas , relations )
274262
275263 if relations and catalogs :
276264 relation_map = {
@@ -388,8 +376,8 @@ def quote_seed_column(
388376 elif quote_config is None :
389377 pass
390378 else :
391- raise dbt .exceptions .CompilationError (f'The seed configuration value of "quote_columns" '
392- f'has an invalid type { type (quote_config )} ' )
379+ raise dbt_common .exceptions .CompilationError (f'The seed configuration value of "quote_columns" '
380+ f'has an invalid type { type (quote_config )} ' )
393381
394382 if quote_columns :
395383 return self .quote (column )
@@ -417,7 +405,7 @@ def render_raw_columns_constraints(cls, raw_columns: Dict[str, Dict[str, Any]])
417405
418406 def get_oml_auth_token (self ) -> str :
419407 if self .config .credentials .oml_auth_token_uri is None :
420- raise dbt .exceptions .DbtRuntimeError ("oml_auth_token_uri should be set to run dbt-py models" )
408+ raise dbt_common .exceptions .DbtRuntimeError ("oml_auth_token_uri should be set to run dbt-py models" )
421409 data = {
422410 "grant_type" : "password" ,
423411 "username" : self .config .credentials .user ,
@@ -428,7 +416,7 @@ def get_oml_auth_token(self) -> str:
428416 json = data )
429417 r .raise_for_status ()
430418 except requests .exceptions .RequestException :
431- raise dbt .exceptions .DbtRuntimeError ("Error getting OML OAuth2.0 token" )
419+ raise dbt_common .exceptions .DbtRuntimeError ("Error getting OML OAuth2.0 token" )
432420 else :
433421 return r .json ()["accessToken" ]
434422
0 commit comments