| 70 | }; |
| 71 | |
| 72 | void QueryPlan::serializeSets(SerializedSetsRegistry & registry, WriteBuffer & out, const SerializationFlags & flags) |
| 73 | { |
| 74 | writeVarUInt(registry.sets.size(), out); |
| 75 | for (const auto & [hash, set] : registry.sets) |
| 76 | { |
| 77 | writeBinary(hash, out); |
| 78 | |
| 79 | if (auto * from_storage = typeid_cast<FutureSetFromStorage *>(set.get())) |
| 80 | { |
| 81 | writeIntBinary(SetSerializationKind::StorageSet, out); |
| 82 | const auto & storage_id = from_storage->getStorageID(); |
| 83 | if (!storage_id) |
| 84 | throw Exception(ErrorCodes::LOGICAL_ERROR, "FutureSetFromStorage without storage id"); |
| 85 | |
| 86 | auto storage_name = storage_id->getFullTableName(); |
| 87 | writeStringBinary(storage_name, out); |
| 88 | } |
| 89 | else if (auto * from_tuple = typeid_cast<FutureSetFromTuple *>(set.get())) |
| 90 | { |
| 91 | writeIntBinary(SetSerializationKind::TupleValues, out); |
| 92 | |
| 93 | auto types = from_tuple->getTypes(); |
| 94 | auto columns = from_tuple->getKeyColumns(); |
| 95 | |
| 96 | if (columns.size() != types.size()) |
| 97 | throw Exception(ErrorCodes::LOGICAL_ERROR, |
| 98 | "Invalid number of columns for Set. Expected {} got {}", |
| 99 | columns.size(), types.size()); |
| 100 | |
| 101 | UInt64 num_columns = columns.size(); |
| 102 | UInt64 num_rows = num_columns > 0 ? columns.front()->size() : 0; |
| 103 | |
| 104 | writeVarUInt(num_columns, out); |
| 105 | writeVarUInt(num_rows, out); |
| 106 | |
| 107 | for (size_t col = 0; col < num_columns; ++col) |
| 108 | { |
| 109 | if (columns[col]->size() != num_rows) |
| 110 | throw Exception(ErrorCodes::LOGICAL_ERROR, |
| 111 | "Invalid number of rows in column of Set. Expected {} got {}", |
| 112 | num_rows, columns[col]->size()); |
| 113 | |
| 114 | encodeDataType(types[col], out); |
| 115 | auto serialization = types[col]->getDefaultSerialization(); |
| 116 | NativeWriter::writeData(*serialization, columns[col], out, {}, 0, 0, 0); |
| 117 | } |
| 118 | } |
| 119 | else if (auto * from_subquery = typeid_cast<FutureSetFromSubquery *>(set.get())) |
| 120 | { |
| 121 | writeIntBinary(SetSerializationKind::SubqueryPlan, out); |
| 122 | const auto * plan = from_subquery->getQueryPlan(); |
| 123 | if (!plan) |
| 124 | throw Exception(ErrorCodes::LOGICAL_ERROR, "Cannot serialize FutureSetFromSubquery with no query plan"); |
| 125 | |
| 126 | plan->serialize(out, flags); |
| 127 | } |
| 128 | else |
| 129 | { |
nothing calls this directly
no test coverage detected