Skip to content

Commit d0c9388

Browse files
committed
fix review
1 parent c0b125a commit d0c9388

File tree

10 files changed

+248
-201
lines changed

10 files changed

+248
-201
lines changed

tests/query/test_query_session.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,13 @@ def test_basic_execute(self, session: QuerySessionSync):
8989
assert len(result_sets[0].rows) == 1
9090
assert len(result_sets[0].columns) == 1
9191
assert list(result_sets[0].rows[0].values()) == [1]
92+
93+
def test_two_results(self, session: QuerySessionSync):
94+
session.create()
95+
res = []
96+
with session.execute("select 1; select 2") as results:
97+
for result_set in results:
98+
if len(result_set.rows) > 0:
99+
res.extend(list(result_set.rows[0].values()))
100+
101+
assert res == [1, 2]

tests/query/test_query_transaction.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,78 @@
11
import pytest
22

3-
from ydb.query.transaction import BaseTxContext
3+
from ydb.query.transaction import BaseQueryTxContext
44
from ydb.query.transaction import QueryTxStateEnum
55

66

77
class TestQueryTransaction:
8-
def test_tx_begin(self, tx: BaseTxContext):
8+
def test_tx_begin(self, tx: BaseQueryTxContext):
99
assert tx.tx_id is None
1010

1111
tx.begin()
1212
assert tx.tx_id is not None
1313

14-
def test_tx_allow_double_commit(self, tx: BaseTxContext):
14+
def test_tx_allow_double_commit(self, tx: BaseQueryTxContext):
1515
tx.begin()
1616
tx.commit()
1717
tx.commit()
1818

19-
def test_tx_allow_double_rollback(self, tx: BaseTxContext):
19+
def test_tx_allow_double_rollback(self, tx: BaseQueryTxContext):
2020
tx.begin()
2121
tx.rollback()
2222
tx.rollback()
2323

24-
def test_tx_commit_before_begin(self, tx: BaseTxContext):
24+
def test_tx_commit_before_begin(self, tx: BaseQueryTxContext):
2525
tx.commit()
2626
assert tx._tx_state._state == QueryTxStateEnum.COMMITTED
2727

28-
def test_tx_rollback_before_begin(self, tx: BaseTxContext):
28+
def test_tx_rollback_before_begin(self, tx: BaseQueryTxContext):
2929
tx.rollback()
3030
assert tx._tx_state._state == QueryTxStateEnum.ROLLBACKED
3131

32-
def test_tx_first_execute_begins_tx(self, tx: BaseTxContext):
32+
def test_tx_first_execute_begins_tx(self, tx: BaseQueryTxContext):
3333
tx.execute("select 1;")
3434
tx.commit()
3535

36-
def test_interactive_tx_commit(self, tx: BaseTxContext):
36+
def test_interactive_tx_commit(self, tx: BaseQueryTxContext):
3737
tx.execute("select 1;", commit_tx=True)
3838
with pytest.raises(RuntimeError):
3939
tx.execute("select 1;")
4040

41-
def test_tx_execute_raises_after_commit(self, tx: BaseTxContext):
41+
def test_tx_execute_raises_after_commit(self, tx: BaseQueryTxContext):
4242
tx.begin()
4343
tx.commit()
4444
with pytest.raises(RuntimeError):
4545
tx.execute("select 1;")
4646

47-
def test_tx_execute_raises_after_rollback(self, tx: BaseTxContext):
47+
def test_tx_execute_raises_after_rollback(self, tx: BaseQueryTxContext):
4848
tx.begin()
4949
tx.rollback()
5050
with pytest.raises(RuntimeError):
5151
tx.execute("select 1;")
5252

53-
def test_context_manager_rollbacks_tx(self, tx: BaseTxContext):
53+
def test_context_manager_rollbacks_tx(self, tx: BaseQueryTxContext):
5454
with tx:
5555
tx.begin()
5656

5757
assert tx._tx_state._state == QueryTxStateEnum.ROLLBACKED
5858

59-
def test_context_manager_normal_flow(self, tx: BaseTxContext):
59+
def test_context_manager_normal_flow(self, tx: BaseQueryTxContext):
6060
with tx:
6161
tx.begin()
6262
tx.execute("select 1;")
6363
tx.commit()
6464

