OmniSciDB  0bd2ec9cf4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RelAlgDagBuilder Class Reference

#include <RelAlgDagBuilder.h>

+ Inheritance diagram for RelAlgDagBuilder:
+ Collaboration diagram for RelAlgDagBuilder:

Public Member Functions

 RelAlgDagBuilder ()=delete
 
 RelAlgDagBuilder (const std::string &query_ra, const Catalog_Namespace::Catalog &cat, const RenderInfo *render_info)
 
 RelAlgDagBuilder (RelAlgDagBuilder &root_dag_builder, const rapidjson::Value &query_ast, const Catalog_Namespace::Catalog &cat, const RenderInfo *render_opts)
 
const RelAlgNodegetRootNode () const
 
std::shared_ptr< const RelAlgNodegetRootNodeShPtr () const
 
void registerSubquery (std::shared_ptr< RexSubQuery > subquery)
 
const std::vector
< std::shared_ptr< RexSubQuery > > & 
getSubqueries () const
 
void resetQueryExecutionState ()
 

Private Member Functions

void build (const rapidjson::Value &query_ast, RelAlgDagBuilder &root_dag_builder)
 

Private Attributes

const Catalog_Namespace::Catalogcat_
 
std::vector< std::shared_ptr
< RelAlgNode > > 
nodes_
 
std::vector< std::shared_ptr
< RexSubQuery > > 
subqueries_
 
const RenderInforender_info_
 

Detailed Description

Builder class to create an in-memory, easy-to-navigate relational algebra DAG interpreted from a JSON representation from Calcite. Also, applies high level optimizations which can be expressed through relational algebra extended with RelCompound. The RelCompound node is an equivalent representation for sequences of RelFilter, RelProject and RelAggregate nodes. This coalescing minimizes the amount of intermediate buffers required to evaluate a query. Lower level optimizations are taken care by lower levels, mainly RelAlgTranslator and the IR code generation.

Definition at line 1490 of file RelAlgDagBuilder.h.

Constructor & Destructor Documentation

RelAlgDagBuilder::RelAlgDagBuilder ( )
delete
RelAlgDagBuilder::RelAlgDagBuilder ( const std::string &  query_ra,
const Catalog_Namespace::Catalog cat,
const RenderInfo render_info 
)

Constructs a RelAlg DAG from a JSON representation.

Parameters
query_raA JSON string representation of an RA tree from Calcite.
catDB catalog for the current user.
render_optsAdditional build options for render queries.

Definition at line 2117 of file RelAlgDagBuilder.cpp.

References build(), CHECK(), logger::ERROR, LOG, RelAlgNode::resetRelAlgFirstId(), and VLOG.

2120  : cat_(cat), render_info_(render_info) {
2121  rapidjson::Document query_ast;
2122  query_ast.Parse(query_ra.c_str());
2123  if (query_ast.HasParseError()) {
2124  query_ast.GetParseError();
2125  LOG(ERROR) << "Failed to parse RA tree from Calcite (offset "
2126  << query_ast.GetErrorOffset() << "):\n"
2127  << rapidjson::GetParseError_En(query_ast.GetParseError());
2128  VLOG(1) << "Failed to parse query RA: " << query_ra;
2129  throw std::runtime_error(
2130  "Failed to parse relational algebra tree. Possible query syntax error.");
2131  }
2132  CHECK(query_ast.IsObject());
2134  build(query_ast, *this);
2135 }
#define LOG(tag)
Definition: Logger.h:188
void build(const rapidjson::Value &query_ast, RelAlgDagBuilder &root_dag_builder)
const Catalog_Namespace::Catalog & cat_
const RenderInfo * render_info_
CHECK(cgen_state)
#define VLOG(n)
Definition: Logger.h:283
static void resetRelAlgFirstId() noexcept

+ Here is the call graph for this function:

RelAlgDagBuilder::RelAlgDagBuilder ( RelAlgDagBuilder root_dag_builder,
const rapidjson::Value &  query_ast,
const Catalog_Namespace::Catalog cat,
const RenderInfo render_opts 
)

Constructs a sub-DAG for any subqueries. Should only be called during DAG building.

