-
Notifications
You must be signed in to change notification settings - Fork 40
feat(connectors): BI-6586 Support YDB VIEW #1245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
catsona
wants to merge
6
commits into
main
Choose a base branch
from
catsona/bi-6586/support_ydb_view
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6a27ce0
feat(connectors): BI-5971 Upgrade YDB SDK dependencies
catsona 361564e
cleanup
catsona 304098d
feat(connectors): BI-6586 Support YDB VIEW
catsona 75d42cf
lint-fix
catsona 32f5f32
add annotation for test function
catsona 25f2076
cleanup
catsona File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,14 @@ | |
|
|
||
| from dl_core import exc | ||
| from dl_core.connection_executors.adapters.adapters_base_sa_classic import BaseClassicAdapter | ||
| from dl_core.connection_models import TableIdent | ||
| from dl_core.connection_executors.models.db_adapter_data import RawColumnInfo | ||
| from dl_core.connection_models import ( | ||
| DBIdent, | ||
| SATextTableDefinition, | ||
| TableDefinition, | ||
| TableIdent, | ||
| ) | ||
| from dl_core.utils import sa_plain_text | ||
| import dl_sqlalchemy_ydb.dialect | ||
|
|
||
| import dl_connector_ydb.core.base.row_converters | ||
|
|
@@ -116,3 +123,43 @@ def make_exc( # TODO: Move to ErrorTransformer | |
|
|
||
| def get_engine_kwargs(self) -> dict: | ||
| return {} | ||
|
|
||
| def _get_raw_columns_info(self, table_def: TableDefinition) -> tuple[RawColumnInfo, ...]: | ||
| # Check if target path is view | ||
| if isinstance(table_def, TableIdent): | ||
| assert table_def.table_name is not None | ||
|
|
||
| db_engine = self.get_db_engine(table_def.db_name) | ||
| connection = db_engine.connect() | ||
|
|
||
| try: | ||
| # SA db_engine -> SA connection -> DBAPI connection -> YDB driver | ||
| driver = connection.connection._driver # type: ignore # 2024-01-24 # TODO: "DBAPIConnection" has no attribute "_driver" [attr-defined] | ||
| assert driver | ||
|
|
||
| # User can gain access to tables by absolute path instead of relative to db_name root. | ||
| # Possible solution: require prefix be equal to db_name/ | ||
| if table_def.db_name is None: | ||
| table_path = table_def.table_name | ||
| elif table_def.table_name.startswith("/"): | ||
| if table_def.table_name.startswith(table_def.db_name + "/"): | ||
| table_path = table_def.table_name | ||
| else: | ||
| # Not ok? | ||
| raise ValueError("absolute table path is not subpath of database path") | ||
|
Comment on lines
+147
to
+149
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| else: | ||
| table_path = table_def.db_name.rstrip("/") + "/" + table_def.table_name | ||
|
|
||
| response = driver.scheme_client.async_describe_path(table_path) | ||
| result = response.result() | ||
|
|
||
| if result.is_view(): | ||
| return self._get_subselect_table_info( | ||
| SATextTableDefinition( | ||
| sa_plain_text(f"(SELECT * FROM `{table_path}` LIMIT 1)"), | ||
| ), | ||
| ).columns | ||
| finally: | ||
| connection.close() | ||
|
|
||
| return super()._get_raw_columns_info(table_def) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message should be more descriptive and include the actual paths to help debugging. Consider:
f'Absolute table path {table_def.table_name} is not a subpath of database path {table_def.db_name}'