| 46 | } |
| 47 | |
| 48 | void flattenColumns( |
| 49 | const TypeTreeNode& node, std::string_view prefix, FieldId& next_id, std::vector<ColumnDescriptor>& out) { |
| 50 | const std::string path = prefix.empty() ? node.name : std::string(prefix) + "." + node.name; |
| 51 | |
| 52 | if (node.kind == TypeKind::kStruct) { |
| 53 | for (const auto& child : node.children) { |
| 54 | flattenColumns(*child, path, next_id, out); |
| 55 | } |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | if (node.kind == TypeKind::kArray) { |
| 60 | if (!node.element_type || !node.fixed_array_size.has_value()) { |
| 61 | return; |
| 62 | } |
| 63 | for (uint32_t i = 0; i < *node.fixed_array_size; ++i) { |
| 64 | const std::string element_path = path + "[" + std::to_string(i) + "]"; |
| 65 | if (node.element_type->kind == TypeKind::kStruct) { |
| 66 | for (const auto& child : node.element_type->children) { |
| 67 | flattenColumns(*child, element_path, next_id, out); |
| 68 | } |
| 69 | } else { |
| 70 | out.push_back( |
| 71 | ColumnDescriptor{ |
| 72 | .field_id = next_id++, |
| 73 | .logical_type = node.element_type->primitive_type.value_or(PrimitiveType::kFloat64), |
| 74 | .field_path = element_path, |
| 75 | }); |
| 76 | } |
| 77 | } |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | out.push_back( |
| 82 | ColumnDescriptor{ |
| 83 | .field_id = next_id++, |
| 84 | .logical_type = node.primitive_type.value_or(PrimitiveType::kFloat64), |
| 85 | .field_path = path, |
| 86 | }); |
| 87 | } |
| 88 | |
| 89 | [[nodiscard]] std::vector<ColumnDescriptor> columnsForTopic(const DataEngine& engine, const TopicStorage& storage) { |
| 90 | if (!storage.columnDescriptors().empty()) { |
no test coverage detected