MCPcopy Create free account
hub / github.com/apache/arrow / TestReadSubsetOfFields

Method TestReadSubsetOfFields

cpp/src/arrow/ipc/read_write_test.cc:1558–1624  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1556 }
1557
1558 void TestReadSubsetOfFields() {
1559 // Part of ARROW-7979
1560 auto a0 = ArrayFromJSON(utf8(), "[\"a0\", null]");
1561 auto a1 = ArrayFromJSON(utf8(), "[\"a1\", null]");
1562 auto a2 = ArrayFromJSON(utf8(), "[\"a2\", null]");
1563 auto a3 = ArrayFromJSON(utf8(), "[\"a3\", null]");
1564
1565 auto my_schema = schema({field("a0", utf8()), field("a1", utf8()),
1566 field("a2", utf8()), field("a3", utf8())},
1567 key_value_metadata({"key1"}, {"value1"}));
1568 auto batch = RecordBatch::Make(my_schema, a0->length(), {a0, a1, a2, a3});
1569
1570 IpcReadOptions options = IpcReadOptions::Defaults();
1571
1572 options.included_fields = {1, 3};
1573
1574 {
1575 WriterHelper writer_helper;
1576 RecordBatchVector out_batches;
1577 std::shared_ptr<Schema> out_schema;
1578 ASSERT_OK(RoundTripHelper(writer_helper, {batch}, IpcWriteOptions::Defaults(),
1579 options, &out_batches, &out_schema));
1580
1581 auto ex_schema = schema({field("a1", utf8()), field("a3", utf8())},
1582 key_value_metadata({"key1"}, {"value1"}));
1583 AssertSchemaEqual(*ex_schema, *out_schema);
1584
1585 auto ex_batch = RecordBatch::Make(ex_schema, a0->length(), {a1, a3});
1586 AssertBatchesEqual(*ex_batch, *out_batches[0], /*check_metadata=*/true);
1587 }
1588
1589 // Duplicated or unordered indices are normalized when reading
1590 options.included_fields = {3, 1, 1};
1591
1592 {
1593 WriterHelper writer_helper;
1594 RecordBatchVector out_batches;
1595 std::shared_ptr<Schema> out_schema;
1596 ASSERT_OK(RoundTripHelper(writer_helper, {batch}, IpcWriteOptions::Defaults(),
1597 options, &out_batches, &out_schema));
1598
1599 auto ex_schema = schema({field("a1", utf8()), field("a3", utf8())},
1600 key_value_metadata({"key1"}, {"value1"}));
1601 AssertSchemaEqual(*ex_schema, *out_schema);
1602
1603 auto ex_batch = RecordBatch::Make(ex_schema, a0->length(), {a1, a3});
1604 AssertBatchesEqual(*ex_batch, *out_batches[0], /*check_metadata=*/true);
1605 }
1606
1607 // Out of bounds cases
1608 options.included_fields = {1, 3, 5};
1609 {
1610 WriterHelper writer_helper;
1611 RecordBatchVector out_batches;
1612 ASSERT_RAISES(Invalid,
1613 RoundTripHelper(writer_helper, {batch}, IpcWriteOptions::Defaults(),
1614 options, &out_batches));
1615 }

Callers

nothing calls this directly

Calls 8

ArrayFromJSONFunction · 0.85
key_value_metadataFunction · 0.85
AssertBatchesEqualFunction · 0.85
schemaFunction · 0.70
fieldFunction · 0.50
MakeFunction · 0.50
DefaultsFunction · 0.50
lengthMethod · 0.45

Tested by

no test coverage detected