Parameters
root_dag_builderThe root DAG builder. The root stores pointers to all subqueries.
query_astThe current JSON node to build a DAG for.
catDB catalog for the current user.
render_optsAdditional build options for render queries.

Definition at line 2137 of file RelAlgDagBuilder.cpp.

References build().

2141  : cat_(cat), render_info_(render_info) {
2142  build(query_ast, root_dag_builder);
2143 }
void build(const rapidjson::Value &query_ast, RelAlgDagBuilder &root_dag_builder)
const Catalog_Namespace::Catalog & cat_
const RenderInfo * render_info_

+ Here is the call graph for this function:

Member Function Documentation

void RelAlgDagBuilder::build ( const rapidjson::Value &  query_ast,
RelAlgDagBuilder root_dag_builder 
)
private

Definition at line 2145 of file RelAlgDagBuilder.cpp.

References alterRAForRender(), anonymous_namespace{RelAlgDagBuilder.cpp}::bind_inputs(), cat_, CHECK(), anonymous_namespace{RelAlgDagBuilder.cpp}::coalesce_nodes(), anonymous_namespace{RelLeftDeepInnerJoin.cpp}::create_left_deep_join(), eliminate_dead_columns(), eliminate_identical_copy(), field(), fold_filters(), get_left_deep_join_root(), hoist_filter_cond_to_cross_join(), anonymous_namespace{RelAlgDagBuilder.cpp}::mark_nops(), nodes_, render_info_, details::RelAlgDispatcher::run(), anonymous_namespace{RelAlgDagBuilder.cpp}::separate_window_function_expressions(), simplify_sort(), and sink_projected_boolean_expr_to_join().

Referenced by RelAlgDagBuilder().

2146  {
2147  const auto& rels = field(query_ast, "rels");
2148  CHECK(rels.IsArray());
2149  try {
2150  nodes_ = details::RelAlgDispatcher(cat_).run(rels, lead_dag_builder);
2151  } catch (const QueryNotSupported&) {
2152  throw;
2153  }
2154  CHECK(!nodes_.empty());
2156 
2157  if (render_info_) {
2158  // Alter the RA for render. Do this before any flattening/optimizations are done to
2159  // the tree.
2161  }
2162 
2163  mark_nops(nodes_);
2168  std::vector<const RelAlgNode*> filtered_left_deep_joins;
2169  std::vector<const RelAlgNode*> left_deep_joins;
2170  for (const auto& node : nodes_) {
2171  const auto left_deep_join_root = get_left_deep_join_root(node);
2172  // The filter which starts a left-deep join pattern must not be coalesced
2173  // since it contains (part of) the join condition.
2174  if (left_deep_join_root) {
2175  left_deep_joins.push_back(left_deep_join_root.get());
2176  if (std::dynamic_pointer_cast<const RelFilter>(left_deep_join_root)) {
2177  filtered_left_deep_joins.push_back(left_deep_join_root.get());
2178  }
2179  }
2180  }
2181  if (filtered_left_deep_joins.empty()) {
2183  }
2184  eliminate_dead_columns(nodes_);
2186  coalesce_nodes(nodes_, left_deep_joins);
2187  CHECK(nodes_.back().unique());
2188  create_left_deep_join(nodes_);
2189 }
void bind_inputs(const std::vector< std::shared_ptr< RelAlgNode >> &nodes) noexcept
void hoist_filter_cond_to_cross_join(std::vector< std::shared_ptr< RelAlgNode >> &nodes) noexcept
std::shared_ptr< const RelAlgNode > get_left_deep_join_root(const std::shared_ptr< RelAlgNode > &node)
void sink_projected_boolean_expr_to_join(std::vector< std::shared_ptr< RelAlgNode >> &nodes) noexcept
void eliminate_identical_copy(std::vector< std::shared_ptr< RelAlgNode >> &nodes) noexcept
std::pair< std::shared_ptr< RelLeftDeepInnerJoin >, std::shared_ptr< const RelAlgNode > > create_left_deep_join(const std::shared_ptr< RelAlgNode > &left_deep_join_root)
const Catalog_Namespace::Catalog & cat_
void simplify_sort(std::vector< std::shared_ptr< RelAlgNode >> &nodes) noexcept
const RenderInfo * render_info_
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
std::vector< std::shared_ptr< RelAlgNode > > nodes_
CHECK(cgen_state)
void separate_window_function_expressions(std::vector< std::shared_ptr< RelAlgNode >> &nodes)
void mark_nops(const std::vector< std::shared_ptr< RelAlgNode >> &nodes) noexcept
void alterRAForRender(std::vector< std::shared_ptr< RelAlgNode >> &nodes, const RenderInfo &render_info)
std::vector< std::shared_ptr< RelAlgNode > > run(const rapidjson::Value &rels, RelAlgDagBuilder &root_dag_builder)
void fold_filters(std::vector< std::shared_ptr< RelAlgNode >> &nodes) noexcept
void eliminate_dead_columns(std::vector< std::shared_ptr< RelAlgNode >> &nodes) noexcept
void coalesce_nodes(std::vector< std::shared_ptr< RelAlgNode >> &nodes, const std::vector< const RelAlgNode * > &left_deep_joins)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const RelAlgNode& RelAlgDagBuilder::getRootNode ( ) const
inline

