This is an automated email from the ASF dual-hosted git repository.

ycai pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/trunk by this push:
     new e8891be04a Fix type check for referenced duration type for nested types
e8891be04a is described below

commit e8891be04a681fbd87e2bec2c07ed22e55725a04
Author: rwelgosh <[email protected]>
AuthorDate: Mon Oct 14 00:01:49 2024 -0400

    Fix type check for referenced duration type for nested types
    
    Patch by Raymond Welgosh; Reviewed by David Capwell, Yifan Cai for 
CASSANDRA-19890
---
 CHANGES.txt                                        |  1 +
 .../apache/cassandra/db/marshal/AbstractType.java  |  7 ++++++
 .../apache/cassandra/db/marshal/ReversedType.java  |  6 +++++
 .../cassandra/db/marshal/AbstractTypeTest.java     | 27 ++++++++++++++++++++++
 4 files changed, 41 insertions(+)

diff --git a/CHANGES.txt b/CHANGES.txt
index 0e454fa198..239c04f4c9 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 5.1
+ * Fix type check for referenced duration type for nested types 
(CASSANDRA-19890)
  * In simulation tests, correctly set the tokens of replacement nodes 
(CASSANDRA-19997)
  * During TCM upgrade, retain all properties of existing system tables 
(CASSANDRA-19992)
  * Properly cancel in-flight futures and reject requests in EpochAwareDebounce 
during shutdown (CASSANDRA-19848)
diff --git a/src/java/org/apache/cassandra/db/marshal/AbstractType.java 
b/src/java/org/apache/cassandra/db/marshal/AbstractType.java
index c55d9afd44..3c382e781b 100644
--- a/src/java/org/apache/cassandra/db/marshal/AbstractType.java
+++ b/src/java/org/apache/cassandra/db/marshal/AbstractType.java
@@ -641,6 +641,13 @@ public abstract class AbstractType<T> implements 
Comparator<ByteBuffer>, Assignm
 
     public boolean referencesDuration()
     {
+        for (AbstractType<?> type : subTypes())
+        {
+            if (type.referencesDuration())
+            {
+                return true;
+            }
+        }
         return false;
     }
 
diff --git a/src/java/org/apache/cassandra/db/marshal/ReversedType.java 
b/src/java/org/apache/cassandra/db/marshal/ReversedType.java
index 3d5e11d0d7..b567fe3481 100644
--- a/src/java/org/apache/cassandra/db/marshal/ReversedType.java
+++ b/src/java/org/apache/cassandra/db/marshal/ReversedType.java
@@ -164,6 +164,12 @@ public class ReversedType<T> extends AbstractType<T>
         return getInstance(baseType.expandUserTypes());
     }
 
+    @Override
+    public boolean referencesDuration()
+    {
+        return baseType.referencesDuration();
+    }
+
     @Override
     public ReversedType<?> withUpdatedUserType(UserType udt)
     {
diff --git a/test/unit/org/apache/cassandra/db/marshal/AbstractTypeTest.java 
b/test/unit/org/apache/cassandra/db/marshal/AbstractTypeTest.java
index 35ecfab60d..ed2046fe5d 100644
--- a/test/unit/org/apache/cassandra/db/marshal/AbstractTypeTest.java
+++ b/test/unit/org/apache/cassandra/db/marshal/AbstractTypeTest.java
@@ -460,6 +460,33 @@ public class AbstractTypeTest
         });
     }
 
+    @Test
+    @SuppressWarnings("rawtypes")
+    public void nestedDuration()
+    {
+        qt().forAll(AbstractTypeGenerators.builder()
+                                          .withoutTypeKinds(COUNTER)
+                                          
.withPrimitives(DurationType.instance)
+                                          .build())
+            .checkAssert(type -> {
+                assertThat(type.referencesDuration()).isTrue();
+                
assertThat(ReversedType.getInstance(type).referencesDuration()).isTrue();
+            });
+    }
+
+    @Test
+    public void nestedWithoutDuration()
+    {
+        qt().forAll(AbstractTypeGenerators.builder()
+                                          .withoutTypeKinds(PRIMITIVE, COUNTER)
+                                          
.withoutPrimitive(DurationType.instance)
+                                          .build())
+            .checkAssert(type -> {
+                assertThat(type.referencesDuration()).isFalse();
+                
assertThat(ReversedType.getInstance(type).referencesDuration()).isFalse();
+            });
+    }
+
     /**
      * @see <pre>CASSANDRA-18526: TupleType getString and fromString are not 
safe with string types</pre>
      */


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

Reply via email to