belliottsmith commented on code in PR #4879:
URL: https://github.com/apache/cassandra/pull/4879#discussion_r3519248568


##########
src/java/org/apache/cassandra/service/accord/txn/TxnCondition.java:
##########
@@ -618,6 +621,125 @@ public long serializedSize(Value condition, 
TableMetadatas tables)
         };
     }
 
+    public static class Reference extends TxnCondition
+    {
+        private static final EnumSet<Kind> KINDS = EnumSet.of(Kind.EQUAL, 
Kind.NOT_EQUAL,
+                                                              
Kind.GREATER_THAN, Kind.GREATER_THAN_OR_EQUAL,
+                                                              Kind.LESS_THAN, 
Kind.LESS_THAN_OR_EQUAL);
+
+        private final TxnReference.ColumnReference referenceLHS;
+        private final TxnReference.ColumnReference referenceRHS;
+        private final ProtocolVersion version;
+
+        public Reference(TxnReference.ColumnReference referenceLHS, Kind kind, 
TxnReference.ColumnReference referenceRHS, ProtocolVersion version)
+        {
+            super(kind);
+            Invariants.requireArgument(KINDS.contains(kind), "Kind " + kind + 
" cannot be used with a value condition");
+            this.referenceLHS = referenceLHS;
+            this.referenceRHS = referenceRHS;
+            this.version = version;
+        }
+
+        public static EnumSet<Kind> supported()
+        {
+            return EnumSet.copyOf(KINDS);
+        }
+
+        @Override
+        public boolean equals(Object o)
+        {
+            if (this == o) return true;
+            if (o == null || getClass() != o.getClass()) return false;
+            if (!super.equals(o)) return false;
+            Reference reference1 = (Reference) o;
+            return referenceLHS.equals(reference1.referenceLHS) && 
referenceRHS.equals(reference1.referenceRHS);
+        }
+
+        @Override
+        public void collect(TableMetadatas.Collector collector)
+        {
+            referenceLHS.collect(collector);
+            referenceRHS.collect(collector);
+        }
+
+        @Override
+        public int hashCode()
+        {
+            return Objects.hash(super.hashCode(), referenceLHS, referenceRHS);
+        }
+
+        @Override
+        public String toString()
+        {
+            return referenceLHS.toString() + ' ' + kind.symbol + ' ' + 
referenceRHS.toString();
+        }
+
+        public AbstractType<?> getColumnType(TxnReference.ColumnReference 
reference)
+        {
+            ColumnMetadata column = reference.column();
+            if (reference.isElementSelection())
+            {
+                if (column.type instanceof ListType)
+                    return ((ListType<?>) column.type).valueComparator();
+                else if (column.type instanceof SetType)
+                    return ((SetType<?>) column.type).nameComparator();
+                else if (column.type instanceof MapType)
+                    return ((MapType<?, ?>) column.type).valueComparator();
+            }
+            else if (reference.isFieldSelection())
+            {
+                return reference.getFieldSelectionType();
+            }
+
+            return column.type;
+        }
+
+        @Override
+        public boolean applies(TxnData data)
+        {
+            AbstractType<?> typeLHS = getColumnType(referenceLHS);
+            AbstractType<?> typeRHS = getColumnType(referenceRHS);
+
+            ByteBuffer lhs = referenceLHS.toByteBuffer(data, typeLHS);
+            ByteBuffer rhs = referenceRHS.toByteBuffer(data, typeRHS);
+
+            if (lhs == null || rhs == null)
+                return false;
+
+            return kind.operator.isSatisfiedBy(typeLHS, lhs, rhs);

Review Comment:
   Let's just add an invariant check and use one of the types so it's clear to 
a reader then?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to