1
1
package com .linkedin .venice .duckdb ;
2
2
3
3
import static com .linkedin .venice .utils .TestWriteUtils .NAME_RECORD_V1_SCHEMA ;
4
+ import static com .linkedin .venice .utils .TestWriteUtils .SIMPLE_USER_WITH_DEFAULT_SCHEMA ;
4
5
import static com .linkedin .venice .utils .TestWriteUtils .SINGLE_FIELD_RECORD_SCHEMA ;
5
6
import static org .testng .Assert .assertEquals ;
6
7
import static org .testng .Assert .assertFalse ;
@@ -140,7 +141,7 @@ public void testVersionSwap() throws SQLException {
140
141
141
142
try (Connection connection = DriverManager .getConnection (duckDBUrl );
142
143
Statement stmt = connection .createStatement ()) {
143
- try (ResultSet rs = stmt .executeQuery ("SELECT * FROM current_version" )) {
144
+ try (ResultSet rs = stmt .executeQuery ("SELECT * FROM " + storeName )) {
144
145
assertTrue (rs .next (), "There should be a first row!" );
145
146
assertEquals (rs .getString ("firstName" ), "Duck" );
146
147
assertEquals (rs .getString ("lastName" ), "Goose" );
@@ -150,12 +151,112 @@ public void testVersionSwap() throws SQLException {
150
151
// Swap here
151
152
recordTransformer_v1 .onEndVersionIngestion (2 );
152
153
153
- try (ResultSet rs = stmt .executeQuery ("SELECT * FROM current_version" )) {
154
+ try (ResultSet rs = stmt .executeQuery ("SELECT * FROM " + storeName )) {
154
155
assertTrue (rs .next (), "There should be a first row!" );
155
156
assertEquals (rs .getString ("firstName" ), "Goose" );
156
157
assertEquals (rs .getString ("lastName" ), "Duck" );
157
158
assertFalse (rs .next (), "There should be only one row!" );
158
159
}
159
160
}
160
161
}
162
+
163
+ @ Test
164
+ public void testTwoTablesConcurrently () throws SQLException {
165
+ String tempDir = Utils .getTempDataDirectory ().getAbsolutePath ();
166
+
167
+ String store1 = "store1" ;
168
+ String store2 = "store2" ;
169
+
170
+ DuckDBDaVinciRecordTransformer recordTransformerForStore1 = new DuckDBDaVinciRecordTransformer (
171
+ 1 ,
172
+ SINGLE_FIELD_RECORD_SCHEMA ,
173
+ NAME_RECORD_V1_SCHEMA ,
174
+ NAME_RECORD_V1_SCHEMA ,
175
+ false ,
176
+ tempDir ,
177
+ store1 ,
178
+ columnsToProject );
179
+ DuckDBDaVinciRecordTransformer recordTransformerForStore2 = new DuckDBDaVinciRecordTransformer (
180
+ 1 ,
181
+ SIMPLE_USER_WITH_DEFAULT_SCHEMA ,
182
+ NAME_RECORD_V1_SCHEMA ,
183
+ NAME_RECORD_V1_SCHEMA ,
184
+ false ,
185
+ tempDir ,
186
+ store2 ,
187
+ columnsToProject );
188
+
189
+ String duckDBUrl = recordTransformerForStore1 .getDuckDBUrl ();
190
+
191
+ recordTransformerForStore1 .onStartVersionIngestion (true );
192
+
193
+ GenericRecord keyRecord = new GenericData .Record (SINGLE_FIELD_RECORD_SCHEMA );
194
+ keyRecord .put ("key" , "key" );
195
+ Lazy <GenericRecord > lazyKey = Lazy .of (() -> keyRecord );
196
+
197
+ GenericRecord valueRecordForStore1 = new GenericData .Record (NAME_RECORD_V1_SCHEMA );
198
+ valueRecordForStore1 .put ("firstName" , "Duck" );
199
+ valueRecordForStore1 .put ("lastName" , "Goose" );
200
+ Lazy <GenericRecord > lazyValue = Lazy .of (() -> valueRecordForStore1 );
201
+ recordTransformerForStore1 .processPut (lazyKey , lazyValue );
202
+
203
+ try (Connection connection = DriverManager .getConnection (duckDBUrl );
204
+ Statement stmt = connection .createStatement ()) {
205
+ try (ResultSet rs = stmt .executeQuery ("SELECT * FROM " + store1 )) {
206
+ assertTrue (rs .next (), "There should be a first row!" );
207
+ assertEquals (rs .getString ("key" ), "key" );
208
+ assertEquals (rs .getString ("firstName" ), "Duck" );
209
+ assertEquals (rs .getString ("lastName" ), "Goose" );
210
+ assertFalse (rs .next (), "There should be only one row!" );
211
+ }
212
+ }
213
+
214
+ recordTransformerForStore2 .onStartVersionIngestion (true );
215
+
216
+ GenericRecord keyRecordForStore2 = new GenericData .Record (SIMPLE_USER_WITH_DEFAULT_SCHEMA );
217
+ keyRecordForStore2 .put ("key" , "key" );
218
+ keyRecordForStore2 .put ("value" , "value" );
219
+ Lazy <GenericRecord > lazyKeyForStore2 = Lazy .of (() -> keyRecordForStore2 );
220
+
221
+ GenericRecord valueRecordForStore2 = new GenericData .Record (NAME_RECORD_V1_SCHEMA );
222
+ valueRecordForStore2 .put ("firstName" , "Duck2" );
223
+ valueRecordForStore2 .put ("lastName" , "Goose2" );
224
+ Lazy <GenericRecord > lazyValueForStore2 = Lazy .of (() -> valueRecordForStore2 );
225
+ recordTransformerForStore2 .processPut (lazyKeyForStore2 , lazyValueForStore2 );
226
+
227
+ try (Connection connection = DriverManager .getConnection (duckDBUrl );
228
+ Statement stmt = connection .createStatement ()) {
229
+ try (ResultSet rs = stmt .executeQuery ("SELECT * FROM " + store1 )) {
230
+ assertTrue (rs .next (), "There should be a first row!" );
231
+ assertEquals (rs .getString ("key" ), "key" );
232
+ assertEquals (rs .getString ("firstName" ), "Duck" );
233
+ assertEquals (rs .getString ("lastName" ), "Goose" );
234
+ assertFalse (rs .next (), "There should be only one row!" );
235
+ }
236
+
237
+ try (ResultSet rs = stmt .executeQuery ("SELECT * FROM " + store2 )) {
238
+ assertTrue (rs .next (), "There should be a first row!" );
239
+ assertEquals (rs .getString ("key" ), "key" );
240
+ assertEquals (rs .getString ("value" ), "value" );
241
+ assertEquals (rs .getString ("firstName" ), "Duck2" );
242
+ assertEquals (rs .getString ("lastName" ), "Goose2" );
243
+ assertFalse (rs .next (), "There should be only one row!" );
244
+ }
245
+
246
+ try (ResultSet rs = stmt .executeQuery (
247
+ "SELECT s1.key AS s1key, s1.firstName AS s1FirstName, s1.lastName AS s1LastName, "
248
+ + "s2.key AS s2key, s2.value AS s2value, s2.firstName AS s2FirstName, s2.lastName AS s2LastName "
249
+ + "FROM " + store1 + " s1 JOIN " + store2 + " s2 ON s1.key = s2.key" )) {
250
+ assertTrue (rs .next (), "There should be a first row!" );
251
+ assertEquals (rs .getString ("s1key" ), "key" );
252
+ assertEquals (rs .getString ("s1FirstName" ), "Duck" );
253
+ assertEquals (rs .getString ("s1LastName" ), "Goose" );
254
+ assertEquals (rs .getString ("s2key" ), "key" );
255
+ assertEquals (rs .getString ("s2value" ), "value" );
256
+ assertEquals (rs .getString ("s2FirstName" ), "Duck2" );
257
+ assertEquals (rs .getString ("s2LastName" ), "Goose2" );
258
+ assertFalse (rs .next (), "There should be only one row!" );
259
+ }
260
+ }
261
+ }
161
262
}
0 commit comments