33import java .time .Instant ;
44import java .util .ArrayList ;
55import java .util .List ;
6- import java .util .UUID ;
6+ import java .util .Random ;
77import java .util .concurrent .CompletableFuture ;
8+ import java .util .concurrent .ThreadLocalRandom ;
9+
810import tech .ydb .core .Result ;
911import tech .ydb .table .SessionRetryContext ;
1012import tech .ydb .table .result .ResultSetReader ;
@@ -29,15 +31,15 @@ public KeyValueApiYdbRepository(SessionRetryContext retryTableCtx) {
2931
3032 public void bulkUpsert (String tableName , List <TitleAuthor > titleAuthorList ) {
3133 var structType = StructType .of (
32- "id" , PrimitiveType .Uuid ,
34+ "id" , PrimitiveType .Int64 ,
3335 "title" , PrimitiveType .Text ,
3436 "author" , PrimitiveType .Text ,
3537 "created_at" , OptionalType .of (PrimitiveType .Timestamp )
3638 );
3739
3840 var listIssues = ListType .of (structType ).newValue (
3941 titleAuthorList .stream ().map (issue -> structType .newValue (
40- "id" , PrimitiveValue .newUuid ( UUID . randomUUID ()),
42+ "id" , PrimitiveValue .newInt64 ( ThreadLocalRandom . current (). nextLong ()),
4143 "title" , PrimitiveValue .newText (issue .title ()),
4244 "author" , PrimitiveValue .newText (issue .author ()),
4345 "created_at" , OptionalType .of (PrimitiveType .Timestamp )
@@ -68,15 +70,16 @@ public List<Issue> readTable(String tableName) {
6870 ).join ().getValue ();
6971 }
7072
71- public List <Issue > readRows (String tableName , UUID id ) {
72- var keyStruct = StructType .of ("id" , PrimitiveType .Uuid );
73+ public List <Issue > readRows (String tableName , long id ) {
74+ var keyStruct = StructType .of ("id" , PrimitiveType .Int64 );
7375
7476 return retryTableCtx .supplyResult (session -> {
7577 var listResult = new ArrayList <Issue >();
7678
7779 var resultSetReader = session .readRows (tableName ,
7880 ReadRowsSettings .newBuilder ()
79- .addKey (keyStruct .newValue ("id" , PrimitiveValue .newUuid (id )))
81+ .addKey (keyStruct .newValue ("id" , PrimitiveValue .newInt64 (id )))
82+ .addColumns ("id" , "title" , "created_at" , "author" )
8083 .build ()
8184 ).join ().getValue ().getResultSetReader ();
8285
@@ -89,10 +92,24 @@ public List<Issue> readRows(String tableName, UUID id) {
8992
9093 private void fetchIssues (ArrayList <Issue > listResult , ResultSetReader resultSetReader ) {
9194 while (resultSetReader .next ()) {
92- var id = resultSetReader .getColumn (0 ).getUuid ();
95+ var id = resultSetReader .getColumn (0 ).getInt64 ();
9396
94- if (!id .toString ().contains ("0" )) {
97+ if (!Long .toString (id ).contains ("0" )) {
9598 continue ;
99+ };
100+
101+ long linksCount ;
102+ if (resultSetReader .getColumnCount () > 4 ) {
103+ linksCount = resultSetReader .getColumn (4 ).getInt64 ();
104+ } else {
105+ linksCount = 0 ;
106+ }
107+
108+ String status ;
109+ if (resultSetReader .getColumnCount () > 5 ) {
110+ status = resultSetReader .getColumn (5 ).getText ();
111+ } else {
112+ status = "" ;
96113 }
97114
98115 listResult .add (
@@ -101,8 +118,8 @@ private void fetchIssues(ArrayList<Issue> listResult, ResultSetReader resultSetR
101118 resultSetReader .getColumn (1 ).getText (),
102119 resultSetReader .getColumn (2 ).getTimestamp (),
103120 resultSetReader .getColumn (3 ).getText (),
104- resultSetReader . getColumn ( 4 ). getInt64 () ,
105- resultSetReader . getColumn ( 5 ). getText ()
121+ linksCount ,
122+ status
106123 )
107124 );
108125 }
0 commit comments