lbug 0.12.3-dev.9 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/lbug-source/.github/workflows/ci-workflow.yml +9 -2
  2. package/lbug-source/CMakeLists.txt +16 -7
  3. package/lbug-source/Makefile +15 -4
  4. package/lbug-source/benchmark/serializer.py +24 -3
  5. package/lbug-source/dataset/demo-db/csv/copy.cypher +4 -4
  6. package/lbug-source/dataset/demo-db/graph-std/demo_indices_follows.parquet +0 -0
  7. package/lbug-source/dataset/demo-db/graph-std/demo_indices_livesin.parquet +0 -0
  8. package/lbug-source/dataset/demo-db/graph-std/demo_indptr_follows.parquet +0 -0
  9. package/lbug-source/dataset/demo-db/graph-std/demo_indptr_livesin.parquet +0 -0
  10. package/lbug-source/dataset/demo-db/graph-std/demo_mapping_city.parquet +0 -0
  11. package/lbug-source/dataset/demo-db/graph-std/demo_mapping_user.parquet +0 -0
  12. package/lbug-source/dataset/demo-db/graph-std/demo_metadata.parquet +0 -0
  13. package/lbug-source/dataset/demo-db/graph-std/demo_nodes_city.parquet +0 -0
  14. package/lbug-source/dataset/demo-db/graph-std/demo_nodes_user.parquet +0 -0
  15. package/lbug-source/dataset/demo-db/graph-std/schema.cypher +4 -0
  16. package/lbug-source/dataset/demo-db/parquet/copy.cypher +4 -4
  17. package/lbug-source/extension/duckdb/src/catalog/duckdb_catalog.cpp +1 -1
  18. package/lbug-source/extension/duckdb/src/catalog/duckdb_table_catalog_entry.cpp +43 -4
  19. package/lbug-source/extension/duckdb/src/connector/duckdb_result_converter.cpp +6 -0
  20. package/lbug-source/extension/duckdb/src/connector/duckdb_secret_manager.cpp +1 -1
  21. package/lbug-source/extension/duckdb/src/function/duckdb_scan.cpp +49 -4
  22. package/lbug-source/extension/duckdb/src/include/catalog/duckdb_table_catalog_entry.h +6 -1
  23. package/lbug-source/extension/duckdb/src/include/function/duckdb_scan.h +2 -0
  24. package/lbug-source/extension/duckdb/test/test_files/duckdb.test +28 -0
  25. package/lbug-source/extension/extension_config.cmake +3 -2
  26. package/lbug-source/extension/httpfs/test/test_files/http.test +1 -0
  27. package/lbug-source/scripts/antlr4/Cypher.g4 +4 -4
  28. package/lbug-source/scripts/antlr4/hash.md5 +1 -1
  29. package/lbug-source/scripts/generate_binary_demo.sh +1 -1
  30. package/lbug-source/src/antlr4/Cypher.g4 +4 -4
  31. package/lbug-source/src/binder/bind/bind_ddl.cpp +97 -15
  32. package/lbug-source/src/binder/bind/bind_graph_pattern.cpp +30 -3
  33. package/lbug-source/src/catalog/catalog.cpp +6 -4
  34. package/lbug-source/src/catalog/catalog_entry/node_table_catalog_entry.cpp +8 -1
  35. package/lbug-source/src/catalog/catalog_entry/rel_group_catalog_entry.cpp +46 -7
  36. package/lbug-source/src/catalog/catalog_set.cpp +1 -0
  37. package/lbug-source/src/function/function_collection.cpp +2 -1
  38. package/lbug-source/src/function/table/CMakeLists.txt +1 -0
  39. package/lbug-source/src/function/table/disk_size_info.cpp +322 -0
  40. package/lbug-source/src/function/table/show_connection.cpp +6 -1
  41. package/lbug-source/src/function/table/show_tables.cpp +10 -2
  42. package/lbug-source/src/function/table/table_function.cpp +11 -2
  43. package/lbug-source/src/include/binder/ddl/bound_create_table_info.h +23 -6
  44. package/lbug-source/src/include/catalog/catalog_entry/node_table_catalog_entry.h +5 -3
  45. package/lbug-source/src/include/catalog/catalog_entry/rel_group_catalog_entry.h +21 -2
  46. package/lbug-source/src/include/catalog/catalog_entry/table_catalog_entry.h +7 -0
  47. package/lbug-source/src/include/common/constants.h +1 -0
  48. package/lbug-source/src/include/common/string_format.h +2 -2
  49. package/lbug-source/src/include/common/types/types.h +1 -0
  50. package/lbug-source/src/include/function/table/bind_data.h +12 -1
  51. package/lbug-source/src/include/function/table/simple_table_function.h +6 -0
  52. package/lbug-source/src/include/function/table/table_function.h +2 -0
  53. package/lbug-source/src/include/optimizer/count_rel_table_optimizer.h +49 -0
  54. package/lbug-source/src/include/optimizer/logical_operator_visitor.h +6 -0
  55. package/lbug-source/src/include/optimizer/order_by_push_down_optimizer.h +21 -0
  56. package/lbug-source/src/include/parser/ddl/create_table_info.h +3 -1
  57. package/lbug-source/src/include/planner/operator/logical_operator.h +1 -0
  58. package/lbug-source/src/include/planner/operator/logical_table_function_call.h +14 -1
  59. package/lbug-source/src/include/planner/operator/scan/logical_count_rel_table.h +84 -0
  60. package/lbug-source/src/include/processor/operator/physical_operator.h +1 -0
  61. package/lbug-source/src/include/processor/operator/scan/count_rel_table.h +62 -0
  62. package/lbug-source/src/include/processor/operator/scan/scan_node_table.h +2 -2
  63. package/lbug-source/src/include/processor/plan_mapper.h +2 -0
  64. package/lbug-source/src/include/storage/storage_manager.h +1 -0
  65. package/lbug-source/src/include/storage/storage_version_info.h +1 -1
  66. package/lbug-source/src/include/storage/table/foreign_rel_table.h +56 -0
  67. package/lbug-source/src/include/storage/table/node_table.h +6 -1
  68. package/lbug-source/src/include/storage/table/parquet_node_table.h +103 -0
  69. package/lbug-source/src/include/storage/table/parquet_rel_table.h +91 -0
  70. package/lbug-source/src/include/storage/table/rel_table.h +2 -2
  71. package/lbug-source/src/include/transaction/transaction.h +2 -0
  72. package/lbug-source/src/optimizer/CMakeLists.txt +3 -1
  73. package/lbug-source/src/optimizer/count_rel_table_optimizer.cpp +217 -0
  74. package/lbug-source/src/optimizer/limit_push_down_optimizer.cpp +12 -0
  75. package/lbug-source/src/optimizer/logical_operator_visitor.cpp +6 -0
  76. package/lbug-source/src/optimizer/optimizer.cpp +10 -0
  77. package/lbug-source/src/optimizer/order_by_push_down_optimizer.cpp +123 -0
  78. package/lbug-source/src/optimizer/projection_push_down_optimizer.cpp +5 -1
  79. package/lbug-source/src/parser/transform/transform_ddl.cpp +6 -1
  80. package/lbug-source/src/parser/transform/transform_expression.cpp +1 -1
  81. package/lbug-source/src/parser/transform/transform_graph_pattern.cpp +6 -1
  82. package/lbug-source/src/parser/transformer.cpp +7 -1
  83. package/lbug-source/src/planner/join_order/cardinality_estimator.cpp +11 -2
  84. package/lbug-source/src/planner/operator/logical_operator.cpp +2 -0
  85. package/lbug-source/src/planner/operator/logical_table_function_call.cpp +4 -0
  86. package/lbug-source/src/planner/operator/scan/CMakeLists.txt +1 -0
  87. package/lbug-source/src/planner/operator/scan/logical_count_rel_table.cpp +24 -0
  88. package/lbug-source/src/planner/plan/plan_join_order.cpp +16 -1
  89. package/lbug-source/src/processor/map/CMakeLists.txt +1 -0
  90. package/lbug-source/src/processor/map/map_count_rel_table.cpp +55 -0
  91. package/lbug-source/src/processor/map/plan_mapper.cpp +3 -0
  92. package/lbug-source/src/processor/operator/index_lookup.cpp +31 -23
  93. package/lbug-source/src/processor/operator/persistent/reader/parquet/parquet_reader.cpp +4 -0
  94. package/lbug-source/src/processor/operator/physical_operator.cpp +2 -0
  95. package/lbug-source/src/processor/operator/scan/CMakeLists.txt +1 -0
  96. package/lbug-source/src/processor/operator/scan/count_rel_table.cpp +137 -0
  97. package/lbug-source/src/processor/operator/scan/scan_multi_rel_tables.cpp +24 -2
  98. package/lbug-source/src/processor/operator/scan/scan_node_table.cpp +44 -8
  99. package/lbug-source/src/processor/operator/scan/scan_rel_table.cpp +18 -2
  100. package/lbug-source/src/storage/storage_manager.cpp +43 -6
  101. package/lbug-source/src/storage/table/CMakeLists.txt +3 -0
  102. package/lbug-source/src/storage/table/foreign_rel_table.cpp +63 -0
  103. package/lbug-source/src/storage/table/parquet_node_table.cpp +338 -0
  104. package/lbug-source/src/storage/table/parquet_rel_table.cpp +388 -0
  105. package/lbug-source/test/common/string_format.cpp +9 -1
  106. package/lbug-source/test/copy/copy_test.cpp +4 -4
  107. package/lbug-source/test/graph_test/CMakeLists.txt +1 -1
  108. package/lbug-source/test/include/test_runner/test_group.h +11 -1
  109. package/lbug-source/test/optimizer/optimizer_test.cpp +46 -0
  110. package/lbug-source/test/runner/e2e_test.cpp +7 -1
  111. package/lbug-source/test/test_files/demo_db/demo_db_graph_std.test +77 -0
  112. package/lbug-source/test/test_helper/CMakeLists.txt +1 -1
  113. package/lbug-source/test/test_helper/test_helper.cpp +33 -1
  114. package/lbug-source/test/test_runner/CMakeLists.txt +1 -1
  115. package/lbug-source/test/test_runner/insert_by_row.cpp +6 -8
  116. package/lbug-source/test/test_runner/multi_copy_split.cpp +2 -4
  117. package/lbug-source/test/test_runner/test_parser.cpp +3 -0
  118. package/lbug-source/test/transaction/checkpoint_test.cpp +1 -1
  119. package/lbug-source/test/transaction/transaction_test.cpp +19 -15
  120. package/lbug-source/third_party/antlr4_cypher/cypher_parser.cpp +2805 -2708
  121. package/lbug-source/third_party/antlr4_cypher/include/cypher_parser.h +7 -3
  122. package/lbug-source/tools/benchmark/count_rel_table.benchmark +5 -0
  123. package/lbug-source/tools/nodejs_api/package.json +4 -2
  124. package/lbug-source/tools/shell/embedded_shell.cpp +78 -3
  125. package/lbug-source/tools/shell/include/embedded_shell.h +2 -0
  126. package/lbug-source/tools/shell/linenoise.cpp +3 -3
  127. package/lbug-source/tools/shell/test/test_helper.py +1 -1
  128. package/lbug-source/tools/shell/test/test_shell_basics.py +12 -0
  129. package/lbug-source/tools/shell/test/test_shell_commands.py +19 -0
  130. package/package.json +9 -2
  131. package/prebuilt/lbugjs-darwin-arm64.node +0 -0
  132. package/prebuilt/lbugjs-linux-arm64.node +0 -0
  133. package/prebuilt/lbugjs-linux-x64.node +0 -0
  134. package/prebuilt/lbugjs-win32-x64.node +0 -0
