Skip to content

Commit

Permalink
feat: clearer Operator::negate and Expression::toString, logical Equi…
Browse files Browse the repository at this point in the history
…valents for debug printing/logging for the Leaf Operators IndexScan and BitmapSelection
  • Loading branch information
Taepper committed Feb 29, 2024
1 parent f942b00 commit 026b639
Show file tree
Hide file tree
Showing 68 changed files with 348 additions and 280 deletions.
2 changes: 1 addition & 1 deletion include/silo/query_engine/filter_expressions/and.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct And : public Expression {
public:
explicit And(std::vector<std::unique_ptr<Expression>>&& children);

std::string toString(const silo::Database& database) const override;
std::string toString() const override;

[[nodiscard]] std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct DateBetween : public Expression {
std::optional<silo::common::Date> date_to
);

std::string toString(const Database& database) const override;
std::string toString() const override;

[[nodiscard]] std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
2 changes: 1 addition & 1 deletion include/silo/query_engine/filter_expressions/exact.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Exact : public Expression {
public:
explicit Exact(std::unique_ptr<Expression> child);

std::string toString(const Database& database) const override;
std::string toString() const override;

[[nodiscard]] std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
2 changes: 1 addition & 1 deletion include/silo/query_engine/filter_expressions/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct Expression {
Expression();
virtual ~Expression() = default;

virtual std::string toString(const silo::Database& database) const = 0;
virtual std::string toString() const = 0;

[[nodiscard]] virtual std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
2 changes: 1 addition & 1 deletion include/silo/query_engine/filter_expressions/false.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace silo::query_engine::filter_expressions {
struct False : public Expression {
explicit False();

std::string toString(const Database& database) const override;
std::string toString() const override;

[[nodiscard]] std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FloatBetween : public Expression {
public:
explicit FloatBetween(std::string column, std::optional<double> from, std::optional<double> to);

std::string toString(const Database& database) const override;
std::string toString() const override;

[[nodiscard]] std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FloatEquals : public Expression {
public:
FloatEquals(std::string column, double value);

std::string toString(const silo::Database& database) const override;
std::string toString() const override;

[[nodiscard]] std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct HasMutation : public Expression {
public:
explicit HasMutation(std::optional<std::string> sequence_name, uint32_t position_idx);

std::string toString(const Database& database) const override;
std::string toString() const override;

[[nodiscard]] std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct InsertionContains : public Expression {
std::string value
);

std::string toString(const Database& database) const override;
std::string toString() const override;

[[nodiscard]] std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
2 changes: 1 addition & 1 deletion include/silo/query_engine/filter_expressions/int_between.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct IntBetween : public Expression {
std::optional<uint32_t> to
);

std::string toString(const Database& database) const override;
std::string toString() const override;

[[nodiscard]] std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
2 changes: 1 addition & 1 deletion include/silo/query_engine/filter_expressions/int_equals.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct IntEquals : public Expression {
public:
explicit IntEquals(std::string column, uint32_t value);

std::string toString(const Database& database) const override;
std::string toString() const override;

[[nodiscard]] std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
2 changes: 1 addition & 1 deletion include/silo/query_engine/filter_expressions/maybe.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct Maybe : public Expression {

explicit Maybe(std::unique_ptr<Expression> child);

std::string toString(const Database& database) const override;
std::string toString() const override;

[[nodiscard]] std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
4 changes: 3 additions & 1 deletion include/silo/query_engine/filter_expressions/negation.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ struct Database;
namespace silo::query_engine::filter_expressions {

class Negation : public Expression {
friend class Expression;

private:
std::unique_ptr<Expression> child;

public:
explicit Negation(std::unique_ptr<Expression> child);

std::string toString(const Database& database) const override;
std::string toString() const override;

[[nodiscard]] std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
2 changes: 1 addition & 1 deletion include/silo/query_engine/filter_expressions/nof.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct NOf : public Expression {
bool match_exactly
);

std::string toString(const Database& database) const override;
std::string toString() const override;

[[nodiscard]] std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
2 changes: 1 addition & 1 deletion include/silo/query_engine/filter_expressions/or.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct Or : public Expression {
public:
Or(std::vector<std::unique_ptr<Expression>>&& children);

std::string toString(const Database& database) const override;
std::string toString() const override;

[[nodiscard]] std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct PangoLineageFilter : public Expression {
bool include_sublineages
);

std::string toString(const Database& database) const override;
std::string toString() const override;

[[nodiscard]] std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct StringEquals : public Expression {
public:
explicit StringEquals(std::string column, std::string value);

std::string toString(const Database& database) const override;
std::string toString() const override;

[[nodiscard]] std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct SymbolEquals : public Expression {
std::optional<typename SymbolType::Symbol> value
);

std::string toString(const Database& database) const override;
std::string toString() const override;

[[nodiscard]] std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
2 changes: 1 addition & 1 deletion include/silo/query_engine/filter_expressions/true.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace silo::query_engine::filter_expressions {
struct True : public Expression {
explicit True();

std::string toString(const Database& database) const override;
std::string toString() const override;

[[nodiscard]] std::unique_ptr<silo::query_engine::operators::Operator> compile(
const Database& database,
Expand Down
4 changes: 1 addition & 3 deletions include/silo/query_engine/operators/bitmap_producer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ class BitmapProducer : public Operator {

virtual std::string toString() const override;

virtual std::unique_ptr<Operator> copy() const override;

virtual std::unique_ptr<Operator> negate() const override;
static std::unique_ptr<Operator> negate(std::unique_ptr<BitmapProducer>&& bitmap_producer);
};

} // namespace silo::query_engine::operators
20 changes: 17 additions & 3 deletions include/silo/query_engine/operators/bitmap_selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ namespace roaring {
class Roaring;
} // namespace roaring

namespace silo::query_engine::filter_expressions {
class Expression;
} // namespace silo::query_engine::filter_expressions

namespace silo::query_engine::operators {

class BitmapSelection : public Operator {
friend class Operator;

public:
enum Comparator { CONTAINS, NOT_CONTAINS };

private:
std::optional<std::unique_ptr<silo::query_engine::filter_expressions::Expression>>
logical_equivalent;
const roaring::Roaring* bitmaps;
uint32_t row_count;
Comparator comparator;
Expand All @@ -31,6 +39,14 @@ class BitmapSelection : public Operator {
uint32_t value
);

explicit BitmapSelection(
std::unique_ptr<silo::query_engine::filter_expressions::Expression>&& logical_equivalent,
const roaring::Roaring* bitmaps,
uint32_t row_count,
Comparator comparator,
uint32_t value
);

~BitmapSelection() noexcept override;

[[nodiscard]] virtual Type type() const override;
Expand All @@ -39,9 +55,7 @@ class BitmapSelection : public Operator {

virtual std::string toString() const override;

virtual std::unique_ptr<Operator> copy() const override;

virtual std::unique_ptr<Operator> negate() const override;
static std::unique_ptr<Operator> negate(std::unique_ptr<BitmapSelection>&& bitmap_selection);
};

} // namespace silo::query_engine::operators
6 changes: 3 additions & 3 deletions include/silo/query_engine/operators/complement.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
namespace silo::query_engine::operators {

class Complement : public Operator {
friend class Operator;

std::unique_ptr<Operator> child;
uint32_t row_count;

Expand All @@ -30,9 +32,7 @@ class Complement : public Operator {

virtual std::string toString() const override;

virtual std::unique_ptr<Operator> copy() const override;

virtual std::unique_ptr<Operator> negate() const override;
static std::unique_ptr<Operator> negate(std::unique_ptr<Complement>&& complement);
};

} // namespace silo::query_engine::operators
4 changes: 1 addition & 3 deletions include/silo/query_engine/operators/empty.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ class Empty : public Operator {

virtual std::string toString() const override;

virtual std::unique_ptr<Operator> copy() const override;

virtual std::unique_ptr<Operator> negate() const override;
static std::unique_ptr<Operator> negate(std::unique_ptr<Empty>&& empty);
};

} // namespace silo::query_engine::operators
4 changes: 1 addition & 3 deletions include/silo/query_engine/operators/full.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ class Full : public Operator {

virtual std::string toString() const override;

virtual std::unique_ptr<Operator> copy() const override;

virtual std::unique_ptr<Operator> negate() const override;
static std::unique_ptr<Operator> negate(std::unique_ptr<Full>&& full_operator);
};

} // namespace silo::query_engine::operators
17 changes: 14 additions & 3 deletions include/silo/query_engine/operators/index_scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,29 @@ namespace roaring {
class Roaring;
} // namespace roaring

namespace silo::query_engine::filter_expressions {
class Expression;
} // namespace silo::query_engine::filter_expressions

namespace silo::query_engine::operators {

class IndexScan : public Operator {
friend class Operator;

private:
std::optional<std::unique_ptr<query_engine::filter_expressions::Expression>> logical_equivalent;
const roaring::Roaring* bitmap;
uint32_t row_count;

public:
explicit IndexScan(const roaring::Roaring* bitmap, uint32_t row_count);

explicit IndexScan(
std::unique_ptr<query_engine::filter_expressions::Expression>&& logical_equivalent,
const roaring::Roaring* bitmap,
uint32_t row_count
);

~IndexScan() noexcept override;

[[nodiscard]] virtual Type type() const override;
Expand All @@ -29,9 +42,7 @@ class IndexScan : public Operator {

virtual std::string toString() const override;

virtual std::unique_ptr<Operator> copy() const override;

virtual std::unique_ptr<Operator> negate() const override;
static std::unique_ptr<Operator> negate(std::unique_ptr<IndexScan>&& index_scan);
};

} // namespace silo::query_engine::operators
12 changes: 6 additions & 6 deletions include/silo/query_engine/operators/intersection.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

namespace silo::query_engine::filter_expressions {
class And;
}
class NOf;
} // namespace silo::query_engine::filter_expressions

namespace silo::query_engine::operators {

class Intersection : public Operator {
friend class silo::query_engine::filter_expressions::And;
friend class silo::query_engine::filter_expressions::NOf;

std::vector<std::unique_ptr<Operator>> children;
std::vector<std::unique_ptr<Operator>> negated_children;
Expand All @@ -30,15 +32,13 @@ class Intersection : public Operator {

~Intersection() noexcept override;

virtual std::string toString() const override;

[[nodiscard]] Type type() const override;

virtual OperatorResult evaluate() const override;

virtual std::string toString() const override;

virtual std::unique_ptr<Operator> copy() const override;

virtual std::unique_ptr<Operator> negate() const override;
static std::unique_ptr<Operator> negate(std::unique_ptr<Intersection>&& intersection);
};

} // namespace silo::query_engine::operators
9 changes: 7 additions & 2 deletions include/silo/query_engine/operators/operator.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#pragma once

#include <memory>
#include <optional>
#include <string>

#include "silo/query_engine/operator_result.h"

namespace silo::query_engine::filter_expressions {
class Expression;
}

namespace silo::query_engine::operators {

enum Type {
Expand Down Expand Up @@ -33,9 +38,9 @@ class Operator {

virtual std::string toString() const = 0;

virtual std::unique_ptr<Operator> copy() const = 0;
virtual std::optional<std::unique_ptr<filter_expressions::Expression>> logicalEquivalent() const;

virtual std::unique_ptr<Operator> negate() const = 0;
static std::unique_ptr<Operator> negate(std::unique_ptr<Operator>&& some_operator);
};

} // namespace silo::query_engine::operators
4 changes: 1 addition & 3 deletions include/silo/query_engine/operators/range_selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ class RangeSelection : public Operator {

virtual std::string toString() const override;

virtual std::unique_ptr<Operator> copy() const override;

virtual std::unique_ptr<Operator> negate() const override;
static std::unique_ptr<Operator> negate(std::unique_ptr<RangeSelection>&& range_selection);
};

} // namespace silo::query_engine::operators
Loading

0 comments on commit 026b639

Please sign in to comment.