dcapwell commented on code in PR #4175:
URL: https://github.com/apache/cassandra/pull/4175#discussion_r2100708956


##########
src/java/org/apache/cassandra/service/accord/txn/TxnCondition.java:
##########
@@ -289,54 +291,99 @@ public boolean applies(TxnData data)
             FilteredPartition partition = reference.getPartition(data);
             boolean exists = partition != null && !partition.isEmpty();
 
-            Row row = null;
-            if (exists)
+            if (reference.column() != null
+                && !reference.column().isPartitionKey())
             {
-                row = reference.getRow(partition);
-                exists = row != null && !row.isEmpty();
-            }
-
-            if (exists && reference.selectsColumn())
-            {
-                ColumnData columnData = reference.getColumnData(row);
-
-                if (columnData == null)
+                Row row = null;
+                if (exists)
                 {
-                    exists = false;
+                    row = reference.getRow(partition);
+                    exists = row != null && !row.isEmpty();
                 }
-                else if (columnData.column().isComplex())
+
+                if (exists && reference.selectsColumn())
                 {
-                    if (reference.isElementSelection() || 
reference.isFieldSelection())
+                    ColumnData columnData = reference.getColumnData(row);
+
+                    if (columnData == null)
+                    {
+                        exists = false;
+                    }
+                    else if (columnData.column().isComplex())
+                    {
+                        if (reference.isElementSelection())
+                        {
+                            Cell<?> cell = (Cell<?>) columnData;
+                            exists = !cell.isTombstone();
+                            // Collections don't support NULL but meangingless 
null types are supported, so byte[0] is allowed!
+                            // This is NULL when touched, so need to still 
check each value
+                            if (exists)
+                            {
+                                CollectionType<?> type = (CollectionType<?>) 
reference.column().type.unwrap();
+                                switch (type.kind)
+                                {
+                                    case MAP:
+                                    {
+                                        exists = 
!type.nameComparator().isNull(cell.path().get(0));
+                                        if (exists)
+                                            exists = 
!type.valueComparator().isNull(cell.buffer());
+                                    }
+                                    break;
+                                    case SET:
+                                    {
+                                        exists = 
!type.nameComparator().isNull(cell.path().get(0));
+                                    }
+                                    break;
+                                    case LIST:
+                                    {
+                                        exists = 
!type.valueComparator().isNull(cell.buffer());
+                                    }
+                                    break;
+                                    default:
+                                        throw new 
UnsupportedOperationException(type.kind.name());
+                                }
+                            }
+                        }
+                        else if (reference.isFieldSelection())
+                        {
+                            Cell<?> cell = (Cell<?>) columnData;
+                            exists = exists(cell, 
reference.getFieldSelectionType());
+                        }
+                        else
+                        {
+                            // TODO: Is this even necessary, given the 
partition is already filtered?
+                            if (!((ComplexColumnData) 
columnData).complexDeletion().isLive())
+                                exists = false;
+                        }
+                    }
+                    else if (reference.isElementSelection())
+                    {
+                        // This is frozen, so check if the Cell is a tombstone 
and that the element is present.
+                        Cell<?> cell = (Cell<?>) columnData;
+                        exists = exists(cell, reference.column().type);
+                        if (exists)
+                        {
+                            ByteBuffer element = 
reference.getFrozenCollectionElement(cell);
+                            exists = 
!reference.getFrozenCollectionElementType().isNull(element);
+                        }
+                    }
+                    else if (reference.isFieldSelection())

Review Comment:
   im not sure if this is allowed in CQL, but it was already here in the code 
so i made sure it worked



-- 
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: pr-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org
For additional commands, e-mail: pr-h...@cassandra.apache.org

Reply via email to