OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RelAlgDagSerializer Struct Reference

#include <RelAlgDagSerializer.h>

Static Public Member Functions

template<class Archive , class RexClass , typename std::enable_if_t< is_rex_class_v< RexClass >> * = nullptr>
static void serialize (Archive &ar, RexClass &obj, const unsigned int version)
 
template<class Archive , class... RelAlgNodeClasses>
static void registerClassesWithArchive (Archive &ar)
 
template<class Archive , class RelAlgClass , typename std::enable_if_t< is_rel_alg_node_class_v< RelAlgClass >> * = nullptr>
static void serialize (Archive &ar, RelAlgClass &obj, const unsigned int version)
 
template<class Archive >
static void serialize (Archive &ar, RelAlgDag &rel_alg_dag, const unsigned int version)
 

Detailed Description

Primary struct for serializing the RelAlgNode/Rex/RexScalar nodes in a RelAlgDag instance. All RelAlgDag-related classes/structs that don't have public getter/setter interfaces for serialization-dependent members need to friend this struct for private access and provide a serialization specialization below.

Definition at line 109 of file RelAlgDagSerializer.h.

Member Function Documentation

template<class Archive , class... RelAlgNodeClasses>
static void RelAlgDagSerializer::registerClassesWithArchive ( Archive ar)
inlinestatic

Utility method that registers polymorphic-derived classes with the boost archive. Registration is needed to ensure derived classes referenced via polymorphic pointer get properly designated for serialization. See: https://www.boost.org/doc/libs/1_74_0/libs/serialization/doc/serialization.html#registration

NOTE: the class types that need to be serialized are passed as a list of template arguments

Definition at line 206 of file RelAlgDagSerializer.h.

206  {
207  (ar.template register_type<RelAlgNodeClasses>(), ...);
208  }
template<class Archive , class RexClass , typename std::enable_if_t< is_rex_class_v< RexClass >> * = nullptr>
static void RelAlgDagSerializer::serialize ( Archive ar,
RexClass &  obj,
const unsigned int  version 
)
inlinestatic

Primary serialization method for Rex/RexScalar-related classes. If you create a new class that inherits from the Rex/RexScalar base class that requires serialization, it needs to be added here.

Making use of "if constexpr" statements to avoid the boilerplate of creating a new templatized method for each class type. This also potentially allows for doing version checking in one spot, if we ever need to version serialization.

Definition at line 122 of file RelAlgDagSerializer.h.

References CHECK.

Referenced by boost::serialization::serialize().

122  {
123  if constexpr (std::is_same_v<Rex, RexClass>) {
124  (ar & obj.hash_);
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));
132  (ar & obj.literal_);
133  (ar & obj.type_);
134  (ar & obj.target_type_);
135  (ar & obj.scale_);
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));
141  (ar & obj.op_);
142  (ar & obj.operands_);
143  (ar & obj.type_);
144  } else if constexpr (std::is_same_v<RexSubQuery, RexClass>) {
145  (ar & boost::serialization::base_object<RexScalar>(obj));
146  (ar & obj.type_);
147 
148  // Execution result should not be set before serialization. If it is means
149  // RelAlgExecutor got its hands on it first before serialization. This is not
150  // advised. Serialization should happen before any RelAlgExecutor processing.
151  CHECK(obj.result_);
152  CHECK(*obj.result_ == nullptr);
153 
154  // BUT we still need to serialize the RexSubQuery::result_. It is a shared_ptr of a
155  // shared_ptr. The outer shared ptr should always be defined, pointing to the
156  // interior shared_ptr that should be null. The way it is designed, this 2-tiered
157  // shared ptr acts as a link between RexSubQuery instances that were deep copied
158  // from a parent. A result should not exist, but the link should, so we need to
159  // serialize result_ (or find a better linking mechanism)
160  (ar & obj.result_);
161 
162  (ar & obj.ra_);
163  } else if constexpr (std::is_same_v<RexInput, RexClass>) {
164  (ar & boost::serialization::base_object<RexAbstractInput>(obj));
165  (ar & obj.node_);
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));
172  (ar & obj.name_);
173  } else if constexpr (std::is_same_v<RexWindowFunctionOperator, RexClass>) {
174  (ar & boost::serialization::base_object<RexFunctionOperator>(obj));
175  (ar & obj.kind_);
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_);
181  (ar & obj.is_rows_);
182  } else if constexpr (std::is_same_v<RexRef, RexClass>) {
183  (ar & boost::serialization::base_object<RexScalar>(obj));
184  (ar & obj.index_);
185  } else if constexpr (std::is_same_v<RexAgg, RexClass>) {
186  (ar & boost::serialization::base_object<Rex>(obj));
187  (ar & obj.agg_);
188  (ar & obj.distinct_);
189  (ar & obj.type_);
190  (ar & obj.operands_);
191  } else {
192  static_assert(!sizeof(RexClass), "Unhandled Rex class during serialization.");
193  }
194  }
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

template<class Archive , class RelAlgClass , typename std::enable_if_t< is_rel_alg_node_class_v< RelAlgClass >> * = nullptr>
static void RelAlgDagSerializer::serialize ( Archive ar,
RelAlgClass &  obj,
const unsigned int  version 
)
inlinestatic

Primary serialization method for RelAlgNode-related classes, including the root RelAlgDag class. If you create a new class that inherits from the RelAlgNode base class that requires serialization, it needs to be added here.

NOTE: Making use of "if constexpr" statements to avoid the boilerplate of creating a new templatized method for each class type.

