-
Notifications
You must be signed in to change notification settings - Fork 0
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
Refactoring/#221 fixed mypy warnings #225
base: main
Are you sure you want to change the base?
Changes from 8 commits
0731aa6
40add98
8cf706c
b2e61fe
c0ef88e
5921a98
519aceb
1b85f18
a2110e4
a607870
9e3c4da
88a0724
976598b
547969f
f493055
4ecca0c
82a4871
6ccdf43
21bbcd7
0775d48
b20532d
1c4377a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,5 +62,6 @@ def transfer_object_to( | |
""" | ||
pass | ||
|
||
@abstractmethod | ||
def get_connection(self, name: str) -> Connection: | ||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
) | ||
from exasol.analytics.query_handler.query_handler import QueryHandler | ||
from exasol.analytics.query_handler.result import Continue, Finish | ||
from exasol.analytics.utils.errors import UninitializedAttributeError | ||
|
||
|
||
class ResultHandlerReturnValue(enum.Enum): | ||
|
@@ -58,20 +59,35 @@ def __init__( | |
self._current_query_handler_context: Optional[ScopeQueryHandlerContext] = None | ||
self._create_current_query_handler() | ||
|
||
def _check_is_valid(self): | ||
if self._current_query_handler is None: | ||
raise RuntimeError("No current query handler set.") | ||
|
||
def get_current_query_handler( | ||
self, | ||
) -> QueryHandler[List[SQLStageInputOutput], SQLStageInputOutput]: | ||
self._check_is_valid() | ||
return self._current_query_handler | ||
value = self._current_query_handler | ||
if value is None: | ||
raise RuntimeError("No current query handler set.") | ||
return value | ||
|
||
@property | ||
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. Property method Questions:
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. If the original is private, the new one needs to be private, too. This means it needs another name. Good question, what the name should be. The same is true for current_stage property. Thinking about a prefix like 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. 👍 I like the proposal 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. I now used
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. See last push |
||
def current_query_handler_context(self) -> ScopeQueryHandlerContext: | ||
value = self._current_query_handler_context | ||
if value is None: | ||
raise UninitializedAttributeError( | ||
"Current query handler context is undefined." | ||
) | ||
return value | ||
|
||
@property | ||
def current_stage(self) -> SQLStage: | ||
value = self._current_stage | ||
if value is None: | ||
raise UninitializedAttributeError("Current stage is None.") | ||
return value | ||
|
||
def handle_result( | ||
self, result: Union[Continue, Finish[SQLStageInputOutput]] | ||
) -> ResultHandlerReturnValue: | ||
self._check_is_valid() | ||
# check if current query handler is set | ||
self.get_current_query_handler() | ||
if isinstance(result, Finish): | ||
return self._handle_finished_result(result) | ||
elif isinstance(result, Continue): | ||
|
@@ -90,7 +106,7 @@ def _handle_finished_result( | |
return self._try_to_move_to_next_stage() | ||
|
||
def _try_to_move_to_next_stage(self) -> ResultHandlerReturnValue: | ||
self._current_query_handler_context.release() | ||
self.current_query_handler_context.release() | ||
if self._is_not_last_stage(): | ||
self._move_to_next_stage() | ||
return ResultHandlerReturnValue.CONTINUE_PROCESSING | ||
|
@@ -123,12 +139,12 @@ def _create_current_query_handler(self): | |
result_bucketfs_location=result_bucketfs_location, | ||
sql_stage_inputs=stage_inputs, | ||
) | ||
self._current_query_handler = self._current_stage.create_train_query_handler( | ||
self._current_query_handler = self.current_stage.create_train_query_handler( | ||
stage_input, self._current_query_handler_context | ||
) | ||
|
||
def _add_result_to_successors(self, result: SQLStageInputOutput): | ||
successors = self._sql_stage_graph.successors(self._current_stage) | ||
successors = self._sql_stage_graph.successors(self.current_stage) | ||
if len(successors) == 0: | ||
raise RuntimeError("Programming error") | ||
self._add_result_to_inputs_of_successors(result, successors) | ||
|
@@ -146,7 +162,7 @@ def _add_result_to_reference_counting_bag( | |
object_proxies = find_object_proxies(result) | ||
for object_proxy in object_proxies: | ||
if object_proxy not in self._reference_counting_bag: | ||
self._current_query_handler_context.transfer_object_to( | ||
self.current_query_handler_context.transfer_object_to( | ||
object_proxy, self._query_handler_context | ||
) | ||
for _ in successors: | ||
|
@@ -160,7 +176,7 @@ def _transfer_ownership_of_result_to_query_result_handler(self, result): | |
object_proxy | ||
) | ||
else: | ||
self._current_query_handler_context.transfer_object_to( | ||
self.current_query_handler_context.transfer_object_to( | ||
object_proxy, self._query_handler_context | ||
) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
from exasol.analytics.query_handler.result import Continue, Finish | ||
from exasol.analytics.query_handler.udf.runner.state import QueryHandlerRunnerState | ||
from exasol.analytics.sql_executor.interface import SQLExecutor | ||
from exasol.analytics.utils.errors import UninitializedAttributeError | ||
|
||
LOGGER = logging.getLogger(__file__) | ||
|
||
|
@@ -72,8 +73,8 @@ def _handle_continue(self, result: Continue) -> Union[Continue, Finish[ResultTyp | |
self._cleanup_query_handler_context() | ||
self._execute_queries(result.query_list) | ||
input_query_result = self._run_input_query(result) | ||
result = self._state.query_handler.handle_query_result(input_query_result) | ||
return result | ||
_result = self._state.query_handler.handle_query_result(input_query_result) | ||
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. Why this rename? 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. Because |
||
return _result | ||
|
||
def _run_input_query(self, result: Continue) -> PythonQueryResult: | ||
input_query_view, input_query = self._wrap_return_query(result.input_query) | ||
|
@@ -116,24 +117,28 @@ def _release_and_create_query_handler_context_of_input_query(self): | |
def _wrap_return_query( | ||
self, input_query: SelectQueryWithColumnDefinition | ||
) -> Tuple[str, str]: | ||
if self._state.input_query_query_handler_context is None: | ||
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. needs investigation |
||
raise UninitializedAttributeError( | ||
"Current state's input query query handler context is not set." | ||
) | ||
temporary_view_name = ( | ||
self._state.input_query_query_handler_context.get_temporary_view_name() | ||
) | ||
input_query_create_view_string = cleandoc( | ||
f""" | ||
CREATE OR REPLACE VIEW {temporary_view_name.fully_qualified} AS | ||
{input_query.query_string}; | ||
""" | ||
CREATE OR REPLACE VIEW {temporary_view_name.fully_qualified} AS | ||
{input_query.query_string}; | ||
""" | ||
) | ||
full_qualified_columns = [ | ||
col.name.fully_qualified for col in input_query.output_columns | ||
] | ||
columns_str = ",\n".join(full_qualified_columns) | ||
input_query_string = cleandoc( | ||
f""" | ||
SELECT | ||
{textwrap.indent(columns_str, " " * 4)} | ||
FROM {temporary_view_name.fully_qualified}; | ||
""" | ||
SELECT | ||
{textwrap.indent(columns_str, " " * 4)} | ||
FROM {temporary_view_name.fully_qualified}; | ||
""" | ||
) | ||
return input_query_create_view_string, input_query_string |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -51,7 +51,7 @@ def rowcount(self) -> int: | |||||
|
||||||
def fetch_as_dataframe( | ||||||
self, num_rows: Union[str, int], start_col: int = 0 | ||||||
) -> "pandas.DataFrame": | ||||||
) -> "pandas.DataFrame": # type: ignore | ||||||
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. Would
Suggested change
work here? 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. Yes, but requires importing pandas. I was not sure whether the string syntax was intentional, here? 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. Importing pandas can take several seconds. 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. I still get errors. See also pydantic/pydantic#234 Using parenthesis causes mypy error:
Using square brackets causes mypy error:
Please also note docs on ForwardRef:
|
||||||
df = self._ctx.get_dataframe(num_rows, start_col=self._start_col) | ||||||
self._initialized = True | ||||||
if df is None: | ||||||
|
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.
I think, we can do this in the pyproject.toml for all imports, but we probably should add py.typed to bucketfs-python
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.
Ah, yes.
I created a ticket for adding file
py.typed
to bucketfs-python here: exasol/bucketfs-python#173There 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.
Thanks to @Nicoretti for helping: We can ignore importing untyped modules in pyproject.toml like this:
Additionally type check can be disabled in tests by
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.
See last push