cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [1/2] git commit: Correctly typecheck in CQL3 even in presence of ReversedType
Date Wed, 27 Mar 2013 15:18:50 GMT
Updated Branches:
  refs/heads/trunk 1527fabfc -> 4c348c422


Correctly typecheck in CQL3 even in presence of ReversedType

patch by slebresne; reviewed by jbellis for CASSANDRA-5386


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/b72af485
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/b72af485
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/b72af485

Branch: refs/heads/trunk
Commit: b72af485f625b734cecaa8556578890f346cd274
Parents: 61e329f
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Wed Mar 27 16:16:10 2013 +0100
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Wed Mar 27 16:16:10 2013 +0100

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 src/java/org/apache/cassandra/cql3/CQL3Type.java   |   32 +++++++++++++++
 src/java/org/apache/cassandra/cql3/TypeCast.java   |    2 +-
 .../cassandra/cql3/functions/FunctionCall.java     |    2 +-
 .../apache/cassandra/cql3/functions/Functions.java |    4 +-
 .../cassandra/cql3/statements/Selection.java       |    2 +-
 .../apache/cassandra/db/marshal/ReversedType.java  |    7 +++
 7 files changed, 45 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/b72af485/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 26b2360..400e5c3 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -12,6 +12,7 @@
  * Invalid streamId in cql binary protocol when using invalid CL (CASSANDRA-5164)
  * Fix validation for IN where clauses with collections (CASSANDRA-5376)
  * Copy resultSet on count query to avoid ConcurrentModificationException (CASSANDRA-5382)
+ * Correctly typecheck in CQL3 even with ReversedType (CASSANDRA-5386)
 Merged from 1.1:
  * cli: Quote ks and cf names in schema output when needed (CASSANDRA-5052)
  * Fix bad default for min/max timestamp in SSTableMetadata (CASSANDRA-5372)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b72af485/src/java/org/apache/cassandra/cql3/CQL3Type.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/CQL3Type.java b/src/java/org/apache/cassandra/cql3/CQL3Type.java
index 58a2fa3..d7a4e8e 100644
--- a/src/java/org/apache/cassandra/cql3/CQL3Type.java
+++ b/src/java/org/apache/cassandra/cql3/CQL3Type.java
@@ -106,6 +106,22 @@ public interface CQL3Type
         }
 
         @Override
+        public final boolean equals(Object o)
+        {
+            if(!(o instanceof Custom))
+                return false;
+
+            Custom that = (Custom)o;
+            return type.equals(that.type);
+        }
+
+        @Override
+        public final int hashCode()
+        {
+            return type.hashCode();
+        }
+
+        @Override
         public String toString()
         {
             return "'" + type + "'";
@@ -167,6 +183,22 @@ public interface CQL3Type
         }
 
         @Override
+        public final boolean equals(Object o)
+        {
+            if(!(o instanceof Collection))
+                return false;
+
+            Collection that = (Collection)o;
+            return type.equals(that.type);
+        }
+
+        @Override
+        public final int hashCode()
+        {
+            return type.hashCode();
+        }
+
+        @Override
         public String toString()
         {
             switch (type.kind)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b72af485/src/java/org/apache/cassandra/cql3/TypeCast.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/TypeCast.java b/src/java/org/apache/cassandra/cql3/TypeCast.java
index 2fa322a..66b5300 100644
--- a/src/java/org/apache/cassandra/cql3/TypeCast.java
+++ b/src/java/org/apache/cassandra/cql3/TypeCast.java
@@ -48,7 +48,7 @@ public class TypeCast implements Term.Raw
 
     public boolean isAssignableTo(ColumnSpecification receiver)
     {
-        return receiver.type.equals(type.getType());
+        return receiver.type.asCQL3Type().equals(type);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b72af485/src/java/org/apache/cassandra/cql3/functions/FunctionCall.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/functions/FunctionCall.java b/src/java/org/apache/cassandra/cql3/functions/FunctionCall.java
index 36603d6..01c26af 100644
--- a/src/java/org/apache/cassandra/cql3/functions/FunctionCall.java
+++ b/src/java/org/apache/cassandra/cql3/functions/FunctionCall.java
@@ -132,7 +132,7 @@ public class FunctionCall extends Term.NonTerminal
         public boolean isAssignableTo(ColumnSpecification receiver)
         {
             AbstractType<?> returnType = Functions.getReturnType(functionName, receiver.ksName,
receiver.cfName);
-            return receiver.type.equals(returnType);
+            return receiver.type.asCQL3Type().equals(returnType.asCQL3Type());
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b72af485/src/java/org/apache/cassandra/cql3/functions/Functions.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/functions/Functions.java b/src/java/org/apache/cassandra/cql3/functions/Functions.java
index 3660f5d..a53b1dd 100644
--- a/src/java/org/apache/cassandra/cql3/functions/Functions.java
+++ b/src/java/org/apache/cassandra/cql3/functions/Functions.java
@@ -112,7 +112,7 @@ public abstract class Functions
 
     private static void validateTypes(Function fun, List<? extends AssignementTestable>
providedArgs, ColumnSpecification receiver) throws InvalidRequestException
     {
-        if (!receiver.type.equals(fun.returnType()))
+        if (!receiver.type.asCQL3Type().equals(fun.returnType().asCQL3Type()))
             throw new InvalidRequestException(String.format("Type error: cannot assign result
of function %s (type %s) to %s (type %s)", fun.name(), fun.returnType().asCQL3Type(), receiver,
receiver.type.asCQL3Type()));
 
         if (providedArgs.size() != fun.argsType().size())
@@ -135,7 +135,7 @@ public abstract class Functions
 
     private static boolean isValidType(Function fun, List<? extends AssignementTestable>
providedArgs, ColumnSpecification receiver)
     {
-        if (!receiver.type.equals(fun.returnType()))
+        if (!receiver.type.asCQL3Type().equals(fun.returnType().asCQL3Type()))
             return false;
 
         if (providedArgs.size() != fun.argsType().size())

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b72af485/src/java/org/apache/cassandra/cql3/statements/Selection.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/Selection.java b/src/java/org/apache/cassandra/cql3/statements/Selection.java
index a402453..c42b587 100644
--- a/src/java/org/apache/cassandra/cql3/statements/Selection.java
+++ b/src/java/org/apache/cassandra/cql3/statements/Selection.java
@@ -374,7 +374,7 @@ public abstract class Selection
 
         public boolean isAssignableTo(ColumnSpecification receiver)
         {
-            return receiver.type.equals(isWritetime ? LongType.instance : Int32Type.instance);
+            return receiver.type.asCQL3Type().equals(isWritetime ? CQL3Type.Native.BIGINT
: CQL3Type.Native.INT);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b72af485/src/java/org/apache/cassandra/db/marshal/ReversedType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/ReversedType.java b/src/java/org/apache/cassandra/db/marshal/ReversedType.java
index 40e9a84..9fdecb8 100644
--- a/src/java/org/apache/cassandra/db/marshal/ReversedType.java
+++ b/src/java/org/apache/cassandra/db/marshal/ReversedType.java
@@ -22,6 +22,7 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.List;
 
+import org.apache.cassandra.cql3.CQL3Type;
 import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.exceptions.SyntaxException;
 
@@ -97,6 +98,12 @@ public class ReversedType<T> extends AbstractType<T>
     }
 
     @Override
+    public CQL3Type asCQL3Type()
+    {
+        return baseType.asCQL3Type();
+    }
+
+    @Override
     public String toString()
     {
         return getClass().getName() + "(" + baseType + ")";


Mime
View raw message