Skip to content

Commit

Permalink
add_select_query
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Mar 2, 2023
1 parent 02cd444 commit 5858095
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 2 additions & 6 deletions core/dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,8 @@ def execute(

@available.parse(lambda *a, **k: [])
def get_column_schema_from_query(self, sql: str) -> List[BaseColumn]:
"""Get a list of the column names and data types from the given sql.
:param str sql: The sql to execute.
:return: List[Column]
"""
_, cursor = self.connections.add_query(sql, add_comment=True)
"""Get a list of the Columns with names and data types from the given sql."""
_, cursor = self.connections.add_select_query(sql)
columns = [
self.Column.create(
column_name, self.connections.data_type_code_to_name(column_type_code)
Expand Down
7 changes: 4 additions & 3 deletions core/dbt/adapters/sql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ def add_query(
auto_begin: bool = True,
bindings: Optional[Any] = None,
abridge_sql_log: bool = False,
add_comment: bool = False,
) -> Tuple[Connection, Any]:
if add_comment:
sql = self._add_query_comment(sql)

connection = self.get_thread_connection()
if auto_begin and connection.transaction_open is False:
Expand Down Expand Up @@ -158,6 +155,10 @@ def add_begin_query(self):
def add_commit_query(self):
return self.add_query("COMMIT", auto_begin=False)

def add_select_query(self, sql: str) -> Tuple[Connection, Any]:
sql = self._add_query_comment(sql)
return self.add_query(sql, auto_begin=False)

def begin(self):
connection = self.get_thread_connection()
if connection.transaction_open is True:
Expand Down

0 comments on commit 5858095

Please sign in to comment.