| 50 | } // namespace |
| 51 | |
| 52 | int main() { |
| 53 | const int num_rows = 8; |
| 54 | memory::MemoryManager::initialize(memory::MemoryManager::Options{}); |
| 55 | |
| 56 | /****************** Vector Writer **********************/ |
| 57 | |
| 58 | // Define rows to write |
| 59 | SelectivityVector rows{num_rows}; |
| 60 | // Array<Map<int,int>> |
| 61 | auto type = TypeFactory<TypeKind::ARRAY>::create( |
| 62 | TypeFactory<TypeKind::MAP>::create(BIGINT(), BIGINT())); |
| 63 | auto pool = memory::memoryManager()->addLeafPool(); |
| 64 | |
| 65 | // result vector |
| 66 | VectorPtr result; |
| 67 | |
| 68 | // 1. Make sure result is writable for rows of interest |
| 69 | BaseVector::ensureWritable(rows, type, pool.get(), result); |
| 70 | |
| 71 | // 2. Define a vector writer VectorWriter<T> where T is the type expressed in |
| 72 | // the simple function type system. |
| 73 | exec::VectorWriter<Array<Map<int64_t, int64_t>>> vectorWriter; |
| 74 | |
| 75 | // 3. Initialize the writer to write to result vector. |
| 76 | vectorWriter.init(*result->as<ArrayVector>()); |
| 77 | |
| 78 | rows.applyToSelected([&](vector_size_t row) { |
| 79 | // 4. To write to a specific row call setOffset(row) followed by current() |
| 80 | // to get the writer at that row |
| 81 | vectorWriter.setOffset(row); |
| 82 | auto& arrayWriter = vectorWriter.current(); |
| 83 | |
| 84 | // Insert a map element to the array |
| 85 | auto& child = arrayWriter.add_item(); |
| 86 | |
| 87 | // Insert 2 kv pairs to the map |
| 88 | child.emplace(serial(), serial()); |
| 89 | child.emplace(serial(), serial()); |
| 90 | |
| 91 | // Insert an empty map |
| 92 | arrayWriter.add_item(); |
| 93 | |
| 94 | // 5. After finishing writing the row call commit(), or commit(false) to |
| 95 | // write a null |
| 96 | vectorWriter.commit(); |
| 97 | }); |
| 98 | |
| 99 | // 6. After finishing writing all rows, call finish() |
| 100 | vectorWriter.finish(); |
| 101 | |
| 102 | /****************** Vector Reader **********************/ |
| 103 | |
| 104 | // 1. Decode the vector for rows of interest. |
| 105 | DecodedVector decoded; |
| 106 | decoded.decode(*result, rows); |
| 107 | |
| 108 | // 2. Define vectorReader<T> where T is the type of the vector being read, T |
| 109 | // is expressed in the simple function type system |
nothing calls this directly
no test coverage detected