6565
assert tx._tx_state._state == QueryTxStateEnum.COMMITTED
6666

67-
def test_context_manager_does_not_hide_exceptions(self, tx: BaseTxContext):
67+
def test_context_manager_does_not_hide_exceptions(self, tx: BaseQueryTxContext):
6868
class CustomException(Exception):
6969
pass
7070

7171
with pytest.raises(CustomException):
7272
with tx:
7373
raise CustomException()
7474

75-
def test_execute_as_context_manager(self, tx: BaseTxContext):
75+
def test_execute_as_context_manager(self, tx: BaseQueryTxContext):
7676
tx.begin()
7777

7878
with tx.execute("select 1;") as results:

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ builtins = _
7575
max-line-length = 160
7676
ignore=E203,W503
7777
exclude=*_pb2.py,*_grpc.py,.venv,.git,.tox,dist,doc,*egg,ydb/public/api/protos/*,docs/*,ydb/public/api/grpc/*,persqueue/*,client/*,dbapi/*,ydb/default_pem.py,*docs/conf.py
78+
per-file-ignores = ydb/table.py:F401
7879

7980
[pytest]
8081
asyncio_mode = auto

ydb/_grpc/grpcwrapper/ydb_query.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
@dataclass
2323
class CreateSessionResponse(IFromProto):
24-
status: Optional[ServerStatus]
24+
status: ServerStatus
2525
session_id: str
2626
node_id: int
2727

@@ -36,7 +36,7 @@ def from_proto(msg: ydb_query_pb2.CreateSessionResponse) -> "CreateSessionRespon
3636

3737
@dataclass
3838
class DeleteSessionResponse(IFromProto):
39-
status: Optional[ServerStatus]
39+
status: ServerStatus
4040

4141
@staticmethod
4242
def from_proto(msg: ydb_query_pb2.DeleteSessionResponse) -> "DeleteSessionResponse":
@@ -129,10 +129,10 @@ def from_proto(msg: ydb_query_pb2.RollbackTransactionResponse) -> "RollbackTrans
129129
@dataclass
130130
class QueryContent(IFromPublic, IToProto):
131131
text: str
132-
syntax: Optional[int] = None
132+
syntax: int
133133

134134
@staticmethod
135-
def from_public(query: str, syntax: int = None) -> "QueryContent":
135+
def from_public(query: str, syntax: int) -> "QueryContent":
136136
return QueryContent(text=query, syntax=syntax)
137137

138138
def to_proto(self) -> ydb_query_pb2.QueryContent:
@@ -141,9 +141,9 @@ def to_proto(self) -> ydb_query_pb2.QueryContent:
141141

142142
@dataclass
143143
class TransactionControl(IToProto):
144-
begin_tx: Optional[TransactionSettings] = None
145-
commit_tx: Optional[bool] = None
146-
tx_id: Optional[str] = None
144+
begin_tx: Optional[TransactionSettings]
145+
commit_tx: Optional[bool]
146+
tx_id: Optional[str]
147147

148148
def to_proto(self) -> ydb_query_pb2.TransactionControl:
149149
if self.tx_id:
@@ -161,11 +161,11 @@ def to_proto(self) -> ydb_query_pb2.TransactionControl:
161161
class ExecuteQueryRequest(IToProto):
162162
session_id: str
163163
query_content: QueryContent
164-
tx_control: Optional[TransactionControl] = None
165-
concurrent_result_sets: Optional[bool] = False
166-
exec_mode: Optional[int] = None
167-
parameters: Optional[dict] = None
168-
stats_mode: Optional[int] = None
164+
tx_control: TransactionControl
165+
concurrent_result_sets: bool
166+
exec_mode: int
167+
parameters: dict
168+
stats_mode: int
169169

170170
def to_proto(self) -> ydb_query_pb2.ExecuteQueryRequest:
171171
tx_control = self.tx_control.to_proto() if self.tx_control is not None else self.tx_control

ydb/query/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"QueryStaleReadOnly",
66
"QuerySessionPool",
77
"QueryClientSync",
8+
"QuerySessionSync",
89
]
910

1011
import logging

0 commit comments

Comments
 (0)