1#include "duckdb/parser/tableref/crossproductref.hpp"
2#include "duckdb/parser/tableref/emptytableref.hpp"
3#include "duckdb/parser/transformer.hpp"
4
5using namespace duckdb;
6using namespace std;
7
8unique_ptr<TableRef> Transformer::TransformFrom(PGList *root) {
9 if (!root) {
10 return make_unique<EmptyTableRef>();
11 }
12
13 if (root->length > 1) {
14 // Cross Product
15 auto result = make_unique<CrossProductRef>();
16 CrossProductRef *cur_root = result.get();
17 for (auto node = root->head; node != nullptr; node = node->next) {
18 auto n = reinterpret_cast<PGNode *>(node->data.ptr_value);
19 unique_ptr<TableRef> next = TransformTableRefNode(n);
20 if (!cur_root->left) {
21 cur_root->left = move(next);
22 } else if (!cur_root->right) {
23 cur_root->right = move(next);
24 } else {
25 auto old_res = move(result);
26 result = make_unique<CrossProductRef>();
27 result->left = move(old_res);
28 result->right = move(next);
29 cur_root = result.get();
30 }
31 }
32 return move(result);
33 }
34
35 auto n = reinterpret_cast<PGNode *>(root->head->data.ptr_value);
36 return TransformTableRefNode(n);
37}
38