@@ -108,6 +108,36 @@ Status CloudTablet::capture_rs_readers(const Version& spec_version,
108
108
return capture_rs_readers_unlocked (version_path, rs_splits);
109
109
}
110
110
111
+ Status CloudTablet::merge_rowsets_schema () {
112
+ // Find the rowset with the max version
113
+ auto max_version_rowset =
114
+ std::max_element (
115
+ _rs_version_map.begin (), _rs_version_map.end (),
116
+ [](const auto & a, const auto & b) {
117
+ return !a.second ->tablet_schema ()
118
+ ? true
119
+ : (!b.second ->tablet_schema ()
120
+ ? false
121
+ : a.second ->tablet_schema ()->schema_version () <
122
+ b.second ->tablet_schema ()
123
+ ->schema_version ());
124
+ })
125
+ ->second ;
126
+ TabletSchemaSPtr max_version_schema = max_version_rowset->tablet_schema ();
127
+ // If the schema has variant columns, perform a merge to create a wide tablet schema
128
+ if (max_version_schema->num_variant_columns () > 0 ) {
129
+ std::vector<TabletSchemaSPtr> schemas;
130
+ std::transform (_rs_version_map.begin (), _rs_version_map.end (), std::back_inserter (schemas),
131
+ [](const auto & rs_meta) { return rs_meta.second ->tablet_schema (); });
132
+ // Merge the collected schemas to obtain the least common schema
133
+ RETURN_IF_ERROR (vectorized::schema_util::get_least_common_schema (schemas, nullptr ,
134
+ max_version_schema));
135
+ VLOG_DEBUG << " dump schema: " << max_version_schema->dump_full_schema ();
136
+ _merged_tablet_schema = max_version_schema;
137
+ }
138
+ return Status::OK ();
139
+ }
140
+
111
141
// There are only two tablet_states RUNNING and NOT_READY in cloud mode
112
142
// This function will erase the tablet from `CloudTabletMgr` when it can't find this tablet in MS.
113
143
Status CloudTablet::sync_rowsets (int64_t query_version, bool warmup_delta_data) {
@@ -133,6 +163,10 @@ Status CloudTablet::sync_rowsets(int64_t query_version, bool warmup_delta_data)
133
163
if (st.is <ErrorCode::NOT_FOUND>()) {
134
164
clear_cache ();
135
165
}
166
+
167
+ // Merge all rowset schemas within a CloudTablet
168
+ RETURN_IF_ERROR (merge_rowsets_schema ());
169
+
136
170
return st;
137
171
}
138
172
@@ -188,16 +222,7 @@ Status CloudTablet::sync_if_not_running() {
188
222
}
189
223
190
224
TabletSchemaSPtr CloudTablet::merged_tablet_schema () const {
191
- std::shared_lock rdlock (_meta_lock);
192
- TabletSchemaSPtr target_schema;
193
- std::vector<TabletSchemaSPtr> schemas;
194
- for (const auto & [_, rowset] : _rs_version_map) {
195
- schemas.push_back (rowset->tablet_schema ());
196
- }
197
- // get the max version schema and merge all schema
198
- static_cast <void >(
199
- vectorized::schema_util::get_least_common_schema (schemas, nullptr , target_schema));
200
- return target_schema;
225
+ return _merged_tablet_schema;
201
226
}
202
227
203
228
void CloudTablet::add_rowsets (std::vector<RowsetSharedPtr> to_add, bool version_overlap,
0 commit comments