souffle  2.0.2-371-g6315b36
ParallelIndexAggregate.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2018, The Souffle Developers. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /************************************************************************
10  *
11  * @file ParallelIndexAggregate.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "AggregateOp.h"
18 #include "ram/AbstractAggregate.h"
19 #include "ram/AbstractParallel.h"
20 #include "ram/Condition.h"
21 #include "ram/Expression.h"
22 #include "ram/IndexAggregate.h"
23 #include "ram/IndexOperation.h"
24 #include "ram/Node.h"
25 #include "ram/Operation.h"
26 #include "ram/Relation.h"
27 #include "ram/utility/Utils.h"
30 #include <iosfwd>
31 #include <memory>
32 #include <ostream>
33 #include <string>
34 #include <utility>
35 #include <vector>
36 
37 namespace souffle::ram {
38 
39 /**
40  * @class ParallelIndexAggregate
41  * @brief Aggregate over values of a relation using an index in parallel
42  *
43  * For example:
44  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45  * t0.0=sum t0.1 SEARCH t0 ∈ S ON INDEX t0.0 = number(1)
46  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47  */
48 class ParallelIndexAggregate : public IndexAggregate, public AbstractParallel {
49 public:
50  ParallelIndexAggregate(Own<Operation> nested, AggregateOp fun, std::string rel,
51  Own<Expression> expression, Own<Condition> condition, RamPattern queryPattern, int ident)
52  : IndexAggregate(std::move(nested), fun, rel, std::move(expression), std::move(condition),
53  std::move(queryPattern), ident) {}
54 
55  ParallelIndexAggregate* clone() const override {
56  RamPattern pattern;
57  for (const auto& i : queryPattern.first) {
58  pattern.first.emplace_back(i->clone());
59  }
60  for (const auto& i : queryPattern.second) {
61  pattern.second.emplace_back(i->clone());
62  }
64  souffle::clone(expression), souffle::clone(condition), std::move(pattern), getTupleId());
65  }
66 
67 protected:
68  void print(std::ostream& os, int tabpos) const override {
69  os << times(" ", tabpos);
70  os << "PARALLEL t" << getTupleId() << ".0=";
71  AbstractAggregate::print(os, tabpos);
72  os << "SEARCH t" << getTupleId() << " ∈ " << relation;
73  printIndex(os);
74  if (!isTrue(condition.get())) {
75  os << " WHERE " << getCondition();
76  }
77  os << std::endl;
78  IndexOperation::print(os, tabpos + 1);
79  }
80 };
81 
82 } // namespace souffle::ram
AggregateOp.h
souffle::ram::AbstractAggregate::getCondition
const Condition & getCondition() const
Get condition.
Definition: AbstractAggregate.h:53
souffle::AggregateOp
AggregateOp
Types of aggregation functions.
Definition: AggregateOp.h:34
souffle::ram::NestedOperation::getOperation
Operation & getOperation() const
Get nested operation.
Definition: NestedOperation.h:62
MiscUtil.h
souffle::ram::ParallelIndexAggregate::ParallelIndexAggregate
ParallelIndexAggregate(Own< Operation > nested, AggregateOp fun, std::string rel, Own< Expression > expression, Own< Condition > condition, RamPattern queryPattern, int ident)
Definition: ParallelIndexAggregate.h:54
souffle::ram::AbstractAggregate::print
void print(std::ostream &os, int) const
Definition: AbstractAggregate.h:74
souffle::ram::ParallelIndexAggregate::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: ParallelIndexAggregate.h:72
souffle::ram
Definition: AstToRamTranslator.h:54
IndexAggregate.h
souffle::ram::RelationOperation::relation
const std::string relation
Search relation.
Definition: RelationOperation.h:60
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
souffle::times
detail::multiplying_printer< T > times(const T &value, unsigned num)
A utility printing a given value multiple times.
Definition: StreamUtil.h:322
i
size_t i
Definition: json11.h:663
souffle::ram::ParallelIndexAggregate::clone
ParallelIndexAggregate * clone() const override
Create a clone (i.e.
Definition: ParallelIndexAggregate.h:59
souffle::ram::ParallelIndexAggregate
Aggregate over values of a relation using an index in parallel.
Definition: ParallelIndexAggregate.h:52
Relation.h
souffle::ram::AbstractAggregate::expression
Own< Expression > expression
Aggregation expression.
Definition: AbstractAggregate.h:104
Condition.h
souffle::ram::IndexAggregate
Indexed aggregation on a relation. The index allows us to iterate over a restricted range.
Definition: IndexAggregate.h:51
souffle::ram::TupleOperation::getTupleId
int getTupleId() const
Get identifier.
Definition: TupleOperation.h:43
Utils.h
souffle::ram::IndexOperation::printIndex
void printIndex(std::ostream &os) const
Helper method for printing.
Definition: IndexOperation.h:108
souffle::ram::isTrue
bool isTrue(const Condition *cond)
Determines if a condition represents true.
Definition: Utils.h:45
IndexOperation.h
AbstractParallel.h
Node.h
std
Definition: Brie.h:3053
Operation.h
souffle::ram::IndexOperation::queryPattern
RamPattern queryPattern
Values of index per column of table (if indexable)
Definition: IndexOperation.h:161
souffle::ram::RamPattern
std::pair< RamBound, RamBound > RamPattern
Definition: IndexOperation.h:42
StreamUtil.h
AbstractAggregate.h
Expression.h
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086
souffle::ram::NestedOperation::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: NestedOperation.h:80
souffle::ram::AbstractAggregate::condition
Own< Condition > condition
Aggregation tuple condition.
Definition: AbstractAggregate.h:107