19 #include <boost/archive/text_iarchive.hpp>
20 #include <boost/archive/text_oarchive.hpp>
21 #include <boost/serialization/access.hpp>
22 #include <boost/serialization/shared_ptr.hpp>
23 #include <boost/serialization/unique_ptr.hpp>
24 #include <boost/serialization/unordered_map.hpp>
25 #include <boost/serialization/variant.hpp>
26 #include <boost/serialization/vector.hpp>
51 #define REL_ALG_NODE_DERIVED_CLASSES \
52 RelScan, RelProject, RelAggregate, RelJoin, RelFilter, RelLeftDeepInnerJoin, \
53 RelCompound, RelSort, RelModify, RelTableFunction, RelLogicalValues, \
56 #define REX_DERIVED_CLASSES \
57 RexAbstractInput, RexLiteral, RexOperator, RexSubQuery, RexInput, RexCase, \
58 RexFunctionOperator, RexWindowFunctionOperator, RexRef, RexAgg
65 template <
class T,
class... Ts>
67 : std::bool_constant<(std::is_same_v<T, typename std::remove_cv_t<Ts>> || ...)> {};
94 : std::bool_constant<is_rel_alg_node_class_v<T> || is_rex_class_v<T> ||
95 std::is_same_v<T, RelAlgDag>> {};
121 typename std::enable_if_t<is_rex_class_v<RexClass>>* =
nullptr>
123 if constexpr (std::is_same_v<Rex, RexClass>) {
125 }
else if constexpr (std::is_same_v<RexScalar, RexClass>) {
126 (ar & boost::serialization::base_object<Rex>(obj));
127 }
else if constexpr (std::is_same_v<RexAbstractInput, RexClass>) {
128 (ar & boost::serialization::base_object<RexScalar>(obj));
129 (ar & obj.in_index_);
130 }
else if constexpr (std::is_same_v<RexLiteral, RexClass>) {
131 (ar & boost::serialization::base_object<RexScalar>(obj));
134 (ar & obj.target_type_);
136 (ar & obj.precision_);
137 (ar & obj.target_scale_);
138 (ar & obj.target_precision_);
139 }
else if constexpr (std::is_same_v<RexOperator, RexClass>) {
140 (ar & boost::serialization::base_object<RexScalar>(obj));
142 (ar & obj.operands_);
144 }
else if constexpr (std::is_same_v<RexSubQuery, RexClass>) {
145 (ar & boost::serialization::base_object<RexScalar>(obj));
152 CHECK(*obj.result_ ==
nullptr);
163 }
else if constexpr (std::is_same_v<RexInput, RexClass>) {
164 (ar & boost::serialization::base_object<RexAbstractInput>(obj));
166 }
else if constexpr (std::is_same_v<RexCase, RexClass>) {
167 (ar & boost::serialization::base_object<RexScalar>(obj));
168 (ar & obj.expr_pair_list_);
169 (ar & obj.else_expr_);
170 }
else if constexpr (std::is_same_v<RexFunctionOperator, RexClass>) {
171 (ar & boost::serialization::base_object<RexOperator>(obj));
173 }
else if constexpr (std::is_same_v<RexWindowFunctionOperator, RexClass>) {
174 (ar & boost::serialization::base_object<RexFunctionOperator>(obj));
176 (ar & obj.partition_keys_);
177 (ar & obj.order_keys_);
178 (ar & obj.collation_);
179 (ar & obj.frame_start_bound_);
180 (ar & obj.frame_end_bound_);
182 }
else if constexpr (std::is_same_v<RexRef, RexClass>) {
183 (ar & boost::serialization::base_object<RexScalar>(obj));
185 }
else if constexpr (std::is_same_v<RexAgg, RexClass>) {
186 (ar & boost::serialization::base_object<Rex>(obj));
188 (ar & obj.distinct_);
190 (ar & obj.operands_);
192 static_assert(!
sizeof(RexClass),
"Unhandled Rex class during serialization.");
205 template <
class Archive,
class... RelAlgNodeClasses>
207 (ar.template register_type<RelAlgNodeClasses>(), ...);
220 typename std::enable_if_t<is_rel_alg_node_class_v<RelAlgClass>>* =
nullptr>
222 if constexpr (std::is_same_v<RelAlgNode, RelAlgClass>) {
232 }
else if constexpr (std::is_same_v<RelScan, RelAlgClass>) {
233 (ar & boost::serialization::base_object<RelAlgNode>(obj));
239 (ar & obj.field_names_);
240 (ar & obj.hint_applied_);
242 }
else if constexpr (std::is_same_v<ModifyManipulationTarget, RelAlgClass>) {
243 (ar & obj.is_update_via_select_);
244 (ar & obj.is_delete_via_select_);
245 (ar & obj.varlen_update_required_);
246 (ar & obj.target_columns_);
247 (ar & obj.force_rowwise_output_);
253 }
else if constexpr (std::is_same_v<RelProject, RelAlgClass>) {
254 (ar & boost::serialization::base_object<RelAlgNode>(obj));
255 (ar & boost::serialization::base_object<ModifyManipulationTarget>(obj));
256 (ar & obj.scalar_exprs_);
258 (ar & obj.hint_applied_);
260 (ar & obj.has_pushed_down_window_expr_);
261 }
else if constexpr (std::is_same_v<RelAggregate, RelAlgClass>) {
262 (ar & boost::serialization::base_object<RelAlgNode>(obj));
263 (ar & obj.groupby_count_);
264 (ar & obj.agg_exprs_);
266 (ar & obj.hint_applied_);
268 }
else if constexpr (std::is_same_v<RelJoin, RelAlgClass>) {
269 (ar & boost::serialization::base_object<RelAlgNode>(obj));
270 (ar & obj.condition_);
271 (ar & obj.join_type_);
272 (ar & obj.hint_applied_);
274 }
else if constexpr (std::is_same_v<RelFilter, RelAlgClass>) {
275 (ar & boost::serialization::base_object<RelAlgNode>(obj));
277 }
else if constexpr (std::is_same_v<RelLeftDeepInnerJoin, RelAlgClass>) {
278 (ar & boost::serialization::base_object<RelAlgNode>(obj));
279 (ar & obj.condition_);
280 (ar & obj.outer_conditions_per_level_);
281 (ar & obj.original_filter_);
282 (ar & obj.original_joins_);
283 }
else if constexpr (std::is_same_v<RelCompound, RelAlgClass>) {
284 (ar & boost::serialization::base_object<RelAlgNode>(obj));
285 (ar & boost::serialization::base_object<ModifyManipulationTarget>(obj));
287 (ar & obj.filter_expr_);
288 (ar & obj.groupby_count_);
289 (ar & obj.agg_exprs_);
292 (ar & obj.scalar_sources_);
293 (ar & obj.target_exprs_);
294 (ar & obj.hint_applied_);
296 }
else if constexpr (std::is_same_v<RelSort, RelAlgClass>) {
297 (ar & boost::serialization::base_object<RelAlgNode>(obj));
298 (ar & obj.collation_);
301 }
else if constexpr (std::is_same_v<RelModify, RelAlgClass>) {
302 (ar & boost::serialization::base_object<RelAlgNode>(obj));
307 (ar & obj.flattened_);
308 (ar & obj.operation_);
309 (ar & obj.target_column_list_);
310 }
else if constexpr (std::is_same_v<RelTableFunction, RelAlgClass>) {
311 (ar & boost::serialization::base_object<RelAlgNode>(obj));
312 (ar & obj.function_name_);
314 (ar & obj.col_inputs_);
315 (ar & obj.table_func_inputs_);
316 (ar & obj.target_exprs_);
317 }
else if constexpr (std::is_same_v<RelLogicalValues, RelAlgClass>) {
318 (ar & boost::serialization::base_object<RelAlgNode>(obj));
319 (ar & obj.tuple_type_);
321 }
else if constexpr (std::is_same_v<RelLogicalUnion, RelAlgClass>) {
322 (ar & boost::serialization::base_object<RelAlgNode>(obj));
325 static_assert(!
sizeof(RelAlgClass),
326 "Unhandled RelAlgNode class during serialization");
333 template <
class Archive>
338 registerClassesWithArchive<Archive, REL_ALG_NODE_DERIVED_CLASSES>(ar);
339 registerClassesWithArchive<Archive, REX_DERIVED_CLASSES>(ar);
348 (ar & rel_alg_dag.
nodes_);
356 namespace serialization {
369 typename std::enable_if_t<all_serializable_rel_alg_classes_v<RelAlgType>>* =
nullptr>
378 typename std::enable_if_t<all_serializable_rel_alg_classes_v<RelAlgType>>* =
nullptr>
388 template <
class Archive>
403 : std::bool_constant<std::is_same_v<RelScan, typename std::remove_cv_t<T>> ||
404 std::is_same_v<RelProject, typename std::remove_cv_t<T>> ||
405 std::is_same_v<RelCompound, typename std::remove_cv_t<T>> ||
406 std::is_same_v<RelModify, typename std::remove_cv_t<T>>> {};
413 : std::bool_constant<std::is_same_v<RelProject, typename std::remove_cv_t<T>> ||
414 std::is_same_v<RelCompound, typename std::remove_cv_t<T>>> {};
431 template <
class RelAlgNodeType,
432 typename std::enable_if_t<is_catalog_rel_alg_node_v<RelAlgNodeType>>* =
nullptr>
434 const RelAlgNodeType* node,
437 if constexpr (is_modify_target_rel_alg_node_v<RelAlgNodeType>) {
438 catalog = node->getModifiedTableCatalog();
440 catalog = &node->getCatalog();
444 ar << catalog->
name();
449 auto* td = node->getTableDescriptor();
451 CHECK(!td->tableName.empty());
466 template <
class RelAlgNodeType>
470 ::new (node) RelAlgNodeType(td, cat);
502 class RelAlgNodeType,
503 typename std::enable_if_t<is_catalog_rel_alg_node<RelAlgNodeType>::value>* =
nullptr>
505 RelAlgNodeType* node,
511 if (!db_name.empty()) {
513 CHECK(
cat) <<
"Catalog not found for database: " << db_name;
516 std::string table_name;
518 if (!table_name.empty()) {
520 td =
cat->getMetadataForTable(table_name,
false);
521 CHECK(td) <<
"Table metadata not found for table: " << table_name
522 <<
" in catalog: " <<
cat->name();
525 if constexpr (is_modify_target_rel_alg_node_v<RelAlgNodeType>) {
constexpr bool is_catalog_rel_alg_node_v
std::unordered_map< size_t, std::unordered_map< unsigned, RegisteredQueryHint > > query_hint_
class for a per-database catalog. also includes metadata for the current database and the current use...
static void serialize(Archive &ar, RexClass &obj, const unsigned int version)
std::vector< std::shared_ptr< RelAlgNode > > nodes_
constexpr bool is_rel_alg_node_class_v
constexpr bool is_rex_class_v
static SysCatalog & instance()
std::vector< std::shared_ptr< RexSubQuery > > subqueries_
constexpr bool all_serializable_rel_alg_classes_v
std::shared_ptr< Catalog > getCatalog(const std::string &dbName)
void serialize(Archive &ar, RegisteredQueryHint &query_hint, const unsigned int version)
void construct_catalog_rel_alg_node(RelAlgNodeType *node, const Catalog_Namespace::Catalog *cat, const TableDescriptor *td)
static void registerClassesWithArchive(Archive &ar)
constexpr bool is_modify_target_rel_alg_node_v
static void serialize(Archive &ar, RelAlgClass &obj, const unsigned int version)
RegisteredQueryHint global_hints_
static void serialize(Archive &ar, RelAlgDag &rel_alg_dag, const unsigned int version)
void save_construct_data(Archive &ar, const ExplainedQueryHint *query_hint, const unsigned int version)
void load_construct_data(Archive &ar, ExplainedQueryHint *query_hint, const unsigned int version)