Skip to content

Commit

Permalink
Fix get_columns output (#89)
Browse files Browse the repository at this point in the history
* fix get_columns output

* bump version

* fixed output
  • Loading branch information
griffatrasgo authored Jun 7, 2022
1 parent 76f5523 commit bc5589c
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
5 changes: 5 additions & 0 deletions rasgoql/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Added db-dtypes as a dependency to optional rasgoql[bigquery] package to prevent breaking changes in google-cloud-bigquery v3.0.0

## [1.5.5] - 2022-06-07
### Fixed
- Fixed a bug where get_columns would not render for all DW types


[1.0.0]: https://pypi.org/project/rasgoql/1.0.0/
[1.0.1]: https://pypi.org/project/rasgoql/1.0.1/
Expand All @@ -112,3 +116,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[1.5.2]: https://pypi.org/project/rasgoql/1.5.2/
[1.5.3]: https://pypi.org/project/rasgoql/1.5.3/
[1.5.4]: https://pypi.org/project/rasgoql/1.5.4/
[1.5.5]: https://pypi.org/project/rasgoql/1.5.5/
4 changes: 2 additions & 2 deletions rasgoql/rasgoql/data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from abc import ABC
import re
import os
from typing import Union, Optional
from typing import List, Optional, Tuple, Union
from collections import namedtuple

import pandas as pd
Expand Down Expand Up @@ -278,7 +278,7 @@ def get_schema(
self,
fqtn: str,
create_sql: str = None,
) -> dict:
) -> List[Tuple[str, str]]:
"""
Return the schema of a table or view
"""
Expand Down
4 changes: 2 additions & 2 deletions rasgoql/rasgoql/data/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import logging
import os
from typing import List, Tuple, Union, Optional
from typing import List, Optional, Tuple, Union

import json
import pandas as pd
Expand Down Expand Up @@ -348,7 +348,7 @@ def get_schema(
self,
fqtn: str,
create_sql: str = None,
) -> Tuple[str, str]:
) -> List[Tuple[str, str]]:
"""
Return the schema of a table or view
Expand Down
4 changes: 2 additions & 2 deletions rasgoql/rasgoql/data/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import annotations
import logging
import os
from typing import List, Optional, Union
from typing import List, Optional, Tuple, Union

import json
import pandas as pd
Expand Down Expand Up @@ -373,7 +373,7 @@ def get_schema(
self,
fqtn: str,
create_sql: str = None,
) -> dict:
) -> List[Tuple[str, str]]:
"""
Return the schema of a table or view
Expand Down
4 changes: 2 additions & 2 deletions rasgoql/rasgoql/data/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import annotations
from abc import abstractmethod
import logging
from typing import Optional, Union
from typing import List, Optional, Tuple, Union
from urllib.parse import quote_plus as urlquote

import pandas as pd
Expand Down Expand Up @@ -226,7 +226,7 @@ def get_object_details(self, fqtn: str) -> tuple:
obj_type = result[0].get("kind")
return obj_exists, is_rasgo_obj, obj_type

def get_schema(self, fqtn: str, create_sql: str = None) -> dict:
def get_schema(self, fqtn: str, create_sql: str = None) -> List[Tuple[str, str]]:
"""
Return the schema of a table or view
Params:
Expand Down
35 changes: 15 additions & 20 deletions rasgoql/rasgoql/primitives/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,26 +314,21 @@ def _set_final_select_statement(
return sql


def get_columns(source_table: str, running_sql: str = None, dw: 'DataWarehouse' = None) -> str:
if not running_sql:
database, schema, table_name = source_table.split('.')
query_string = f"""
SELECT COLUMN_NAME, DATA_TYPE
FROM {database}.information_schema.columns
WHERE TABLE_CATALOG = '{database.upper()}'
AND TABLE_SCHEMA = '{schema.upper()}'
AND TABLE_NAME = '{table_name.upper()}'
"""
else:
query_string = f"""
SELECT COLUMN_NAME, DATA_TYPE
FROM {dw.default_database}.information_schema.columns
WHERE TABLE_CATALOG = '{dw.default_database}'
AND TABLE_SCHEMA = '{dw.default_schema}'
AND TABLE_NAME = '{source_table}'
"""
df = _run_query(query_string, dw=dw, running_sql=running_sql, source_table=source_table)
return df.set_index('COLUMN_NAME')['DATA_TYPE'].to_dict()
def get_columns(
source_table: str,
running_sql: str = None,
dw: 'DataWarehouse' = None,
) -> Dict[str, str]:
"""
Return the column names of a given table (or sql statement)
"""
return {
row[0]: row[1]
for row in dw.get_schema(
fqtn=dw.magic_fqtn_handler(source_table, dw.default_namespace),
create_sql=running_sql,
)
}


def _source_code_functions(
Expand Down
2 changes: 1 addition & 1 deletion rasgoql/rasgoql/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
Package version for pypi
"""
__version__ = '1.5.4'
__version__ = '1.5.5'

0 comments on commit bc5589c

Please sign in to comment.