Skip to content

Query service client support #455

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

Merged
merged 57 commits into from
Jul 30, 2024
Merged

Query service client support #455

merged 57 commits into from
Jul 30, 2024

Conversation

vgvoleg
Copy link
Collaborator

@vgvoleg vgvoleg commented Jul 17, 2024

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Other information

Copy link

github-actions bot commented Jul 17, 2024

🌋 Here are results of SLO test for python-sync:

Grafana Dashboard

SLO-sync

@vgvoleg vgvoleg changed the title WIP: Query service client support Query service client support Jul 25, 2024
rekby
rekby previously approved these changes Jul 25, 2024
@rekby rekby self-requested a review July 25, 2024 09:39
@rekby rekby dismissed their stale review July 25, 2024 09:40

misclick for approve

for _ in res:
pass

with pytest.raises(Exception):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for specific error


def test_tx_rollback_raises_before_begin(self, tx: BaseTxContext):
with pytest.raises(RuntimeError):
tx.rollback()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as for commit

@dataclass
class QueryContent(IFromPublic, IToProto):
text: str
syntax: Optional[int] = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in other places.

I think defaults in internal wrappers is bad idea.
With default field you can forget to initialize it while create the object.

@property
def tx_id(self):
"""
Returns a id of open transaction or None otherwise
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use "an" instead of "a" before vowel "i" in "id"

pass

@abc.abstractmethod
def begin(settings: QueryClientSettings = None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here and below:

  1. first parameter should be self
  2. if default value is None - type hint must respect it and be Optional

"""
return self._tx_state.tx_id

def begin(self, settings=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need type hint for result for all functions, which return something

concurrent_result_sets: bool = False,
):
self._ensure_prev_stream_finished()
self._tx_state._check_tx_not_terminal()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if rename negative "not terminal" to positive "alive" for simplify read?

def execute(
self,
query: str,
tx_mode: base.BaseQueryTxMode = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional for typehint (here and in other similar places)

exec_mode: QueryExecMode = None,
parameters: dict = None,
concurrent_result_sets: bool = False,
empty_tx_control: bool = False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need separate flag empty_tx_control? What is use tx_mode = None for it?

And use SerializeReadWrite (or add some constant) as default value for methods instead of None?

self._pool = pool
self._session = QuerySessionSync(pool._driver)

def __enter__(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type hint

"QuerySnapshotReadOnly",
"QueryStaleReadOnly",
"QuerySessionPool",
"QueryClientSync",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about QuerySessionSync? it need as minimum for type hints

parameters: dict = None,
concurrent_result_sets: bool = False,
empty_tx_control: bool = False,
):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need typehint, now IDE can't understand what objects will be returned by iterator


def callee(session):
print("=" * 50)
with session.execute("delete from example"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need common style, with other example queries.
now delete, but CREATE. I prefer capital case for SQL commands (as CREATE)

session.create()
res = []
with session.execute("select 1; select 2") as results:
for result_set in results:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest - the test can check about the execute returns two result instead on two lines in one result.


return retry_operation_sync(wrapped_callee, retry_settings)

def execute_with_retries(self, query: str, retry_settings: Optional[RetrySettings] = None, *args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs typehint - for comfort work with result of the query

@vgvoleg vgvoleg merged commit afcb2f8 into main Jul 30, 2024
11 checks passed
@vgvoleg vgvoleg deleted the query_service branch July 30, 2024 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants