-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathp2c.cpp
More file actions
691 lines (582 loc) · 22 KB
/
p2c.cpp
File metadata and controls
691 lines (582 loc) · 22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
// Viktor Leis, 2023
#include <algorithm>
#include <cassert>
#include <functional>
#include <iostream>
#include <map>
#include <source_location>
#include <sstream>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>
#if __has_include(<format>)
#include <format>
#include <print>
#elif __has_include(<fmt/core.h>)
#include <fmt/core.h>
using namespace fmt;
#else
#error "Neither <format> nor libfmt is available. Please install libfmt and link it in your Makefile."
#endif
#include "tpch.hpp"
#include "types.hpp"
using namespace std;
using namespace p2c;
////////////////////////////////////////////////////////////////////////////////
// an Information Unit (IU) represents an attribute of a query plan
struct IU {
string name;
Type type;
string varname;
IU(const string& name, Type type) : name(name), type(type), varname(genVar(name)) {}
// generate unique variable name
static string genVar(const string& name) {
static unsigned varCounter = 1;
return format("{}{}", name, varCounter++);
}
};
// format generic list of strings with delimiter (helper)
string join(const vector<string>& strs, const string& delim) {
string result = "";
bool first = true;
for (const auto& str : strs) {
if (first)
first = false;
else
result += delim;
result += str;
}
return result;
}
// format comma-separated list of IU types (helper)
string formatTypes(const vector<IU*>& ius) {
vector<string> iuNames;
for (IU* iu : ius)
iuNames.push_back(tname(iu->type));
return join(iuNames, ",");
}
// format comma-separated list of IU varnames (helper)
string formatVarnames(const vector<IU*>& ius) {
vector<string> varNames;
for (IU* iu : ius)
varNames.push_back(iu->varname);
return join(varNames, ",");
}
// provide an IU by generating local variable (helper)
void provideIU(IU* iu, const string& value) {
print("{} {} = {};\n", tname(iu->type), iu->varname, value);
}
// an unordered set of IUs
struct IUSet {
// set is represented as array; invariant: IUs are sorted by pointer value
vector<IU*> v;
// empty set constructor
IUSet() {}
// move constructor
IUSet(IUSet&& x) { v = std::move(x.v); }
// copy constructor
IUSet(const IUSet& x) { v = x.v; }
// convert vector to set of IUs (assumes vector is unique, but not sorted)
explicit IUSet(const vector<IU*>& vv) {
v = vv;
sort(v.begin(), v.end());
// check that there are no duplicates
assert(adjacent_find(v.begin(), v.end()) == v.end());
}
// iterate over IUs
IU** begin() { return v.data(); }
IU** end() { return v.data() + v.size(); }
IU* const* begin() const { return v.data(); }
IU* const* end() const { return v.data() + v.size(); }
void add(IU* iu) {
auto it = lower_bound(v.begin(), v.end(), iu);
if (it == v.end() || *it != iu)
v.insert(it, iu); // O(n), not nice
}
bool contains(IU* iu) const {
auto it = lower_bound(v.begin(), v.end(), iu);
return (it != v.end() && *it == iu);
}
unsigned size() const { return v.size(); };
};
// set union operator
IUSet operator|(const IUSet& a, const IUSet& b) {
IUSet result;
set_union(a.v.begin(), a.v.end(), b.v.begin(), b.v.end(), back_inserter(result.v));
return result;
}
// set intersection operator
IUSet operator&(const IUSet& a, const IUSet& b) {
IUSet result;
set_intersection(a.v.begin(), a.v.end(), b.v.begin(), b.v.end(), back_inserter(result.v));
return result;
}
// set difference operator
IUSet operator-(const IUSet& a, const IUSet& b) {
IUSet result;
set_difference(a.v.begin(), a.v.end(), b.v.begin(), b.v.end(), back_inserter(result.v));
return result;
}
// set equality operator
bool operator==(const IUSet& a, const IUSet& b) {
return equal(a.v.begin(), a.v.end(), b.v.begin(), b.v.end());
}
////////////////////////////////////////////////////////////////////////////////
// abstract base class of all expressions
struct Exp {
// compile expression to string
virtual string compile() = 0;
// set of all IUs used in this expression
virtual IUSet iusUsed() = 0;
// destructor
virtual ~Exp(){};
};
// expression that simply references an IU
struct IUExp : public Exp {
IU* iu;
// constructor
IUExp(IU* iu) : iu(iu) {}
// destructor
~IUExp() {}
string compile() override { return iu->varname; }
IUSet iusUsed() override { return IUSet({iu}); }
};
// expression that represent a constant value
template<typename T>
requires is_p2c_type<T>
struct ConstExp : public Exp {
T x;
// constructor
ConstExp(T x) : x(x){};
// destructor
~ConstExp() {}
string compile() override {
if constexpr (type_tag<T>::tag == Type::String) {
return format("\"{}\"", x); // Add quotes for strings
} else {
return format("{}", x);
}
}
IUSet iusUsed() override { return {}; }
};
// expression that represents function all
struct FnExp : public Exp {
// function name
string fnName;
// arguments
vector<unique_ptr<Exp>> args;
// constructor
FnExp(string fnName, vector<unique_ptr<Exp>>&& v) : fnName(fnName), args(std::move(v)) {}
// destructor
~FnExp() {}
string compile() override {
vector<string> strs;
for (auto& e : args)
strs.emplace_back(e->compile());
return format("{}({})", fnName, join(strs, ","));
}
IUSet iusUsed() override {
IUSet result;
for (auto& exp : args)
for (IU* iu : exp->iusUsed())
result.add(iu);
return result;
}
};
////////////////////////////////////////////////////////////////////////////////
// generate curly-brace block of C++ code (helper)
template<class Fn>
void genBlock(const string& str, Fn fn, const std::source_location& location = std::source_location::current()) {
cout << str << "{ //" << location.line() << "; " << location.function_name() << endl;
fn();
cout << "}" << endl;
}
// consumer callback function
typedef std::function<void(void)> ConsumerFn;
// abstract base class of all operators
struct Operator {
// compute *all* IUs this operator can produce
virtual IUSet availableIUs() = 0;
// generate code for operator providing 'required' IUs and pushing them to 'consume' callback
virtual void produce(const IUSet& required, ConsumerFn consume) = 0;
// destructor
virtual ~Operator() {}
};
// table scan operator
struct Scan : public Operator {
// IU storage for all available attributes
vector<IU> attributes;
// relation name
string relName;
// constructor
Scan(const string& relName) : relName(relName) {
// get relation info from schema
auto it = TPCH::schema.find(relName);
assert(it != TPCH::schema.end());
auto& rel = it->second;
// create IUs for all available attributes
attributes.reserve(rel.size());
for (auto& att : rel)
attributes.emplace_back(IU{att.first, att.second});
}
// destructor
~Scan() {}
IUSet availableIUs() override {
IUSet result;
for (auto& iu : attributes)
result.add(&iu);
return result;
}
void produce(const IUSet& required, ConsumerFn consume) override {
genBlock(format("for (uint64_t i = 0; i != db.{}.tupleCount; i++)", relName), [&]() {
for (IU* iu : required)
provideIU(iu, format("db.{}.{}[i]", relName, iu->name));
consume();
});
}
IU* getIU(const string& attName) {
for (IU& iu : attributes)
if (iu.name == attName)
return &iu;
throw;
}
};
// selection operator
struct Selection : public Operator {
unique_ptr<Operator> input;
unique_ptr<Exp> pred;
// constructor
Selection(unique_ptr<Operator> input, unique_ptr<Exp> predicate) : input(std::move(input)), pred(std::move(predicate)) {}
// destructor
~Selection() {}
IUSet availableIUs() override { return input->availableIUs(); }
void produce(const IUSet& required, ConsumerFn consume) override {
input->produce(required | pred->iusUsed(), [&]() {
genBlock(format("if ({})", pred->compile()), [&]() {
consume();
});
});
}
};
// map operator (compute new value)
struct Map : public Operator {
unique_ptr<Operator> input;
unique_ptr<Exp> exp;
IU iu;
// constructor
Map(unique_ptr<Operator> input, unique_ptr<Exp> exp, const string& name, Type type)
: input(std::move(input)), exp(std::move(exp)), iu{name, type} {}
// destructor
~Map() {}
IUSet availableIUs() override { return input->availableIUs() | IUSet({&iu}); }
void produce(const IUSet& required, ConsumerFn consume) override {
input->produce((required | exp->iusUsed()) - IUSet({&iu}), [&]() {
genBlock("", [&]() {
provideIU(&iu, exp->compile());
consume();
});
});
}
IU* getIU(const string& attName) {
if (iu.name == attName)
return &iu;
throw;
}
};
// sort operator
struct Sort : public Operator {
unique_ptr<Operator> input;
vector<IU*> keyIUs;
vector<bool> ascending;
IU v{"vector", Type::Undefined};
IU cmp{"custom_cmp", Type::Undefined};
// constructor
Sort(unique_ptr<Operator> input, const vector<IU*>& keyIUs, const vector<bool> ascending) : input(std::move(input)), keyIUs(keyIUs), ascending(ascending) {}
// destructor
~Sort() {}
IUSet availableIUs() override { return input->availableIUs(); }
void produce(const IUSet& required, ConsumerFn consume) override {
// compute IUs
IUSet restIUs = required - IUSet(keyIUs);
vector<IU*> allIUs = keyIUs;
allIUs.insert(allIUs.end(), restIUs.v.begin(), restIUs.v.end());
// define custom comparator
genBlock("struct", [&]() {
genBlock(format("bool operator()(const tuple<{0}>& lhs, const tuple<{0}>& rhs) const",
formatTypes(allIUs)),
[&]() {
for (size_t i = 0; i != keyIUs.size(); i++) {
print("if (get<{0}>(lhs) != get<{0}>(rhs)) return get<{0}>(lhs) {1} get<{0}>(rhs);\n", i,
ascending[i] ? "<" : ">");
}
print("return false;\n");
});
});
print("{};\n", cmp.varname);
// collect tuples
print("vector<tuple<{}>> {};\n", formatTypes(allIUs), v.varname);
input->produce(IUSet(allIUs), [&]() {
print("{}.push_back({{{}}});\n", v.varname, formatVarnames(allIUs));
});
// sort
print("sort({0}.begin(), {0}.end(), {1});\n", v.varname, cmp.varname);
// iterate
genBlock(format("for (auto& t : {})", v.varname), [&]() {
for (unsigned i = 0; i < allIUs.size(); i++)
if (required.contains(allIUs[i]))
provideIU(allIUs[i], format("get<{}>(t)", i));
consume();
});
};
};
// abstract base class for aggregate functions using in group by
struct Aggregate {
IU* inputIU; // IU to aggregate (is nullptr when aggFn==Count)
IU resultIU;
Aggregate(string name, IU* _inputIU) : inputIU(_inputIU), resultIU(name, _inputIU->type) {}
Aggregate(std::string name, Type type) : inputIU(nullptr), resultIU(std::move(name), type) {}
virtual ~Aggregate() = default;
virtual string genInitValue() = 0;
virtual string genUpdate(string oldValueRef) = 0;
};
struct CountAggregate final : Aggregate {
CountAggregate(string name) : Aggregate(name, Type::Integer) {}
string genInitValue() override { return "1"; }
string genUpdate(string oldValueRef) override {
return format("{} += 1", oldValueRef);
}
};
struct MinAggregate final : Aggregate {
MinAggregate(string name, IU* _inputIU) : Aggregate(name, _inputIU) {}
string genInitValue() override { return format("{}", inputIU->varname); }
string genUpdate(string oldValueRef) override {
return format("{} = std::min({}, {})", oldValueRef, oldValueRef, inputIU->varname);
}
};
struct SumAggregate final : Aggregate {
SumAggregate(string name, IU* _inputIU) : Aggregate(name, _inputIU) {}
string genInitValue() override { return format("{}", inputIU->varname); }
string genUpdate(string oldValueRef) override {
return format("{} += {}", oldValueRef, inputIU->varname);
}
};
// group by operator
struct GroupBy : public Operator {
unique_ptr<Operator> input;
IUSet groupKeyIUs;
vector<unique_ptr<Aggregate>> aggs;
IU ht{"aggHT", Type::Undefined};
// constructor
GroupBy(unique_ptr<Operator> input, const IUSet& groupKeyIUs) : input(std::move(input)), groupKeyIUs(groupKeyIUs) {}
// destructor
~GroupBy() {}
void addAggregate(std::unique_ptr<Aggregate> agg) { aggs.emplace_back(std::move(agg)); }
std::vector<IU*> resultIUs() {
std::vector<IU*> v;
for (auto& agg : aggs)
v.push_back(&agg->resultIU);
return v;
}
IUSet inputIUs() {
IUSet v;
for (auto& agg : aggs)
if (agg->inputIU)
v.add(agg->inputIU);
return v;
}
IUSet availableIUs() override { return groupKeyIUs | IUSet(resultIUs()); }
void produce(const IUSet& required, ConsumerFn consume) override {
// build hash table
print("unordered_map<tuple<{}>, tuple<{}>> {};\n", formatTypes(groupKeyIUs.v), formatTypes(resultIUs()), ht.varname);
input->produce(groupKeyIUs | inputIUs(), [&]() {
// insert tuple into hash table
print("auto it = {}.find({{{}}});\n", ht.varname, formatVarnames(groupKeyIUs.v));
genBlock(format("if (it == {}.end())", ht.varname), [&]() {
vector<string> initValues;
for (auto& agg : aggs)
initValues.push_back(agg->genInitValue());
// insert new group
print("{}.insert({{{{{}}}, {{{}}}}});\n", ht.varname, formatVarnames(groupKeyIUs.v), join(initValues, ","));
});
genBlock("else", [&]() {
// update group
unsigned i = 0;
for (auto& agg : aggs) {
print("{};\n", agg->genUpdate(format("get<{}>(it->second)", i++)));
}
});
});
// iterate over hash table
genBlock(format("for (auto& it : {})", ht.varname), [&]() {
for (unsigned i = 0; i < groupKeyIUs.size(); i++) {
IU* iu = groupKeyIUs.v[i];
if (required.contains(iu))
provideIU(iu, format("get<{}>(it.first)", i));
}
unsigned i = 0;
for (auto& agg : aggs) {
provideIU(&agg->resultIU, format("get<{}>(it.second)", i));
i++;
}
consume();
});
}
IU* getIU(const string& attName) {
for (auto& agg : aggs)
if (agg->resultIU.name == attName)
return &agg->resultIU;
throw;
}
};
// hash join operator
struct HashJoin : public Operator {
unique_ptr<Operator> left;
unique_ptr<Operator> right;
// join keys from both inputs, example: left=[a, b] right=[c, d] a=c AND b=d
vector<IU*> leftKeyIUs, rightKeyIUs;
// variable name for hash table
IU ht{"joinHT", Type::Undefined};
// constructor
HashJoin(unique_ptr<Operator> left, unique_ptr<Operator> right, const vector<IU*>& leftKeyIUs, const vector<IU*>& rightKeyIUs)
: left(std::move(left)), right(std::move(right)), leftKeyIUs(leftKeyIUs), rightKeyIUs(rightKeyIUs) {}
// destructor
~HashJoin() {}
IUSet availableIUs() override { return left->availableIUs() | right->availableIUs(); }
void produce(const IUSet& required, ConsumerFn consume) override {
// figure out where required IUs come from
IUSet leftRequiredIUs = (required & left->availableIUs()) | IUSet(leftKeyIUs);
IUSet rightRequiredIUs = (required & right->availableIUs()) | IUSet(rightKeyIUs);
IUSet leftPayloadIUs = leftRequiredIUs - IUSet(leftKeyIUs); // these we need to store in hash table as payload
// build hash table
print("unordered_multimap<tuple<{}>, tuple<{}>> {};\n", formatTypes(leftKeyIUs), formatTypes(leftPayloadIUs.v), ht.varname);
left->produce(leftRequiredIUs, [&]() {
// insert tuple into hash table
print("{}.insert({{{{{}}}, {{{}}}}});\n", ht.varname, formatVarnames(leftKeyIUs), formatVarnames(leftPayloadIUs.v));
});
// probe hash table
right->produce(rightRequiredIUs, [&]() {
// iterate over matches
genBlock(format("for (auto range = {}.equal_range({{{}}}); range.first!=range.second; range.first++)", ht.varname, formatVarnames(rightKeyIUs)), [&]() {
// unpack payload
unsigned countP = 0;
for (IU* iu : leftPayloadIUs)
provideIU(iu, format("get<{}>(range.first->second)", countP++));
// unpack keys if needed
for (unsigned i = 0; i < leftKeyIUs.size(); i++) {
IU* iu = leftKeyIUs[i];
if (required.contains(iu))
provideIU(iu, format("get<{}>(range.first->first)", i));
}
// consume
consume();
});
});
}
};
////////////////////////////////////////////////////////////////////////////////
// create a function call expression (helper)
template<typename T>
requires is_p2c_type<T>
unique_ptr<Exp> makeCallExp(const string& fn, IU* iu, const T& x) {
vector<unique_ptr<Exp>> v;
v.push_back(make_unique<IUExp>(iu));
v.push_back(make_unique<ConstExp<T>>(x));
return make_unique<FnExp>(fn, std::move(v));
}
template<typename... T>
unique_ptr<Exp> makeCallExp(const string& fn, std::unique_ptr<T>... args) {
vector<unique_ptr<Exp>> v;
(v.push_back(std::move(args)), ...);
return make_unique<FnExp>(fn, std::move(v));
}
// Print
void produceAndPrint(unique_ptr<Operator> root, const std::vector<IU*>& ius, unsigned perfRepeat = 2) {
genBlock(format("for (uint64_t {0} = 0; {0} != {1}; {0}++)", IU::genVar("perfRepeat"), perfRepeat - 1), [&]() {
root->produce(IUSet(ius), [&]() {
for (IU* iu : ius)
print("cout << {} << \" \";", iu->varname);
print("cout << endl;\n");
});
});
}
////////////////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[]) {
// ------------------------------------------------------------
// TPC-H Query 5; should return the following on sf1 according to umbra:
// INDONESIA 55502041.1697
// VIETNAM 55295086.9967
// CHINA 53724494.2566
// INDIA 52035512.0002
// JAPAN 45410175.6954
// ------------------------------------------------------------
// select
// n_name,
// sum(l_extendedprice * (1 - l_discount)) as revenue
// from
// customer,
// orders,
// lineitem,
// supplier,
// nation,
// region
// where
// c_custkey = o_custkey
// and l_orderkey = o_orderkey
// and l_suppkey = s_suppkey
// and c_nationkey = s_nationkey
// and s_nationkey = n_nationkey
// and n_regionkey = r_regionkey
// and r_name = 'ASIA'
// and o_orderdate >= date '1994-01-01'
// and o_orderdate < date '1994-01-01' + interval '1' year
// group by
// n_name
// order by
// revenue desc
// ------------------------------------------------------------
{
auto r = make_unique<Scan>("region");
IU* r_regionkey = r->getIU("r_regionkey");
IU* r_name = r->getIU("r_name");
auto r_sel =
make_unique<Selection>(std::move(r), makeCallExp("std::equal_to()", make_unique<IUExp>(r_name),
make_unique<ConstExp<string_view>>("ASIA")));
auto n = make_unique<Scan>("nation");
IU* n_nationkey = n->getIU("n_nationkey");
IU* n_regionkey = n->getIU("n_regionkey");
IU* n_name = n->getIU("n_name");
auto join1 = make_unique<HashJoin>(std::move(r_sel), std::move(n), vector<IU*>{r_regionkey}, vector<IU*>{n_regionkey});
auto c = make_unique<Scan>("customer");
IU* c_custkey = c->getIU("c_custkey");
IU* c_nationkey = c->getIU("c_nationkey");
auto join2 = make_unique<HashJoin>(std::move(join1), std::move(c), vector<IU*>{n_nationkey}, vector<IU*>{c_nationkey});
auto o = make_unique<Scan>("orders");
auto o_orderkey = o->getIU("o_orderkey");
auto o_custkey = o->getIU("o_custkey");
auto o_orderdate = o->getIU("o_orderdate");
auto lowerBoundExp = makeCallExp("std::greater_equal()", o_orderdate, stringToType<date>("1994-01-01", 10).value);
auto upperBoundExp = makeCallExp("std::less()", o_orderdate, stringToType<date>("1995-01-01", 10).value);
auto o_sel = make_unique<Selection>(std::move(o), makeCallExp("std::logical_and()", std::move(lowerBoundExp), std::move(upperBoundExp)));
auto join3 = make_unique<HashJoin>(std::move(join2), std::move(o_sel), vector<IU*>{c_custkey}, vector<IU*>{o_custkey});
auto l = make_unique<Scan>("lineitem");
auto l_orderkey = l->getIU("l_orderkey");
auto l_suppkey = l->getIU("l_suppkey");
auto l_extendedprice = l->getIU("l_extendedprice");
auto l_discount = l->getIU("l_discount");
auto join4 = make_unique<HashJoin>(std::move(join3), std::move(l), vector<IU*>{o_orderkey}, vector<IU*>{l_orderkey});
auto s = make_unique<Scan>("supplier");
auto s_suppkey = s->getIU("s_suppkey");
auto s_nationkey = s->getIU("s_nationkey");
auto join5 = make_unique<HashJoin>(std::move(s), std::move(join4), vector<IU*>{s_suppkey, s_nationkey}, vector<IU*>{l_suppkey, n_nationkey});
auto discountPriceExp = makeCallExp("std::multiplies()", make_unique<IUExp>(l_extendedprice), makeCallExp("std::minus()", make_unique<ConstExp<double>>(1.0), make_unique<IUExp>(l_discount)));
auto discountPriceMap = make_unique<Map>(std::move(join5), std::move(discountPriceExp), "revenue", Type::Double);
auto discountPrice = discountPriceMap->getIU("revenue");
auto gb = make_unique<GroupBy>(std::move(discountPriceMap), IUSet({n_name}));
gb->addAggregate(make_unique<SumAggregate>("revenue", discountPrice));
auto revenue = gb->getIU("revenue");
auto sort = make_unique<Sort>(std::move(gb), vector<IU*>{revenue}, vector<bool>{false});
produceAndPrint(std::move(sort), {n_name, revenue});
}
return 0;
}