Returns the root node of the DAG.

Definition at line 1521 of file RelAlgDagBuilder.h.

References CHECK().

1521  {
1522  CHECK(nodes_.size());
1523  const auto& last_ptr = nodes_.back();
1524  CHECK(last_ptr);
1525  return *last_ptr;
1526  }
std::vector< std::shared_ptr< RelAlgNode > > nodes_
CHECK(cgen_state)

+ Here is the call graph for this function:

std::shared_ptr<const RelAlgNode> RelAlgDagBuilder::getRootNodeShPtr ( ) const
inline

Definition at line 1528 of file RelAlgDagBuilder.h.

References CHECK().

Referenced by anonymous_namespace{RelAlgDagBuilder.cpp}::parse_subquery().

1528  {
1529  CHECK(nodes_.size());
1530  return nodes_.back();
1531  }
std::vector< std::shared_ptr< RelAlgNode > > nodes_
CHECK(cgen_state)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::vector<std::shared_ptr<RexSubQuery> >& RelAlgDagBuilder::getSubqueries ( ) const
inline

Gets all registered subqueries. Only the root DAG can contain subqueries.

Definition at line 1544 of file RelAlgDagBuilder.h.

1544  {
1545  return subqueries_;
1546  }
std::vector< std::shared_ptr< RexSubQuery > > subqueries_
void RelAlgDagBuilder::registerSubquery ( std::shared_ptr< RexSubQuery subquery)
inline

Registers a subquery with a root DAG builder. Should only be called during DAG building and registration should only occur on the root.

Definition at line 1537 of file RelAlgDagBuilder.h.

Referenced by anonymous_namespace{RelAlgDagBuilder.cpp}::parse_subquery().

1537  {
1538  subqueries_.push_back(subquery);
1539  }
std::vector< std::shared_ptr< RexSubQuery > > subqueries_

+ Here is the caller graph for this function:

void RelAlgDagBuilder::resetQueryExecutionState ( )

Gets all registered subqueries. Only the root DAG can contain subqueries.

Definition at line 2191 of file RelAlgDagBuilder.cpp.

References nodes_.

2191  {
2192  for (auto& node : nodes_) {
2193  if (node) {
2194  node->resetQueryExecutionState();
2195  }
2196  }
2197 }
std::vector< std::shared_ptr< RelAlgNode > > nodes_

Member Data Documentation

const Catalog_Namespace::Catalog& RelAlgDagBuilder::cat_
private

Definition at line 1556 of file RelAlgDagBuilder.h.

Referenced by build().

std::vector<std::shared_ptr<RelAlgNode> > RelAlgDagBuilder::nodes_
private

Definition at line 1557 of file RelAlgDagBuilder.h.

Referenced by build(), and resetQueryExecutionState().

const RenderInfo* RelAlgDagBuilder::render_info_
private

Definition at line 1559 of file RelAlgDagBuilder.h.

Referenced by build().

std::vector<std::shared_ptr<RexSubQuery> > RelAlgDagBuilder::subqueries_
private

Definition at line 1558 of file RelAlgDagBuilder.h.


The documentation for this class was generated from the following files: