OmniSciDB  f632821e96
anonymous_namespace{RelAlgExecutionDescriptor.cpp} Namespace Reference

Functions

std::vector< Vertexmerge_sort_with_input (const std::vector< Vertex > &vertices, const DAG &graph)
 
DAG build_dag (const RelAlgNode *sink)
 
std::unordered_set< Vertexget_join_vertices (const std::vector< Vertex > &vertices, const DAG &graph)
 

Function Documentation

◆ build_dag()

DAG anonymous_namespace{RelAlgExecutionDescriptor.cpp}::build_dag ( const RelAlgNode sink)

Definition at line 120 of file RelAlgExecutionDescriptor.cpp.

References CHECK.

Referenced by RaExecutionSequence::RaExecutionSequence().

120  {
121  DAG graph(1);
122  graph[0] = sink;
123  std::unordered_map<const RelAlgNode*, int> node_ptr_to_vert_idx{
124  std::make_pair(sink, 0)};
125  std::vector<const RelAlgNode*> stack(1, sink);
126  while (!stack.empty()) {
127  const auto node = stack.back();
128  stack.pop_back();
129  if (dynamic_cast<const RelScan*>(node)) {
130  continue;
131  }
132 
133  const auto input_num = node->inputCount();
134  switch (input_num) {
135  case 0:
136  CHECK(dynamic_cast<const RelLogicalValues*>(node));
137  case 1:
138  break;
139  case 2:
140  CHECK(dynamic_cast<const RelJoin*>(node) ||
141  dynamic_cast<const RelLeftDeepInnerJoin*>(node) ||
142  dynamic_cast<const RelLogicalUnion*>(node) ||
143  dynamic_cast<const RelTableFunction*>(node));
144  break;
145  default:
146  CHECK(dynamic_cast<const RelLeftDeepInnerJoin*>(node) ||
147  dynamic_cast<const RelLogicalUnion*>(node) ||
148  dynamic_cast<const RelTableFunction*>(node));
149  }
150  for (size_t i = 0; i < input_num; ++i) {
151  const auto input = node->getInput(i);
152  CHECK(input);
153  const bool visited = node_ptr_to_vert_idx.count(input) > 0;
154  if (!visited) {
155  node_ptr_to_vert_idx.insert(std::make_pair(input, node_ptr_to_vert_idx.size()));
156  }
157  boost::add_edge(node_ptr_to_vert_idx[input], node_ptr_to_vert_idx[node], graph);
158  if (!visited) {
159  graph[node_ptr_to_vert_idx[input]] = input;
160  stack.push_back(input);
161  }
162  }
163  }
164  return graph;
165 }
#define CHECK(condition)
Definition: Logger.h:197
boost::adjacency_list< boost::setS, boost::vecS, boost::bidirectionalS, const RelAlgNode * > DAG
+ Here is the caller graph for this function:

◆ get_join_vertices()

std::unordered_set<Vertex> anonymous_namespace{RelAlgExecutionDescriptor.cpp}::get_join_vertices ( const std::vector< Vertex > &  vertices,
const DAG graph 
)

Definition at line 167 of file RelAlgExecutionDescriptor.cpp.

References CHECK.

Referenced by RaExecutionSequence::RaExecutionSequence().

168  {
169  std::unordered_set<Vertex> joins;
170  for (const auto vert : vertices) {
171  if (dynamic_cast<const RelLeftDeepInnerJoin*>(graph[vert])) {
172  joins.insert(vert);
173  continue;
174  }
175  if (!dynamic_cast<const RelJoin*>(graph[vert])) {
176  continue;
177  }
178  if (boost::out_degree(vert, graph) > 1) {
179  throw std::runtime_error("Join used more than once not supported yet");
180  }
181  auto [oe_iter, oe_end] = boost::out_edges(vert, graph);
182  CHECK(std::next(oe_iter) == oe_end);
183  const auto out_vert = boost::target(*oe_iter, graph);
184  if (!dynamic_cast<const RelJoin*>(graph[out_vert])) {
185  joins.insert(vert);
186  }
187  }
188  return joins;
189 }
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the caller graph for this function:

◆ merge_sort_with_input()

std::vector<Vertex> anonymous_namespace{RelAlgExecutionDescriptor.cpp}::merge_sort_with_input ( const std::vector< Vertex > &  vertices,
const DAG graph 
)

Definition at line 90 of file RelAlgExecutionDescriptor.cpp.

References CHECK.

Referenced by RaExecutionSequence::RaExecutionSequence().

91  {
92  DAG::in_edge_iterator ie_iter, ie_end;
93  std::unordered_set<Vertex> inputs;
94  for (const auto vert : vertices) {
95  if (const auto sort = dynamic_cast<const RelSort*>(graph[vert])) {
96  boost::tie(ie_iter, ie_end) = boost::in_edges(vert, graph);
97  CHECK(size_t(1) == sort->inputCount() && boost::next(ie_iter) == ie_end);
98  const auto in_vert = boost::source(*ie_iter, graph);
99  const auto input = graph[in_vert];
100  if (dynamic_cast<const RelScan*>(input)) {
101  throw std::runtime_error("Standalone sort not supported yet");
102  }
103  if (boost::out_degree(in_vert, graph) > 1) {
104  throw std::runtime_error("Sort's input node used by others not supported yet");
105  }
106  inputs.insert(in_vert);
107  }
108  }
109 
110  std::vector<Vertex> new_vertices;
111  for (const auto vert : vertices) {
112  if (inputs.count(vert)) {
113  continue;
114  }
115  new_vertices.push_back(vert);
116  }
117  return new_vertices;
118 }
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the caller graph for this function: