|
13 | 13 | import org.junit.After; |
14 | 14 | import org.junit.Assert; |
15 | 15 | import org.junit.ClassRule; |
| 16 | +import org.junit.Ignore; |
16 | 17 | import org.junit.Test; |
17 | 18 |
|
18 | 19 | import tech.ydb.core.grpc.GrpcReadStream; |
|
22 | 23 | import tech.ydb.table.impl.SimpleTableClient; |
23 | 24 | import tech.ydb.table.query.BulkUpsertData; |
24 | 25 | import tech.ydb.table.query.Params; |
| 26 | +import tech.ydb.table.query.arrow.ApacheArrowData; |
25 | 27 | import tech.ydb.table.query.arrow.ApacheArrowWriter; |
26 | 28 | import tech.ydb.table.result.ResultSetReader; |
27 | 29 | import tech.ydb.table.rpc.grpc.GrpcTableRpc; |
28 | 30 | import tech.ydb.table.settings.ExecuteScanQuerySettings; |
29 | 31 | import tech.ydb.table.settings.ExecuteSchemeQuerySettings; |
| 32 | +import tech.ydb.table.utils.Hex; |
30 | 33 | import tech.ydb.table.values.ListValue; |
| 34 | +import tech.ydb.table.values.PrimitiveType; |
31 | 35 | import tech.ydb.table.values.PrimitiveValue; |
32 | 36 | import tech.ydb.test.junit4.GrpcTransportRule; |
33 | 37 |
|
@@ -160,11 +164,59 @@ public void writeProtobufToColumnShardTable() { |
160 | 164 | Assert.assertEquals(5000, rows2Count); |
161 | 165 | } |
162 | 166 |
|
| 167 | + @Test |
| 168 | + @Ignore("https://github.com/ydb-platform/ydb/issues/36331") |
| 169 | + public void writeApacheArrowEmptyStringToDataShardTest() { |
| 170 | + // Create table |
| 171 | + TableDescription table = TableDescription.newBuilder() |
| 172 | + .addNullableColumn("id", PrimitiveType.Int32) |
| 173 | + .addNullableColumn("text", PrimitiveType.Text) |
| 174 | + .setPrimaryKey("id") |
| 175 | + .build(); |
| 176 | + |
| 177 | + createTable(table); |
| 178 | + |
| 179 | + ApacheArrowWriter.Schema schema = ApacheArrowWriter.newSchema() |
| 180 | + .addNullableColumn("id", PrimitiveType.Int32) |
| 181 | + .addNullableColumn("text", PrimitiveType.Text); |
| 182 | + |
| 183 | + try (BufferAllocator allocator = new RootAllocator()) { |
| 184 | + try (ApacheArrowWriter writer = schema.createWriter(allocator)) { |
| 185 | + // create batch with estimated size |
| 186 | + ApacheArrowWriter.Batch batch = writer.createNewBatch(1); |
| 187 | + ApacheArrowWriter.Row row = batch.writeNextRow(); |
| 188 | + row.writeInt32("id", 1); |
| 189 | + row.writeNull("text"); |
| 190 | + ApacheArrowData data = batch.buildBatch(); |
| 191 | + System.out.println("SCHEMA = \n" + Hex.toHex(data.getSchema())); |
| 192 | + System.out.println("DATA = \n" + Hex.toHex(data.getData())); |
| 193 | + bulkUpsert(data); |
| 194 | + } catch (IOException ex) { |
| 195 | + throw new AssertionError("Cannot serialize apache arrow", ex); |
| 196 | + } |
| 197 | + } |
| 198 | + |
| 199 | + retryCtx.supplyStatus(session -> { |
| 200 | + GrpcReadStream<ResultSetReader> stream = session.executeScanQuery( |
| 201 | + "SELECT * FROM `" + TEST_TABLE + "`;", |
| 202 | + Params.empty(), |
| 203 | + ExecuteScanQuerySettings.newBuilder().build() |
| 204 | + ); |
| 205 | + |
| 206 | + return stream.start((rs) -> { |
| 207 | + Assert.assertTrue(rs.next()); |
| 208 | + Assert.assertEquals(1, rs.getColumn("id").getInt32()); |
| 209 | + Assert.assertEquals("", rs.getColumn("text").getText()); |
| 210 | + Assert.assertFalse(rs.next()); |
| 211 | + }); |
| 212 | + }).join().expectSuccess("cannot read table"); |
| 213 | + } |
| 214 | + |
163 | 215 | @Test |
164 | 216 | public void writeApacheArrowToDataShardTest() { |
165 | 217 | // Create table |
166 | 218 | TableDescription table = AllTypesRecord.createTableDescription(false); |
167 | | - retryCtx.supplyStatus(s -> s.createTable(tablePath(), table)).join().expectSuccess("Cannot create table"); |
| 219 | + createTable(table); |
168 | 220 |
|
169 | 221 | Set<String> columnNames = table.getColumns().stream().map(TableColumn::getName).collect(Collectors.toSet()); |
170 | 222 |
|
@@ -210,7 +262,7 @@ public void writeApacheArrowToDataShardTest() { |
210 | 262 | public void writeApacheArrowToColumnShardTest() { |
211 | 263 | // Create table |
212 | 264 | TableDescription table = AllTypesRecord.createTableDescription(true); |
213 | | - retryCtx.supplyStatus(s -> s.createTable(tablePath(), table)).join().expectSuccess("Cannot create table"); |
| 265 | + createTable(table); |
214 | 266 |
|
215 | 267 | Set<String> columnNames = table.getColumns().stream().map(TableColumn::getName).collect(Collectors.toSet()); |
216 | 268 |
|
|
0 commit comments