Definition at line 221 of file RelAlgDagSerializer.h.

221  {
222  if constexpr (std::is_same_v<RelAlgNode, RelAlgClass>) {
223  (ar & obj.inputs_);
224  (ar & obj.id_);
225  (ar & obj.hash_);
226  (ar & obj.is_nop_);
227 
228  // NOTE: not serializing the id_in_plan_tree_, context_data_, targets_metainfo_,
229  // dag_node_id_, query_plan_dag_, & query_plan_dag_hash_ members. They are only
230  // needed for RelAlgExecutor pathways and not needed at the time serialization
231  // is needed.
232  } else if constexpr (std::is_same_v<RelScan, RelAlgClass>) {
233  (ar & boost::serialization::base_object<RelAlgNode>(obj));
234 
235  // NOTE: we're not serializing anything in regard to the member RelScan::td_. The
236  // table descriptor is instead a construction-dependent argument and will be
237  // serialized as part of the save/load contruction data. See
238  // boost::serialization::save_construct_data override below.
239  (ar & obj.field_names_);
240  (ar & obj.hint_applied_);
241  (ar & obj.hints_);
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_);
248 
249  // NOTE: we're not serializing table_descriptor_. The table descriptor is
250  // instead a constructor-dependent argument and will be saved/loaded as part of
251  // custom contructor data. See: boost::serializer::load_construct_data below for
252  // more details.
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_);
257  (ar & obj.fields_);
258  (ar & obj.hint_applied_);
259  (ar & obj.hints_);
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_);
265  (ar & obj.fields_);
266  (ar & obj.hint_applied_);
267  (ar & obj.hints_);
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_);
273  (ar & obj.hints_);
274  } else if constexpr (std::is_same_v<RelFilter, RelAlgClass>) {
275  (ar & boost::serialization::base_object<RelAlgNode>(obj));
276  (ar & obj.filter_);
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));
286 
287  (ar & obj.filter_expr_);
288  (ar & obj.groupby_count_);
289  (ar & obj.agg_exprs_);
290  (ar & obj.fields_);
291  (ar & obj.is_agg_);
292  (ar & obj.scalar_sources_);
293  (ar & obj.target_exprs_);
294  (ar & obj.hint_applied_);
295  (ar & obj.hints_);
296  } else if constexpr (std::is_same_v<RelSort, RelAlgClass>) {
297  (ar & boost::serialization::base_object<RelAlgNode>(obj));
298  (ar & obj.collation_);
299  (ar & obj.limit_);
300  (ar & obj.offset_);
301  } else if constexpr (std::is_same_v<RelModify, RelAlgClass>) {
302  (ar & boost::serialization::base_object<RelAlgNode>(obj));
303  // NOTE: not serializing anything in regard to RelModify::catalog_ or
304  // table_descriptor_ members. They will be used as constructor-dependent arguments
305  // instead and will be saved/loaded with custom constuctor data. See:
306  // RelAlgSerializer for more.
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_);
313  (ar & obj.fields_);
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_);
320  (ar & obj.values_);
321  } else if constexpr (std::is_same_v<RelLogicalUnion, RelAlgClass>) {
322  (ar & boost::serialization::base_object<RelAlgNode>(obj));
323  (ar & obj.is_all_);
324  } else {
325  static_assert(!sizeof(RelAlgClass),
326  "Unhandled RelAlgNode class during serialization");
327  }
328  }
template<class Archive >
static void RelAlgDagSerializer::serialize ( Archive ar,
RelAlgDag rel_alg_dag,
const unsigned int  version 
)
inlinestatic

Primary serialization method for the RelAlgDag clas.

Definition at line 334 of file RelAlgDagSerializer.h.

References RelAlgDag::build_state_, RelAlgDag::global_hints_, RelAlgDag::nodes_, RelAlgDag::query_hint_, and RelAlgDag::subqueries_.

334  {
335  // Need to register all RelAlgNode and RexRexScalar-derived classes for
336  // serialization. This is to ensure derived classes referenced via polymorphic
337  // pointer get properly designated for serialization.
338  registerClassesWithArchive<Archive, REL_ALG_NODE_DERIVED_CLASSES>(ar);
339  registerClassesWithArchive<Archive, REX_DERIVED_CLASSES>(ar);
340 
341  // NOTE: we are not archiving RelTranslatedJoin as it is a RelAlgNode only created
342  // during query execution and therefore not relevant here as the serialization
343  // archive for the RelAlgDag should only be saved/loaded before query execution to
344  // avoid having to serialize any query state
345 
346  // now archive relevant RelAlgDag members
347  (ar & rel_alg_dag.build_state_);
348  (ar & rel_alg_dag.nodes_);
349  (ar & rel_alg_dag.subqueries_);
350  (ar & rel_alg_dag.query_hint_);
351  (ar & rel_alg_dag.global_hints_);
352  }
std::unordered_map< size_t, std::unordered_map< unsigned, RegisteredQueryHint > > query_hint_
Definition: RelAlgDag.h:3388
std::vector< std::shared_ptr< RelAlgNode > > nodes_
Definition: RelAlgDag.h:3381
std::vector< std::shared_ptr< RexSubQuery > > subqueries_
Definition: RelAlgDag.h:3382
RegisteredQueryHint global_hints_
Definition: RelAlgDag.h:3389
BuildState build_state_
Definition: RelAlgDag.h:3379

The documentation for this struct was generated from the following file: