1313import lombok .AllArgsConstructor ;
1414import lombok .Setter ;
1515import lombok .SneakyThrows ;
16- import lombok .Value ;
1716import lombok .experimental .Delegate ;
1817import org .assertj .core .api .Assertions ;
1918import org .junit .Assert ;
7473import tech .ydb .yoj .repository .ydb .sample .model .HintInt64Range ;
7574import tech .ydb .yoj .repository .ydb .sample .model .HintTablePreset ;
7675import tech .ydb .yoj .repository .ydb .sample .model .HintUniform ;
76+ import tech .ydb .yoj .repository .ydb .statement .FindAllYqlStatement ;
7777import tech .ydb .yoj .repository .ydb .statement .FindStatement ;
7878import tech .ydb .yoj .repository .ydb .statement .YqlStatement ;
7979import tech .ydb .yoj .repository .ydb .table .YdbTable ;
@@ -195,6 +195,18 @@ public void throwConversionExceptionOnSerializationProblem() {
195195
196196 @ Test
197197 public void readYqlListAndMap () {
198+ record GroupByResult (
199+ String id ,
200+ List <String > items ,
201+ Map <String , String > map ,
202+
203+ @ Column (flatten = false )
204+ GroupByResult .Struct struct
205+ ) {
206+ record Struct (String name ) {
207+ }
208+ }
209+
198210 WithUnflattenableField entity = new WithUnflattenableField (
199211 new WithUnflattenableField .Id ("id_yql_list" ),
200212 new WithUnflattenableField .Unflattenable ("Hello, world!" , 100_500 )
@@ -203,7 +215,7 @@ public void readYqlListAndMap() {
203215 db .tx (() -> {
204216 EntitySchema <WithUnflattenableField > schema = EntitySchema .of (WithUnflattenableField .class );
205217 var tableDescriptor = TableDescriptor .from (schema );
206- List <GroupByResult > result = (( YdbRepositoryTransaction <?>) Tx . Current . get (). getRepositoryTransaction () )
218+ List <GroupByResult > result = ydbRepositoryTransaction ( )
207219 .execute (new YqlStatement <>(tableDescriptor , schema , ObjectSchema .of (GroupByResult .class )) {
208220 @ Override
209221 public String getQuery (String tablespace ) {
@@ -230,20 +242,6 @@ public QueryType getQueryType() {
230242 });
231243 }
232244
233- @ Value
234- static class GroupByResult {
235- String id ;
236- List <String > items ;
237- Map <String , String > map ;
238- @ Column (flatten = false )
239- Struct struct ;
240-
241- @ Value
242- static class Struct {
243- String name ;
244- }
245- }
246-
247245 @ Test
248246 public void readViewFromCache () {
249247 TypeFreak tf1 = newTypeFreak (0 , "AAA1" , "bbb" );
@@ -893,15 +891,15 @@ public void creatingRepositoryDoesNotConnect() {
893891 public void ydbTransactionCompatibility () {
894892 db .tx (() -> {
895893 // No db tx or session yet!
896- var sdkTx = (( YdbRepositoryTransaction <?>) Tx . Current . get (). getRepositoryTransaction () ).toSdkTransaction ();
894+ var sdkTx = ydbRepositoryTransaction ( ).toSdkTransaction ();
897895 assertThatIllegalStateException ().isThrownBy (sdkTx ::getSessionId );
898896 assertThat (sdkTx .getId ()).isNull ();
899897 assertThat (sdkTx .getTxMode ()).isEqualTo (TxMode .SERIALIZABLE_RW );
900898 assertThatExceptionOfType (UnsupportedOperationException .class ).isThrownBy (sdkTx ::getStatusFuture );
901899
902900 // Perform any read - session and tx ID appear
903901 db .projects ().countAll ();
904- sdkTx = (( YdbRepositoryTransaction <?>) Tx . Current . get (). getRepositoryTransaction () ).toSdkTransaction ();
902+ sdkTx = ydbRepositoryTransaction ( ).toSdkTransaction ();
905903 assertThat (sdkTx .getSessionId ()).isNotNull ();
906904 assertThat (sdkTx .getId ()).isNotNull ();
907905 assertThat (sdkTx .getTxMode ()).isEqualTo (TxMode .SERIALIZABLE_RW );
@@ -919,15 +917,15 @@ public void ydbTransactionCompatibility() {
919917
920918 db .readOnly ().withStatementIsolationLevel (isolationLevel ).run (() -> {
921919 // No db tx or session yet!
922- var sdkTx = (( YdbRepositoryTransaction <?>) Tx . Current . get (). getRepositoryTransaction () ).toSdkTransaction ();
920+ var sdkTx = ydbRepositoryTransaction ( ).toSdkTransaction ();
923921 assertThatIllegalStateException ().isThrownBy (sdkTx ::getSessionId );
924922 assertThat (sdkTx .getId ()).isNull ();
925923 assertThat (sdkTx .getTxMode ()).isEqualTo (txMode );
926924 assertThatExceptionOfType (UnsupportedOperationException .class ).isThrownBy (sdkTx ::getStatusFuture );
927925
928926 // Perform any read - session and tx ID appear
929927 db .projects ().countAll ();
930- sdkTx = (( YdbRepositoryTransaction <?>) Tx . Current . get (). getRepositoryTransaction () ).toSdkTransaction ();
928+ sdkTx = ydbRepositoryTransaction ( ).toSdkTransaction ();
931929 assertThat (sdkTx .getSessionId ()).isNotNull ();
932930 // Read transactions might have no ID or might have an ID, depending on your YDB version (that's what YDB returns, folks!)
933931 assertThat (sdkTx .getTxMode ()).isEqualTo (txMode );
@@ -1019,6 +1017,54 @@ public void queryStatsCollectionMode() {
10191017 assertThat (found ).hasSize (4 );
10201018 }
10211019
1020+ @ Test
1021+ public void streamingScanNotTruncatedOldSpliterator () {
1022+ int maxPageSizeBiggerThatReal = 11_000 ;
1023+
1024+ db .tx (() -> IntStream .range (0 , maxPageSizeBiggerThatReal ).forEach (
1025+ i -> db .projects ().save (new Project (new Project .Id ("id_" + i ), "name" ))
1026+ ));
1027+
1028+ List <Project .Id > result = db .scan ().useNewSpliterator (false ).withMaxSize (maxPageSizeBiggerThatReal ).run (() -> {
1029+ var schema = EntitySchema .of (Project .class );
1030+ var desc = TableDescriptor .from (schema );
1031+ var statement = new FindAllYqlStatement <>(desc , schema , schema );
1032+
1033+ var projectIds = new ArrayList <Project .Id >();
1034+ try (var stream = ydbRepositoryTransaction ().executeScanQuery (statement , null )) {
1035+ stream .forEach (p -> projectIds .add (p .getId ()));
1036+ }
1037+ return projectIds ;
1038+ });
1039+ assertEquals (maxPageSizeBiggerThatReal , result .size ());
1040+ }
1041+
1042+ @ Test
1043+ public void streamingScanNotTruncatedNewSpliterator () {
1044+ int maxPageSizeBiggerThatReal = 11_000 ;
1045+
1046+ db .tx (() -> IntStream .range (0 , maxPageSizeBiggerThatReal ).forEach (
1047+ i -> db .projects ().save (new Project (new Project .Id ("id_" + i ), "name" ))
1048+ ));
1049+
1050+ List <Project .Id > result = db .scan ().useNewSpliterator (true ).withMaxSize (maxPageSizeBiggerThatReal ).run (() -> {
1051+ var schema = EntitySchema .of (Project .class );
1052+ var desc = TableDescriptor .from (schema );
1053+ var statement = new FindAllYqlStatement <>(desc , schema , schema );
1054+
1055+ var projectIds = new ArrayList <Project .Id >();
1056+ try (var stream = ydbRepositoryTransaction ().executeScanQuery (statement , null )) {
1057+ stream .forEach (p -> projectIds .add (p .getId ()));
1058+ }
1059+ return projectIds ;
1060+ });
1061+ assertEquals (maxPageSizeBiggerThatReal , result .size ());
1062+ }
1063+
1064+ private static YdbRepositoryTransaction <?> ydbRepositoryTransaction () {
1065+ return (YdbRepositoryTransaction <?>) Tx .Current .get ().getRepositoryTransaction ();
1066+ }
1067+
10221068 @ AllArgsConstructor
10231069 private static class DelegateSchemeServiceImplBase extends SchemeServiceGrpc .SchemeServiceImplBase {
10241070 @ Delegate
0 commit comments