[PATCH] position_in_partition: Introduce reversed() transformation

7 views
Skip to first unread message

Tomasz Grabiec

unread,
Sep 17, 2021, 6:26:16 AMSep 17
to scylla...@googlegroups.com
It transforms the position from a forward-clustering-order schema
domain to a reversed-clustering-order schema domain.

The object still refers to the same element of the space of keys under this
transformation. However, the identification of the position,
the position_in_partition object, is schema-dependent, it is always
interpreted relative to some schema. Hence the need to transform it
when switching schema domains.
---
position_in_partition.hh | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)

diff --git a/position_in_partition.hh b/position_in_partition.hh
index d6800a8dc4..6df81a2c4a 100644
--- a/position_in_partition.hh
+++ b/position_in_partition.hh
@@ -59,6 +59,18 @@ enum class bound_weight : int8_t {
after_all_prefixed = 1,
};

+inline
+bound_weight reversed(bound_weight w) {
+ switch (w) {
+ case bound_weight::equal:
+ return w;
+ case bound_weight::before_all_prefixed:
+ return bound_weight::after_all_prefixed;
+ case bound_weight::after_all_prefixed:
+ return bound_weight::before_all_prefixed;
+ }
+}
+
inline
bound_weight position_weight(bound_kind k) {
switch (k) {
@@ -213,6 +225,11 @@ class position_in_partition_view {
friend std::ostream& operator<<(std::ostream& os, printer p);
};

+ // Create a position which is the same as this one but governed by a schema with reversed clustering key order.
+ position_in_partition_view reversed() const {
+ return position_in_partition_view(_type, ::reversed(_bound_weight), _ck);
+ }
+
friend std::ostream& operator<<(std::ostream& os, printer p);
friend std::ostream& operator<<(std::ostream&, position_in_partition_view);
friend bool no_clustering_row_between(const schema&, position_in_partition_view, position_in_partition_view);
@@ -522,6 +539,16 @@ class position_in_partition {
}
};
friend std::ostream& operator<<(std::ostream&, const position_in_partition&);
+
+ // Create a position which is the same as this one but governed by a schema with reversed clustering key order.
+ position_in_partition reversed() const& {
+ return position_in_partition(_type, ::reversed(_bound_weight), _ck);
+ }
+
+ // Create a position which is the same as this one but governed by a schema with reversed clustering key order.
+ position_in_partition reversed() && {
+ return position_in_partition(_type, ::reversed(_bound_weight), std::move(_ck));
+ }
};

inline
--
2.29.2

Benny Halevy

unread,
Sep 19, 2021, 1:37:52 AMSep 19
to Tomasz Grabiec, scylla...@googlegroups.com
LGTM overall,

The reversed() functions just lack users.
Adding trivial unit test to make sure they compile and work properly
would be appreciated.

Kamil Braun

unread,
Sep 27, 2021, 6:51:09 AMSep 27
to Benny Halevy, Tomasz Grabiec, scylladb-dev
ping, please follow up with this
I'd like to use this in my code

--
You received this message because you are subscribed to the Google Groups "ScyllaDB development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scylladb-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scylladb-dev/ccc707b68b2f9f22287b431465d7c3743e73ac78.camel%40scylladb.com.

Commit Bot

unread,
Sep 27, 2021, 7:23:16 AMSep 27
to scylla...@googlegroups.com, Tomasz Grabiec
From: Tomasz Grabiec <tgra...@scylladb.com>
Committer: Avi Kivity <a...@scylladb.com>
Branch: next

position_in_partition: Introduce reversed() transformation

It transforms the position from a forward-clustering-order schema
domain to a reversed-clustering-order schema domain.

The object still refers to the same element of the space of keys under this
transformation. However, the identification of the position,
the position_in_partition object, is schema-dependent, it is always
interpreted relative to some schema. Hence the need to transform it
when switching schema domains.

Message-Id: <20210917102612.3...@scylladb.com>

---
diff --git a/position_in_partition.hh b/position_in_partition.hh
--- a/position_in_partition.hh
+++ b/position_in_partition.hh
@@ -59,6 +59,18 @@ enum class bound_weight : int8_t {
after_all_prefixed = 1,
};

+inline
+bound_weight reversed(bound_weight w) {
+ switch (w) {
+ case bound_weight::equal:
+ return w;
+ case bound_weight::before_all_prefixed:
+ return bound_weight::after_all_prefixed;
+ case bound_weight::after_all_prefixed:
+ return bound_weight::before_all_prefixed;
+ }
+}
+
inline
bound_weight position_weight(bound_kind k) {
switch (k) {
@@ -213,6 +225,11 @@ public:
friend std::ostream& operator<<(std::ostream& os, printer p);
};

+ // Create a position which is the same as this one but governed by a schema with reversed clustering key order.
+ position_in_partition_view reversed() const {
+ return position_in_partition_view(_type, ::reversed(_bound_weight), _ck);
+ }
+
friend std::ostream& operator<<(std::ostream& os, printer p);
friend std::ostream& operator<<(std::ostream&, position_in_partition_view);
friend bool no_clustering_row_between(const schema&, position_in_partition_view, position_in_partition_view);
@@ -522,6 +539,16 @@ public:

Commit Bot

unread,
Sep 28, 2021, 10:00:12 AMSep 28
to scylla...@googlegroups.com, Tomasz Grabiec
From: Tomasz Grabiec <tgra...@scylladb.com>
Committer: Avi Kivity <a...@scylladb.com>
Branch: master

position_in_partition: Introduce reversed() transformation

It transforms the position from a forward-clustering-order schema
domain to a reversed-clustering-order schema domain.

The object still refers to the same element of the space of keys under this
transformation. However, the identification of the position,
the position_in_partition object, is schema-dependent, it is always
interpreted relative to some schema. Hence the need to transform it
when switching schema domains.

Message-Id: <20210917102612.3...@scylladb.com>

---
diff --git a/position_in_partition.hh b/position_in_partition.hh
--- a/position_in_partition.hh
+++ b/position_in_partition.hh
@@ -59,6 +59,18 @@ enum class bound_weight : int8_t {
after_all_prefixed = 1,
};

+inline
+bound_weight reversed(bound_weight w) {
+ switch (w) {
+ case bound_weight::equal:
+ return w;
+ case bound_weight::before_all_prefixed:
+ return bound_weight::after_all_prefixed;
+ case bound_weight::after_all_prefixed:
+ return bound_weight::before_all_prefixed;
+ }
+}
+
inline
bound_weight position_weight(bound_kind k) {
switch (k) {
@@ -213,6 +225,11 @@ public:
friend std::ostream& operator<<(std::ostream& os, printer p);
};

+ // Create a position which is the same as this one but governed by a schema with reversed clustering key order.
+ position_in_partition_view reversed() const {
+ return position_in_partition_view(_type, ::reversed(_bound_weight), _ck);
+ }
+
friend std::ostream& operator<<(std::ostream& os, printer p);
friend std::ostream& operator<<(std::ostream&, position_in_partition_view);
friend bool no_clustering_row_between(const schema&, position_in_partition_view, position_in_partition_view);
@@ -522,6 +539,16 @@ public:
Reply all
Reply to author
Forward
0 new messages