MCPcopy Create free account
hub / github.com/apache/fory / TEST

Function TEST

cpp/fory/row/row_test.cc:32–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30namespace row {
31
32TEST(RowTest, write) {
33 auto f1 = field("f1", utf8());
34 auto f2 = field("f2", int32());
35 auto arr_type = list(int32());
36 auto f3 = field("f3", arr_type);
37 auto map_type = map(utf8(), float32());
38 auto f4 = field("f4", map_type);
39 auto struct_type = std::dynamic_pointer_cast<StructType>(
40 struct_({field("n1", utf8()), field("n2", int32())}));
41 auto f5 = field("f5", struct_type);
42 std::vector<FieldPtr> fields = {f1, f2, f3, f4, f5};
43 auto s = schema(fields);
44
45 RowWriter row_writer(s);
46 row_writer.reset();
47 row_writer.write_string(0, std::string("str"));
48 row_writer.write(1, static_cast<int32_t>(1));
49
50 // array
51 row_writer.set_not_null_at(2);
52 int start = row_writer.cursor();
53 ArrayWriter array_writer(arr_type, &row_writer);
54 array_writer.reset(2);
55 array_writer.write(0, static_cast<int32_t>(2));
56 array_writer.write(1, static_cast<int32_t>(2));
57 EXPECT_EQ(array_writer.copy_to_array_data()->to_string(),
58 std::string("[2, 2]"));
59 row_writer.set_offset_and_size(2, start, row_writer.cursor() - start);
60
61 // map
62 row_writer.set_not_null_at(3);
63 int offset = row_writer.cursor();
64 row_writer.write_directly(-1);
65 ArrayWriter key_array_writer(list(utf8()), &row_writer);
66 key_array_writer.reset(2);
67 key_array_writer.write_string(0, "key1");
68 key_array_writer.write_string(1, "key2");
69 EXPECT_EQ(key_array_writer.copy_to_array_data()->to_string(),
70 std::string("[key1, key2]"));
71 row_writer.write_directly(offset, key_array_writer.size());
72 ArrayWriter value_array_writer(list(float32()), &row_writer);
73 value_array_writer.reset(2);
74 value_array_writer.write(0, 1.0f);
75 value_array_writer.write(1, 1.0f);
76 EXPECT_EQ(value_array_writer.copy_to_array_data()->to_string(),
77 std::string("[1, 1]"));
78 int size = row_writer.cursor() - offset;
79 row_writer.set_offset_and_size(3, offset, size);
80
81 // struct
82 RowWriter struct_writer(schema(struct_type->fields()), &row_writer);
83 row_writer.set_not_null_at(4);
84 offset = row_writer.cursor();
85 struct_writer.reset();
86 struct_writer.write_string(0, "str");
87 struct_writer.write(1, 1);
88 size = row_writer.cursor() - offset;
89 row_writer.set_offset_and_size(4, offset, size);

Callers

nothing calls this directly

Calls 15

utf8Function · 0.85
struct_Function · 0.85
schemaFunction · 0.85
allocate_bufferFunction · 0.85
cursorMethod · 0.80
copy_to_array_dataMethod · 0.80
write_directlyMethod · 0.80
get_stringMethod · 0.80
set_bufferMethod · 0.80
fieldFunction · 0.70
int32Function · 0.70
listFunction · 0.70

Tested by

no test coverage detected