1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
|
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package pqarrow
import (
"context"
"testing"
"github.com/apache/arrow-go/v18/arrow"
"github.com/apache/arrow-go/v18/arrow/array"
"github.com/apache/arrow-go/v18/arrow/extensions"
"github.com/apache/arrow-go/v18/arrow/memory"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNonNullableSingleList(t *testing.T) {
// translates to the following parquet schema:
// required group bag {
// repeated group [unseen] (List) {
// required int64 Entires;
// }
// }
// So:
// def level 0: a null entry
// def level 1: a non-null entry
bldr := array.NewListBuilder(memory.DefaultAllocator, arrow.PrimitiveTypes.Int64)
defer bldr.Release()
vb := bldr.ValueBuilder().(*array.Int64Builder)
bldr.Append(true)
vb.Append(1)
bldr.Append(true)
vb.Append(2)
vb.Append(3)
bldr.Append(true)
vb.Append(4)
vb.Append(5)
vb.Append(6)
arr := bldr.NewListArray()
defer arr.Release()
mp, err := newMultipathLevelBuilder(arr, false)
require.NoError(t, err)
defer mp.Release()
ctx := arrowCtxFromContext(NewArrowWriteContext(context.Background(), nil))
result, err := mp.write(0, ctx)
require.NoError(t, err)
assert.Equal(t, []int16{2, 2, 2, 2, 2, 2}, result.defLevels)
assert.Equal(t, []int16{0, 0, 1, 0, 1, 1}, result.repLevels)
assert.Len(t, result.postListVisitedElems, 1)
assert.EqualValues(t, 0, result.postListVisitedElems[0].start)
assert.EqualValues(t, 6, result.postListVisitedElems[0].end)
}
// next group of tests translates to the following parquet schema:
// optional group bag {
// repeated group [unseen] (List) {
// optional int64 Entires;
// }
// }
// So:
// def level 0: a null list
// def level 1: an empty list
// def level 2: a null entry
// def level 3: a non-null entry
func TestNullableSingleListAllNulls(t *testing.T) {
bldr := array.NewListBuilder(memory.DefaultAllocator, arrow.PrimitiveTypes.Int64)
defer bldr.Release()
bldr.AppendNull()
bldr.AppendNull()
bldr.AppendNull()
bldr.AppendNull()
arr := bldr.NewListArray()
defer arr.Release()
mp, err := newMultipathLevelBuilder(arr, true)
require.NoError(t, err)
defer mp.Release()
ctx := arrowCtxFromContext(NewArrowWriteContext(context.Background(), nil))
result, err := mp.write(0, ctx)
require.NoError(t, err)
assert.Equal(t, []int16{0, 0, 0, 0}, result.defLevels)
assert.Equal(t, []int16{0, 0, 0, 0}, result.repLevels)
}
func TestNullableSingleListAllEmpty(t *testing.T) {
bldr := array.NewListBuilder(memory.DefaultAllocator, arrow.PrimitiveTypes.Int64)
defer bldr.Release()
bldr.Append(true)
bldr.Append(true)
bldr.Append(true)
bldr.Append(true)
arr := bldr.NewListArray()
defer arr.Release()
mp, err := newMultipathLevelBuilder(arr, true)
require.NoError(t, err)
defer mp.Release()
ctx := arrowCtxFromContext(NewArrowWriteContext(context.Background(), nil))
result, err := mp.write(0, ctx)
require.NoError(t, err)
assert.Equal(t, []int16{1, 1, 1, 1}, result.defLevels)
assert.Equal(t, []int16{0, 0, 0, 0}, result.repLevels)
}
func TestNullableSingleListAllNullEntries(t *testing.T) {
bldr := array.NewListBuilder(memory.DefaultAllocator, arrow.PrimitiveTypes.Int64)
defer bldr.Release()
vb := bldr.ValueBuilder().(*array.Int64Builder)
bldr.Append(true)
vb.AppendNull()
bldr.Append(true)
vb.AppendNull()
bldr.Append(true)
vb.AppendNull()
bldr.Append(true)
vb.AppendNull()
arr := bldr.NewListArray()
defer arr.Release()
mp, err := newMultipathLevelBuilder(arr, true)
require.NoError(t, err)
defer mp.Release()
ctx := arrowCtxFromContext(NewArrowWriteContext(context.Background(), nil))
result, err := mp.write(0, ctx)
require.NoError(t, err)
assert.Equal(t, []int16{2, 2, 2, 2}, result.defLevels)
assert.Equal(t, []int16{0, 0, 0, 0}, result.repLevels)
assert.Len(t, result.postListVisitedElems, 1)
assert.EqualValues(t, 0, result.postListVisitedElems[0].start)
assert.EqualValues(t, 4, result.postListVisitedElems[0].end)
}
func TestNullableSingleListAllPresentEntries(t *testing.T) {
bldr := array.NewListBuilder(memory.DefaultAllocator, arrow.PrimitiveTypes.Int64)
defer bldr.Release()
vb := bldr.ValueBuilder().(*array.Int64Builder)
bldr.Append(true)
bldr.Append(true)
bldr.Append(true)
vb.Append(1)
bldr.Append(true)
bldr.Append(true)
vb.Append(2)
vb.Append(3)
arr := bldr.NewListArray()
defer arr.Release()
mp, err := newMultipathLevelBuilder(arr, true)
require.NoError(t, err)
defer mp.Release()
ctx := arrowCtxFromContext(NewArrowWriteContext(context.Background(), nil))
result, err := mp.write(0, ctx)
require.NoError(t, err)
assert.Equal(t, []int16{1, 1, 3, 1, 3, 3}, result.defLevels)
assert.Equal(t, []int16{0, 0, 0, 0, 0, 1}, result.repLevels)
assert.Len(t, result.postListVisitedElems, 1)
assert.EqualValues(t, 0, result.postListVisitedElems[0].start)
assert.EqualValues(t, 3, result.postListVisitedElems[0].end)
}
func TestNullableSingleListSomeNullEntriesSomeNullLists(t *testing.T) {
bldr := array.NewListBuilder(memory.DefaultAllocator, arrow.PrimitiveTypes.Int64)
defer bldr.Release()
vb := bldr.ValueBuilder().(*array.Int64Builder)
bldr.Append(false)
bldr.Append(true)
vb.AppendValues([]int64{1, 2, 3}, nil)
bldr.Append(true)
bldr.Append(true)
bldr.AppendNull()
bldr.AppendNull()
bldr.Append(true)
vb.AppendValues([]int64{4, 5}, nil)
bldr.Append(true)
vb.AppendNull()
arr := bldr.NewListArray()
defer arr.Release()
mp, err := newMultipathLevelBuilder(arr, true)
require.NoError(t, err)
defer mp.Release()
ctx := arrowCtxFromContext(NewArrowWriteContext(context.Background(), nil))
result, err := mp.write(0, ctx)
require.NoError(t, err)
assert.Equal(t, []int16{0, 3, 3, 3, 1, 1, 0, 0, 3, 3, 2}, result.defLevels)
assert.Equal(t, []int16{0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0}, result.repLevels)
}
// next group of tests translate to the following parquet schema:
//
// optional group bag {
// repeated group outer_list (List) {
// optional group nullable {
// repeated group inner_list (List) {
// optional int64 Entries;
// }
// }
// }
// }
// So:
// def level 0: null outer list
// def level 1: empty outer list
// def level 2: null inner list
// def level 3: empty inner list
// def level 4: null entry
// def level 5: non-null entry
func TestNestedListsWithSomeEntries(t *testing.T) {
listType := arrow.ListOf(arrow.PrimitiveTypes.Int64)
bldr := array.NewListBuilder(memory.DefaultAllocator, listType)
defer bldr.Release()
nestedBldr := bldr.ValueBuilder().(*array.ListBuilder)
vb := nestedBldr.ValueBuilder().(*array.Int64Builder)
// produce: [null, [[1, 2, 3], [4, 5]], [[], [], []], []]
bldr.AppendNull()
bldr.Append(true)
nestedBldr.Append(true)
vb.AppendValues([]int64{1, 2, 3}, nil)
nestedBldr.Append(true)
vb.AppendValues([]int64{4, 5}, nil)
bldr.Append(true)
nestedBldr.Append(true)
nestedBldr.Append(true)
nestedBldr.Append(true)
bldr.Append(true)
arr := bldr.NewListArray()
defer arr.Release()
mp, err := newMultipathLevelBuilder(arr, true)
require.NoError(t, err)
defer mp.Release()
ctx := arrowCtxFromContext(NewArrowWriteContext(context.Background(), nil))
result, err := mp.write(0, ctx)
require.NoError(t, err)
assert.Equal(t, []int16{0, 5, 5, 5, 5, 5, 3, 3, 3, 1}, result.defLevels)
assert.Equal(t, []int16{0, 0, 2, 2, 1, 2, 0, 1, 1, 0}, result.repLevels)
}
func TestNestedListsWithSomeNulls(t *testing.T) {
listType := arrow.ListOf(arrow.PrimitiveTypes.Int64)
bldr := array.NewListBuilder(memory.DefaultAllocator, listType)
defer bldr.Release()
nestedBldr := bldr.ValueBuilder().(*array.ListBuilder)
vb := nestedBldr.ValueBuilder().(*array.Int64Builder)
// produce: [null, [[1, null, 3], null, null], [[4, 5]]]
bldr.AppendNull()
bldr.Append(true)
nestedBldr.Append(true)
vb.AppendValues([]int64{1, 0, 3}, []bool{true, false, true})
nestedBldr.AppendNull()
nestedBldr.AppendNull()
bldr.Append(true)
nestedBldr.Append(true)
vb.AppendValues([]int64{4, 5}, nil)
arr := bldr.NewListArray()
defer arr.Release()
mp, err := newMultipathLevelBuilder(arr, true)
require.NoError(t, err)
defer mp.Release()
ctx := arrowCtxFromContext(NewArrowWriteContext(context.Background(), nil))
result, err := mp.write(0, ctx)
require.NoError(t, err)
assert.Equal(t, []int16{0, 5, 4, 5, 2, 2, 5, 5}, result.defLevels)
assert.Equal(t, []int16{0, 0, 2, 2, 1, 1, 0, 2}, result.repLevels)
}
func TestNestedListsSomeNullsSomeEmpty(t *testing.T) {
listType := arrow.ListOf(arrow.PrimitiveTypes.Int64)
bldr := array.NewListBuilder(memory.DefaultAllocator, listType)
defer bldr.Release()
nestedBldr := bldr.ValueBuilder().(*array.ListBuilder)
vb := nestedBldr.ValueBuilder().(*array.Int64Builder)
// produce: [null, [[1, null, 3], [], []], [[4, 5]]]
bldr.AppendNull()
bldr.Append(true)
nestedBldr.Append(true)
vb.AppendValues([]int64{1, 0, 3}, []bool{true, false, true})
nestedBldr.Append(true)
nestedBldr.Append(true)
bldr.Append(true)
nestedBldr.Append(true)
vb.AppendValues([]int64{4, 5}, nil)
arr := bldr.NewListArray()
defer arr.Release()
mp, err := newMultipathLevelBuilder(arr, true)
require.NoError(t, err)
defer mp.Release()
ctx := arrowCtxFromContext(NewArrowWriteContext(context.Background(), nil))
result, err := mp.write(0, ctx)
require.NoError(t, err)
assert.Equal(t, []int16{0, 5, 4, 5, 3, 3, 5, 5}, result.defLevels)
assert.Equal(t, []int16{0, 0, 2, 2, 1, 1, 0, 2}, result.repLevels)
}
func TestNestedExtensionListsWithSomeNulls(t *testing.T) {
mem := memory.NewCheckedAllocator(memory.DefaultAllocator)
defer mem.AssertSize(t, 0)
listType := arrow.ListOf(extensions.NewUUIDType())
bldr := array.NewListBuilder(mem, listType)
defer bldr.Release()
nestedBldr := bldr.ValueBuilder().(*array.ListBuilder)
vb := nestedBldr.ValueBuilder().(*extensions.UUIDBuilder)
uuid1 := uuid.New()
uuid3 := uuid.New()
uuid4 := uuid.New()
uuid5 := uuid.New()
// produce: [null, [[uuid1, null, uuid3], null, null], [[uuid4, uuid5]]]
bldr.AppendNull()
bldr.Append(true)
nestedBldr.Append(true)
vb.Append(uuid1)
vb.AppendNull()
vb.Append(uuid3)
nestedBldr.AppendNull()
nestedBldr.AppendNull()
bldr.Append(true)
nestedBldr.Append(true)
vb.AppendValues([]uuid.UUID{uuid4, uuid5}, nil)
arr := bldr.NewListArray()
defer arr.Release()
mp, err := newMultipathLevelBuilder(arr, true)
require.NoError(t, err)
defer mp.Release()
ctx := arrowCtxFromContext(NewArrowWriteContext(context.Background(), nil))
result, err := mp.write(0, ctx)
require.NoError(t, err)
assert.Equal(t, []int16{0, 5, 4, 5, 2, 2, 5, 5}, result.defLevels)
assert.Equal(t, []int16{0, 0, 2, 2, 1, 1, 0, 2}, result.repLevels)
assert.Equal(t, result.leafArr.NullN(), 1)
}
// triplenested translates to parquet:
//
// optional group bag {
// repeated group outer_list (List) {
// option group nullable {
// repeated group middle_list (List) {
// option group nullable {
// repeated group inner_list (List) {
// optional int64 Entries;
// }
// }
// }
// }
// }
// }
// So:
// def level 0: a outer list
// def level 1: an empty outer list
// def level 2: a null middle list
// def level 3: an empty middle list
// def level 4: an null inner list
// def level 5: an empty inner list
// def level 6: a null entry
// def level 7: a non-null entry
func TestTripleNestedAllPresent(t *testing.T) {
listType := arrow.ListOf(arrow.PrimitiveTypes.Int64)
nestedListType := arrow.ListOf(listType)
bldr := array.NewListBuilder(memory.DefaultAllocator, nestedListType)
defer bldr.Release()
dblNestedBldr := bldr.ValueBuilder().(*array.ListBuilder)
nestedBldr := dblNestedBldr.ValueBuilder().(*array.ListBuilder)
vb := nestedBldr.ValueBuilder().(*array.Int64Builder)
// produce: [ [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9]]] ]
bldr.Append(true)
dblNestedBldr.Append(true)
nestedBldr.Append(true)
vb.AppendValues([]int64{1, 2, 3}, nil)
nestedBldr.Append(true)
vb.AppendValues([]int64{4, 5, 6}, nil)
dblNestedBldr.Append(true)
nestedBldr.Append(true)
vb.AppendValues([]int64{7, 8, 9}, nil)
arr := bldr.NewListArray()
defer arr.Release()
mp, err := newMultipathLevelBuilder(arr, true)
require.NoError(t, err)
defer mp.Release()
ctx := arrowCtxFromContext(NewArrowWriteContext(context.Background(), nil))
result, err := mp.write(0, ctx)
require.NoError(t, err)
assert.Equal(t, []int16{7, 7, 7, 7, 7, 7, 7, 7, 7}, result.defLevels)
assert.Equal(t, []int16{0, 3, 3, 2, 3, 3, 1, 3, 3}, result.repLevels)
}
func TestTripleNestedSomeNullsSomeEmpty(t *testing.T) {
listType := arrow.ListOf(arrow.PrimitiveTypes.Int64)
nestedListType := arrow.ListOf(listType)
bldr := array.NewListBuilder(memory.DefaultAllocator, nestedListType)
defer bldr.Release()
dblNestedBldr := bldr.ValueBuilder().(*array.ListBuilder)
nestedBldr := dblNestedBldr.ValueBuilder().(*array.ListBuilder)
vb := nestedBldr.ValueBuilder().(*array.Int64Builder)
// produce: [
// [null, [[1, null, 3], []], []], first row
// [[[]], [[], [1, 2]], null, [[3]]], second row
// null, third row
// [] fourth row
// ]
// first row
bldr.Append(true)
dblNestedBldr.AppendNull()
dblNestedBldr.Append(true)
nestedBldr.Append(true)
vb.AppendValues([]int64{1, 0, 3}, []bool{true, false, true})
nestedBldr.Append(true)
dblNestedBldr.Append(true)
// second row
bldr.Append(true)
dblNestedBldr.Append(true)
nestedBldr.Append(true)
dblNestedBldr.Append(true)
nestedBldr.Append(true)
nestedBldr.Append(true)
vb.AppendValues([]int64{1, 2}, nil)
dblNestedBldr.AppendNull()
dblNestedBldr.Append(true)
nestedBldr.Append(true)
vb.Append(3)
// third row
bldr.AppendNull()
// fourth row
bldr.Append(true)
arr := bldr.NewListArray()
defer arr.Release()
mp, err := newMultipathLevelBuilder(arr, true)
require.NoError(t, err)
defer mp.Release()
ctx := arrowCtxFromContext(NewArrowWriteContext(context.Background(), nil))
result, err := mp.write(0, ctx)
require.NoError(t, err)
assert.Equal(t, []int16{
2, 7, 6, 7, 5, 3, // first row
5, 5, 7, 7, 2, 7, // second row
0, // third row
1,
}, result.defLevels)
assert.Equal(t, []int16{
0, 1, 3, 3, 2, 1, // first row
0, 1, 2, 3, 1, 1, // second row
0, 0,
}, result.repLevels)
}
func TestStruct(t *testing.T) {
structType := arrow.StructOf(arrow.Field{Name: "list", Type: arrow.ListOf(arrow.PrimitiveTypes.Int64), Nullable: true},
arrow.Field{Name: "Entries", Type: arrow.PrimitiveTypes.Int64, Nullable: true})
bldr := array.NewStructBuilder(memory.DefaultAllocator, structType)
defer bldr.Release()
entryBldr := bldr.FieldBuilder(1).(*array.Int64Builder)
listBldr := bldr.FieldBuilder(0).(*array.ListBuilder)
vb := listBldr.ValueBuilder().(*array.Int64Builder)
// produce: [ {"Entries": 1, "list": [2, 3]}, {"Entries": 4, "list": [5, 6]}, null]
bldr.Append(true)
entryBldr.Append(1)
listBldr.Append(true)
vb.AppendValues([]int64{2, 3}, nil)
bldr.Append(true)
entryBldr.Append(4)
listBldr.Append(true)
vb.AppendValues([]int64{5, 6}, nil)
bldr.AppendNull()
arr := bldr.NewArray()
defer arr.Release()
mp, err := newMultipathLevelBuilder(arr, true)
require.NoError(t, err)
defer mp.Release()
ctx := arrowCtxFromContext(NewArrowWriteContext(context.Background(), nil))
result, err := mp.writeAll(ctx)
require.NoError(t, err)
assert.Len(t, result, 2)
assert.Equal(t, []int16{4, 4, 4, 4, 0}, result[0].defLevels)
assert.Equal(t, []int16{0, 1, 0, 1, 0}, result[0].repLevels)
assert.Equal(t, []int16{2, 2, 0}, result[1].defLevels)
assert.Nil(t, result[1].repLevels)
}
func TestFixedSizeListNullableElems(t *testing.T) {
bldr := array.NewFixedSizeListBuilder(memory.DefaultAllocator, 2, arrow.PrimitiveTypes.Int64)
defer bldr.Release()
vb := bldr.ValueBuilder().(*array.Int64Builder)
bldr.AppendValues([]bool{false, true, true, false})
vb.AppendValues([]int64{2, 3, 4, 5}, nil)
// produce: [null, [2, 3], [4, 5], null]
arr := bldr.NewArray()
defer arr.Release()
mp, err := newMultipathLevelBuilder(arr, true)
require.NoError(t, err)
defer mp.Release()
ctx := arrowCtxFromContext(NewArrowWriteContext(context.Background(), nil))
result, err := mp.writeAll(ctx)
require.NoError(t, err)
assert.Len(t, result, 1)
assert.Equal(t, []int16{0, 3, 3, 3, 3, 0}, result[0].defLevels)
assert.Equal(t, []int16{0, 0, 1, 0, 1, 0}, result[0].repLevels)
// null slots take up space in a fixed size list (they can in variable
// size lists as well) but the actual written values are only the middle
// elements
assert.Len(t, result[0].postListVisitedElems, 1)
assert.EqualValues(t, 2, result[0].postListVisitedElems[0].start)
assert.EqualValues(t, 6, result[0].postListVisitedElems[0].end)
}
func TestFixedSizeListMissingMiddleTwoVisitedRanges(t *testing.T) {
bldr := array.NewFixedSizeListBuilder(memory.DefaultAllocator, 2, arrow.PrimitiveTypes.Int64)
defer bldr.Release()
vb := bldr.ValueBuilder().(*array.Int64Builder)
bldr.AppendValues([]bool{true, false, true})
vb.AppendValues([]int64{0, 1, 2, 3}, nil)
// produce: [[0, 1], null, [2, 3]]
arr := bldr.NewArray()
defer arr.Release()
mp, err := newMultipathLevelBuilder(arr, true)
require.NoError(t, err)
defer mp.Release()
ctx := arrowCtxFromContext(NewArrowWriteContext(context.Background(), nil))
result, err := mp.writeAll(ctx)
require.NoError(t, err)
assert.Len(t, result, 1)
assert.Equal(t, []int16{3, 3, 0, 3, 3}, result[0].defLevels)
assert.Equal(t, []int16{0, 1, 0, 0, 1}, result[0].repLevels)
// null slots take up space in a fixed size list (they can in variable
// size lists as well) but the actual written values are only the middle
// elements
assert.Len(t, result[0].postListVisitedElems, 2)
assert.EqualValues(t, 0, result[0].postListVisitedElems[0].start)
assert.EqualValues(t, 2, result[0].postListVisitedElems[0].end)
assert.EqualValues(t, 4, result[0].postListVisitedElems[1].start)
assert.EqualValues(t, 6, result[0].postListVisitedElems[1].end)
}
func TestPrimitiveNonNullable(t *testing.T) {
bldr := array.NewInt64Builder(memory.DefaultAllocator)
defer bldr.Release()
bldr.AppendValues([]int64{1, 2, 3, 4}, nil)
arr := bldr.NewArray()
defer arr.Release()
mp, err := newMultipathLevelBuilder(arr, false)
require.NoError(t, err)
defer mp.Release()
ctx := arrowCtxFromContext(NewArrowWriteContext(context.Background(), nil))
result, err := mp.write(0, ctx)
require.NoError(t, err)
assert.Nil(t, result.defLevels)
assert.Nil(t, result.repLevels)
assert.Len(t, result.postListVisitedElems, 1)
assert.EqualValues(t, 0, result.postListVisitedElems[0].start)
assert.EqualValues(t, 4, result.postListVisitedElems[0].end)
}
|