@@ -0,0 +1,338 @@
1
+ #include "storage/table/parquet_node_table.h"
2
+
3
+ #include <mutex>
4
+
5
+ #include "catalog/catalog_entry/node_table_catalog_entry.h"
6
+ #include "common/data_chunk/sel_vector.h"
7
+ #include "common/exception/runtime.h"
8
+ #include "common/file_system/virtual_file_system.h"
9
+ #include "common/types/value/value.h"
10
+ #include "main/client_context.h"
11
+ #include "processor/operator/persistent/reader/parquet/parquet_reader.h"
12
+ #include "storage/buffer_manager/memory_manager.h"
13
+ #include "storage/storage_manager.h"
14
+ #include "storage/storage_utils.h"
15
+ #include "storage/table/column.h"
16
+ #include "transaction/transaction.h"
17
+
18
+ using namespace lbug::catalog;
19
+ using namespace lbug::common;
20
+ using namespace lbug::processor;
21
+ using namespace lbug::transaction;
22
+
23
+ namespace lbug {
24
+ namespace storage {
25
+
26
+ ParquetNodeTable::ParquetNodeTable(const StorageManager* storageManager,
27
+ const NodeTableCatalogEntry* nodeTableEntry, MemoryManager* memoryManager)
28
+ : NodeTable{storageManager, nodeTableEntry, memoryManager},
29
+ nodeTableCatalogEntry{nodeTableEntry} {
30
+ std::string prefix = nodeTableEntry->getStorage();
31
+ if (prefix.empty()) {
32
+ throw RuntimeException("Parquet file prefix is empty for parquet-backed node table");
33
+ }
34
+
35
+ // Get the table name for multi-table directory support
36
+ std::string tableName = nodeTableEntry->getName();
37
+
38
+ // For node tables with multi-table support:
39
+ // prefix_nodes_{tableName}.parquet (e.g., demo_nodes_city.parquet)
40
+ parquetFilePath = prefix + "_nodes_" + tableName + ".parquet";
41
+ sharedState = std::make_unique<ParquetNodeTableSharedState>();
42
+ }
43
+
44
+ void ParquetNodeTable::initScanState(Transaction* transaction, TableScanState& scanState,
45
+ [[maybe_unused]] bool resetCachedBoundNodeSelVec) const {
46
+ // Set up the scan state similar to how NodeTable does it
47
+ auto& nodeScanState = scanState.cast<NodeTableScanState>();
48
+ nodeScanState.source = TableScanSource::COMMITTED;
49
+
50
+ // Note: Don't set nodeGroupIdx here - it's set by the morsel-driven parallelism system
51
+
52
+ auto& parquetNodeScanState = static_cast<ParquetNodeTableScanState&>(nodeScanState);
53
+
54
+ // Reset scan state for each scan to allow multiple scans of the same table in one query
55
+ parquetNodeScanState.dataRead = false;
56
+ parquetNodeScanState.allData.clear();
57
+ parquetNodeScanState.totalRows = 0;
58
+ parquetNodeScanState.nextRowToDistribute = 0;
59
+
60
+ // Reset scan completion flag for this scan state
61
+ parquetNodeScanState.scanCompleted = false;
62
+
63
+ // Each scan state gets its own parquet reader for thread safety
64
+ if (!parquetNodeScanState.initialized) {
65
+ auto context = transaction->getClientContext();
66
+ if (!context) {
67
+ throw RuntimeException("Invalid client context for parquet scan state initialization");
68
+ }
69
+
70
+ std::vector<bool> columnSkips;
71
+ try {
72
+ parquetNodeScanState.parquetReader =
73
+ std::make_unique<ParquetReader>(parquetFilePath, columnSkips, context);
74
+ parquetNodeScanState.initialized = true;
75
+ } catch (const std::exception& e) {
76
+ throw RuntimeException("Failed to initialize parquet reader for file '" +
77
+ parquetFilePath + "': " + e.what());
78
+ }
79
+ }
80
+
81
+ // Set nodeGroupIdx to invalid initially - will be assigned by getNextRowGroup
82
+ parquetNodeScanState.nodeGroupIdx = INVALID_NODE_GROUP_IDX;
83
+
84
+ // Initialize scan state for the current row group (assigned via shared state)
85
+ initParquetScanForRowGroup(transaction, parquetNodeScanState);
86
+ }
87
+
88
+ void ParquetNodeTable::initializeScanCoordination(const Transaction* transaction) {
89
+ // Reset shared state at the start of each scan operation
90
+ // This is called once per scan operation by the ScanNodeTable operator
91
+ // Create a temporary reader to get the number of row groups
92
+ auto context = transaction->getClientContext();
93
+ if (!context) {
94
+ return;
95
+ }
96
+
97
+ std::vector<bool> columnSkips;
98
+ try {
99
+ auto tempReader = std::make_unique<ParquetReader>(parquetFilePath, columnSkips, context);
100
+ auto numRowGroups = tempReader->getNumRowsGroups();
101
+ sharedState->reset(numRowGroups);
102
+ } catch (const std::exception& e) {
103
+ // If we can't read the file, set to 1 row group as fallback
104
+ sharedState->reset(1);
105
+ }
106
+ }
107
+
108
+ void ParquetNodeTable::initParquetScanForRowGroup(Transaction* transaction,
109
+ ParquetNodeTableScanState& scanState) const {
110
+ auto context = transaction->getClientContext();
111
+ if (!context) {
112
+ return;
113
+ }
114
+
115
+ auto vfs = VirtualFileSystem::GetUnsafe(*context);
116
+ if (!vfs) {
117
+ return;
118
+ }
119
+
120
+ // Defensive check: ensure parquet reader exists
121
+ if (!scanState.parquetReader) {
122
+ return;
123
+ }
124
+
125
+ // Defensive check: ensure parquet scan state exists
126
+ if (!scanState.parquetScanState) {
127
+ return;
128
+ }
129
+
130
+ std::vector<uint64_t> groupsToRead;
131
+
132
+ // Use shared state to get the next available row group for this scan state
133
+ if (scanState.nodeGroupIdx == INVALID_NODE_GROUP_IDX) {
134
+ common::node_group_idx_t assignedRowGroup;
135
+ if (sharedState->getNextRowGroup(assignedRowGroup)) {
136
+ scanState.nodeGroupIdx = assignedRowGroup;
137
+ groupsToRead.push_back(assignedRowGroup);
138
+ } else {
139
+ // No more row groups available - mark scan as completed
140
+ scanState.scanCompleted = true;
141
+ // Still need to initialize the scan state with empty groups so reader is in valid state
142
+ scanState.parquetReader->initializeScan(*scanState.parquetScanState, groupsToRead, vfs);
143
+ return;
144
+ }
145
+ } else {
146
+ // Row group already assigned (e.g., by external morsel system or re-initialization)
147
+ groupsToRead.push_back(scanState.nodeGroupIdx);
148
+ }
149
+
150
+ // Re-initialize scan for the specific row groups
151
+ // Note: initializeScan can be called multiple times; the first call populates column metadata
152
+ scanState.parquetReader->initializeScan(*scanState.parquetScanState, groupsToRead, vfs);
153
+ }
154
+
155
+ bool ParquetNodeTable::scanInternal(Transaction* transaction, TableScanState& scanState) {
156
+ auto& parquetScanState = static_cast<ParquetNodeTableScanState&>(scanState);
157
+
158
+ // Check if this particular scan state has already completed
159
+ if (parquetScanState.scanCompleted) {
160
+ return false;
161
+ }
162
+
163
+ scanState.resetOutVectors();
164
+
165
+ // Read all data once into scan state
166
+ if (!parquetScanState.dataRead) {
167
+ // Only the first thread reads the parquet data
168
+ if (!parquetScanState.initialized) {
169
+ return false;
170
+ }
171
+
172
+ // Create a data chunk for reading parquet data
173
+ auto numColumns = parquetScanState.parquetReader->getNumColumns();
174
+
175
+ // Defensive check: ensure parquet file has at least one column
176
+ if (numColumns == 0) {
177
+ throw RuntimeException("Parquet file '" + parquetFilePath + "' has no columns");
178
+ }
179
+
180
+ DataChunk parquetDataChunk(numColumns, scanState.outState);
181
+
182
+ // Create vectors with parquet types
183
+ // Defensive check: ensure parquet file has enough columns for what we expect
184
+ // Always create the data chunk to match the exact number of parquet columns
185
+ // to prevent crashes in the parquet reader when accessing result vectors
186
+ for (uint32_t i = 0; i < numColumns; ++i) {
187
+ const auto& parquetColumnType = parquetScanState.parquetReader->getColumnType(i);
188
+ auto columnType = parquetColumnType.copy();
189
+ auto vector = std::make_shared<ValueVector>(std::move(columnType),
190
+ MemoryManager::Get(*transaction->getClientContext()), scanState.outState);
191
+ parquetDataChunk.insert(i, vector);
192
+ }
193
+
194
+ // Read from parquet
195
+ parquetScanState.parquetReader->scan(*parquetScanState.parquetScanState, parquetDataChunk);
196
+
197
+ auto selSize = parquetDataChunk.state->getSelVector().getSelSize();
198
+ if (selSize > 0) {
199
+ parquetScanState.allData.resize(selSize);
200
+ for (size_t row = 0; row < selSize; ++row) {
201
+ parquetScanState.allData[row].resize(
202
+ scanState.outputVectors
203
+ .size()); // Use output vector count, not parquet column count
204
+
205
+ // Map parquet columns to correct output vector positions by name
206
+ // Defensive check: ensure we don't access more columns than available in the chunk
207
+ auto maxParquetCol = std::min(static_cast<size_t>(numColumns),
208
+ static_cast<size_t>(parquetDataChunk.getNumValueVectors()));
209
+
210
+ for (size_t parquetCol = 0; parquetCol < maxParquetCol; ++parquetCol) {
211
+ // Defensive check: ensure the column index is valid for the data chunk
212
+ if (parquetCol >= parquetDataChunk.getNumValueVectors()) {
213
+ continue;
214
+ }
215
+
216
+ auto& srcVector = parquetDataChunk.getValueVectorMutable(parquetCol);
217
+
218
+ // Get parquet column name and find its corresponding column ID
219
+ std::string parquetColumnName =
220
+ parquetScanState.parquetReader->getColumnName(parquetCol);
221
+ auto nodeTableEntry = this->nodeTableCatalogEntry;
222
+
223
+ // Check if the column exists first before calling getColumnID
224
+ if (!nodeTableEntry->containsProperty(parquetColumnName)) {
225
+ // Column doesn't exist in table schema, skip it
226
+ continue;
227
+ }
228
+
229
+ // Find the column ID for this property name
230
+ column_id_t parquetColumnID = nodeTableEntry->getColumnID(parquetColumnName);
231
+
232
+ // Find which output vector position corresponds to this column ID
233
+ size_t outputCol = INVALID_COLUMN_ID;
234
+ for (size_t outCol = 0; outCol < scanState.columnIDs.size(); ++outCol) {
235
+ if (scanState.columnIDs[outCol] == parquetColumnID) {
236
+ outputCol = outCol;
237
+ break;
238
+ }
239
+ }
240
+
241
+ // Only copy data if we found a matching output position
242
+ if (outputCol != INVALID_COLUMN_ID &&
243
+ outputCol < parquetScanState.allData[row].size()) {
244
+ // Defensive check: ensure the row index is valid for the source vector
245
+ if (row >= srcVector.state->getSelVector().getSelSize()) {
246
+ continue;
247
+ }
248
+
249
+ if (srcVector.isNull(row)) {
250
+ parquetScanState.allData[row][outputCol] =
251
+ std::make_unique<Value>(Value::createNullValue());
252
+ } else {
253
+ parquetScanState.allData[row][outputCol] =
254
+ std::make_unique<Value>(*srcVector.getAsValue(row));
255
+ }
256
+ }
257
+ }
258
+ }
259
+ parquetScanState.totalRows = selSize;
260
+ }
261
+ parquetScanState.dataRead = true;
262
+ }
263
+
264
+ // Now distribute one row to this scan state
265
+ if (parquetScanState.nextRowToDistribute >= parquetScanState.totalRows) {
266
+ parquetScanState.scanCompleted = true;
267
+ return false; // No more rows to distribute
268
+ }
269
+
270
+ size_t rowIndex = parquetScanState.nextRowToDistribute++;
271
+
272
+ // Copy one row to output vectors
273
+ // Defensive checks: ensure valid row index and handle empty data gracefully
274
+ if (rowIndex >= parquetScanState.allData.size()) {
275
+ parquetScanState.scanCompleted = true;
276
+ return false;
277
+ }
278
+
279
+ auto numColumns =
280
+ std::min(scanState.outputVectors.size(), parquetScanState.allData[rowIndex].size());
281
+ for (size_t col = 0; col < numColumns; ++col) {
282
+ // Defensive check: ensure output vector exists
283
+ if (col >= scanState.outputVectors.size() || !scanState.outputVectors[col]) {
284
+ continue;
285
+ }
286
+
287
+ auto& dstVector = *scanState.outputVectors[col];
288
+
289
+ // Defensive check: ensure value exists for this column
290
+ if (col >= parquetScanState.allData[rowIndex].size() ||
291
+ !parquetScanState.allData[rowIndex][col]) {
292
+ dstVector.setNull(0, true);
293
+ continue;
294
+ }
295
+
296
+ auto& value = *parquetScanState.allData[rowIndex][col];
297
+
298
+ if (value.isNull()) {
299
+ dstVector.setNull(0, true);
300
+ } else {
301
+ dstVector.copyFromValue(0, value);
302
+ }
303
+ }
304
+
305
+ // Set node ID for this row
306
+ auto tableID = this->getTableID();
307
+ auto& nodeID = scanState.nodeIDVector->getValue<nodeID_t>(0);
308
+ nodeID.tableID = tableID;
309
+ nodeID.offset = rowIndex; // Use the actual row index from parquet
310
+
311
+ scanState.outState->getSelVectorUnsafe().setSelSize(1); // Return exactly one row
312
+ return true;
313
+ }
314
+
315
+ row_idx_t ParquetNodeTable::getNumTotalRows(const transaction::Transaction* transaction) {
316
+ // Create a temporary reader to get metadata
317
+ auto context = transaction->getClientContext();
318
+ if (!context) {
319
+ return 0;
320
+ }
321
+
322
+ std::vector<bool> columnSkips;
323
+
324
+ try {
325
+ auto tempReader = std::make_unique<ParquetReader>(parquetFilePath, columnSkips, context);
326
+ if (!tempReader) {
327
+ return 0;
328
+ }
329
+ auto metadata = tempReader->getMetadata();
330
+ return metadata ? metadata->num_rows : 0;
331
+ } catch (const std::exception& e) {
332
+ // If parquet file is corrupted or invalid, return 0 instead of crashing
333
+ return 0;
334
+ }
335
+ }
336
+
337
+ } // namespace storage
338
+ } // namespace lbug