cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [1/7] CQL3 refactor to allow conversion function
Date Fri, 08 Feb 2013 17:58:40 GMT
http://git-wip-us.apache.org/repos/asf/cassandra/blob/31e669ab/src/java/org/apache/cassandra/db/marshal/FloatType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/FloatType.java b/src/java/org/apache/cassandra/db/marshal/FloatType.java
index 95854e1..cb3cc3b 100644
--- a/src/java/org/apache/cassandra/db/marshal/FloatType.java
+++ b/src/java/org/apache/cassandra/db/marshal/FloatType.java
@@ -18,12 +18,9 @@
 package org.apache.cassandra.db.marshal;
 
 import java.nio.ByteBuffer;
-import java.util.EnumSet;
-import java.util.Set;
 
 import org.apache.cassandra.cql.jdbc.JdbcFloat;
 import org.apache.cassandra.cql3.CQL3Type;
-import org.apache.cassandra.cql3.Term;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 
@@ -31,8 +28,6 @@ public class FloatType extends AbstractType<Float>
 {
     public static final FloatType instance = new FloatType();
 
-    private final Set<Term.Type> supportedCQL3Constants = EnumSet.of(Term.Type.INTEGER,
Term.Type.FLOAT);
-
     FloatType() {} // singleton
 
     public Float compose(ByteBuffer bytes)
@@ -94,11 +89,6 @@ public class FloatType extends AbstractType<Float>
             throw new MarshalException(String.format("Expected 4 or 0 byte value for a float
(%d)", bytes.remaining()));
     }
 
-    public Set<Term.Type> supportedCQL3Constants()
-    {
-        return supportedCQL3Constants;
-    }
-
     public CQL3Type asCQL3Type()
     {
         return CQL3Type.Native.FLOAT;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/31e669ab/src/java/org/apache/cassandra/db/marshal/InetAddressType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/InetAddressType.java b/src/java/org/apache/cassandra/db/marshal/InetAddressType.java
index e90bdf3..f060354 100644
--- a/src/java/org/apache/cassandra/db/marshal/InetAddressType.java
+++ b/src/java/org/apache/cassandra/db/marshal/InetAddressType.java
@@ -20,20 +20,15 @@ package org.apache.cassandra.db.marshal;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.nio.ByteBuffer;
-import java.util.EnumSet;
-import java.util.Set;
 
 import org.apache.cassandra.cql.jdbc.JdbcInetAddress;
 import org.apache.cassandra.cql3.CQL3Type;
-import org.apache.cassandra.cql3.Term;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class InetAddressType extends AbstractType<InetAddress>
 {
     public static final InetAddressType instance = new InetAddressType();
 
-    private final Set<Term.Type> supportedCQL3Constants = EnumSet.of(Term.Type.STRING);
-
     InetAddressType() {} // singleton
 
     public InetAddress compose(ByteBuffer bytes)
@@ -88,11 +83,6 @@ public class InetAddressType extends AbstractType<InetAddress>
         }
     }
 
-    public Set<Term.Type> supportedCQL3Constants()
-    {
-        return supportedCQL3Constants;
-    }
-
     public CQL3Type asCQL3Type()
     {
         return CQL3Type.Native.INET;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/31e669ab/src/java/org/apache/cassandra/db/marshal/Int32Type.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/Int32Type.java b/src/java/org/apache/cassandra/db/marshal/Int32Type.java
index a945074..1e206ff 100644
--- a/src/java/org/apache/cassandra/db/marshal/Int32Type.java
+++ b/src/java/org/apache/cassandra/db/marshal/Int32Type.java
@@ -18,20 +18,15 @@
 package org.apache.cassandra.db.marshal;
 
 import java.nio.ByteBuffer;
-import java.util.EnumSet;
-import java.util.Set;
 
 import org.apache.cassandra.cql.jdbc.JdbcInt32;
 import org.apache.cassandra.cql3.CQL3Type;
-import org.apache.cassandra.cql3.Term;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class Int32Type extends AbstractType<Integer>
 {
     public static final Int32Type instance = new Int32Type();
 
-    private final Set<Term.Type> supportedCQL3Constants = EnumSet.of(Term.Type.INTEGER);
-
     Int32Type() {} // singleton
 
     public Integer compose(ByteBuffer bytes)
@@ -101,11 +96,6 @@ public class Int32Type extends AbstractType<Integer>
             throw new MarshalException(String.format("Expected 4 or 0 byte int (%d)", bytes.remaining()));
     }
 
-    public Set<Term.Type> supportedCQL3Constants()
-    {
-        return supportedCQL3Constants;
-    }
-
     public CQL3Type asCQL3Type()
     {
         return CQL3Type.Native.INT;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/31e669ab/src/java/org/apache/cassandra/db/marshal/IntegerType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/IntegerType.java b/src/java/org/apache/cassandra/db/marshal/IntegerType.java
index d492ba6..de675f6 100644
--- a/src/java/org/apache/cassandra/db/marshal/IntegerType.java
+++ b/src/java/org/apache/cassandra/db/marshal/IntegerType.java
@@ -19,20 +19,15 @@ package org.apache.cassandra.db.marshal;
 
 import java.math.BigInteger;
 import java.nio.ByteBuffer;
-import java.util.EnumSet;
-import java.util.Set;
 
 import org.apache.cassandra.cql.jdbc.JdbcInteger;
 import org.apache.cassandra.cql3.CQL3Type;
-import org.apache.cassandra.cql3.Term;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 public final class IntegerType extends AbstractType<BigInteger>
 {
     public static final IntegerType instance = new IntegerType();
 
-    private final Set<Term.Type> supportedCQL3Constants = EnumSet.of(Term.Type.INTEGER);
-
     private static int findMostSignificantByte(ByteBuffer bytes)
     {
         int len = bytes.remaining() - 1;
@@ -159,11 +154,6 @@ public final class IntegerType extends AbstractType<BigInteger>
         // no invalid integers.
     }
 
-    public Set<Term.Type> supportedCQL3Constants()
-    {
-        return supportedCQL3Constants;
-    }
-
     public CQL3Type asCQL3Type()
     {
         return CQL3Type.Native.VARINT;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/31e669ab/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java b/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java
index 3805ac3..c1f2049 100644
--- a/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java
+++ b/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java
@@ -18,12 +18,9 @@
 package org.apache.cassandra.db.marshal;
 
 import java.nio.ByteBuffer;
-import java.util.EnumSet;
-import java.util.Set;
 import java.util.UUID;
 
 import org.apache.cassandra.cql.jdbc.JdbcLexicalUUID;
-import org.apache.cassandra.cql3.Term;
 import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.UUIDGen;
 
@@ -31,8 +28,6 @@ public class LexicalUUIDType extends AbstractType<UUID>
 {
     public static final LexicalUUIDType instance = new LexicalUUIDType();
 
-    private final Set<Term.Type> supportedCQL3Constants = EnumSet.of(Term.Type.UUID);
-
     LexicalUUIDType() {} // singleton
 
     public UUID compose(ByteBuffer bytes)
@@ -93,9 +88,4 @@ public class LexicalUUIDType extends AbstractType<UUID>
             throw new MarshalException(String.format("LexicalUUID should be 16 or 0 bytes
(%d)", bytes.remaining()));
         // not sure what the version should be for this.
     }
-
-    public Set<Term.Type> supportedCQL3Constants()
-    {
-        return supportedCQL3Constants;
-    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/31e669ab/src/java/org/apache/cassandra/db/marshal/LongType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/LongType.java b/src/java/org/apache/cassandra/db/marshal/LongType.java
index 4bf95c6..71ad36f 100644
--- a/src/java/org/apache/cassandra/db/marshal/LongType.java
+++ b/src/java/org/apache/cassandra/db/marshal/LongType.java
@@ -18,20 +18,15 @@
 package org.apache.cassandra.db.marshal;
 
 import java.nio.ByteBuffer;
-import java.util.EnumSet;
-import java.util.Set;
 
 import org.apache.cassandra.cql.jdbc.JdbcLong;
 import org.apache.cassandra.cql3.CQL3Type;
-import org.apache.cassandra.cql3.Term;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class LongType extends AbstractType<Long>
 {
     public static final LongType instance = new LongType();
 
-    private final Set<Term.Type> supportedCQL3Constants = EnumSet.of(Term.Type.INTEGER);
-
     LongType() {} // singleton
 
     public Long compose(ByteBuffer bytes)
@@ -101,11 +96,6 @@ public class LongType extends AbstractType<Long>
             throw new MarshalException(String.format("Expected 8 or 0 byte long (%d)", bytes.remaining()));
     }
 
-    public Set<Term.Type> supportedCQL3Constants()
-    {
-        return supportedCQL3Constants;
-    }
-
     public CQL3Type asCQL3Type()
     {
         return CQL3Type.Native.BIGINT;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/31e669ab/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java b/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java
index e37e04e..4eda451 100644
--- a/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java
+++ b/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java
@@ -18,15 +18,12 @@
 package org.apache.cassandra.db.marshal;
 
 import java.nio.ByteBuffer;
-import java.util.EnumSet;
-import java.util.Set;
 import java.util.UUID;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.apache.cassandra.cql.jdbc.JdbcTimeUUID;
 import org.apache.cassandra.cql3.CQL3Type;
-import org.apache.cassandra.cql3.Term;
 import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.UUIDGen;
 
@@ -35,9 +32,6 @@ public class TimeUUIDType extends AbstractType<UUID>
     public static final TimeUUIDType instance = new TimeUUIDType();
 
     static final Pattern regexPattern = Pattern.compile("[A-Fa-f0-9]{8}\\-[A-Fa-f0-9]{4}\\-[A-Fa-f0-9]{4}\\-[A-Fa-f0-9]{4}\\-[A-Fa-f0-9]{12}");
-    static final Pattern functionPattern = Pattern.compile("(\\w+)\\((.*)\\)");
-
-    private final Set<Term.Type> supportedCQL3Constants = EnumSet.of(Term.Type.UUID);
 
     TimeUUIDType() {} // singleton
 
@@ -171,34 +165,8 @@ public class TimeUUIDType extends AbstractType<UUID>
         }
         else
         {
-            Matcher m = functionPattern.matcher(source);
-            if (!m.matches())
-                throw new MarshalException(String.format("Unable to make a time-based UUID
from '%s'", source));
-
-            String fct = m.group(1);
-            String arg = m.group(2);
-
-            if (fct.equalsIgnoreCase("minTimeUUID"))
-            {
-                idBytes = decompose(UUIDGen.minTimeUUID(DateType.dateStringToTimestamp(arg)));
-            }
-            else if (fct.equalsIgnoreCase("maxTimeUUID"))
-            {
-                idBytes = decompose(UUIDGen.maxTimeUUID(DateType.dateStringToTimestamp(arg)));
-            }
-            else if (fct.equalsIgnoreCase("now"))
-            {
-                if (!arg.trim().isEmpty())
-                    throw new MarshalException(String.format("The 'now' timeuuid method takes
no argument ('%s' provided)", arg));
-
-                idBytes = ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes());
-            }
-            else
-            {
-                throw new MarshalException(String.format("Unknown timeuuid method '%s'",
fct));
-            }
+            throw new MarshalException(String.format("Unknown timeuuid representation: %s",
source));
         }
-
         return idBytes;
     }
 
@@ -216,11 +184,6 @@ public class TimeUUIDType extends AbstractType<UUID>
         }
     }
 
-    public Set<Term.Type> supportedCQL3Constants()
-    {
-        return supportedCQL3Constants;
-    }
-
     public CQL3Type asCQL3Type()
     {
         return CQL3Type.Native.TIMEUUID;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/31e669ab/src/java/org/apache/cassandra/db/marshal/UTF8Type.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/UTF8Type.java b/src/java/org/apache/cassandra/db/marshal/UTF8Type.java
index 5e05a3f..f3ca98b 100644
--- a/src/java/org/apache/cassandra/db/marshal/UTF8Type.java
+++ b/src/java/org/apache/cassandra/db/marshal/UTF8Type.java
@@ -18,19 +18,15 @@
 package org.apache.cassandra.db.marshal;
 
 import java.nio.ByteBuffer;
-import java.util.EnumSet;
-import java.util.Set;
 
 import org.apache.cassandra.cql.jdbc.JdbcUTF8;
+import org.apache.cassandra.cql3.Constants;
 import org.apache.cassandra.cql3.CQL3Type;
-import org.apache.cassandra.cql3.Term;
 
 public class UTF8Type extends AbstractType<String>
 {
     public static final UTF8Type instance = new UTF8Type();
 
-    private final Set<Term.Type> supportedCQL3Constants = EnumSet.of(Term.Type.STRING);
-
     UTF8Type() {} // singleton
 
     public String compose(ByteBuffer bytes)
@@ -197,11 +193,6 @@ public class UTF8Type extends AbstractType<String>
         return this == previous || previous == AsciiType.instance;
     }
 
-    public Set<Term.Type> supportedCQL3Constants()
-    {
-        return supportedCQL3Constants;
-    }
-
     public CQL3Type asCQL3Type()
     {
         return CQL3Type.Native.TEXT;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/31e669ab/src/java/org/apache/cassandra/db/marshal/UUIDType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/UUIDType.java b/src/java/org/apache/cassandra/db/marshal/UUIDType.java
index 427326b..0221abd 100644
--- a/src/java/org/apache/cassandra/db/marshal/UUIDType.java
+++ b/src/java/org/apache/cassandra/db/marshal/UUIDType.java
@@ -20,13 +20,10 @@ package org.apache.cassandra.db.marshal;
 
 import java.nio.ByteBuffer;
 import java.text.ParseException;
-import java.util.EnumSet;
-import java.util.Set;
 import java.util.UUID;
 
 import org.apache.cassandra.cql.jdbc.JdbcUUID;
 import org.apache.cassandra.cql3.CQL3Type;
-import org.apache.cassandra.cql3.Term;
 import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.UUIDGen;
@@ -48,8 +45,6 @@ public class UUIDType extends AbstractType<UUID>
 {
     public static final UUIDType instance = new UUIDType();
 
-    private final Set<Term.Type> supportedCQL3Constants = EnumSet.of(Term.Type.UUID);
-
     UUIDType()
     {
     }
@@ -249,11 +244,6 @@ public class UUIDType extends AbstractType<UUID>
         return idBytes;
     }
 
-    public Set<Term.Type> supportedCQL3Constants()
-    {
-        return supportedCQL3Constants;
-    }
-
     public CQL3Type asCQL3Type()
     {
         return CQL3Type.Native.UUID;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/31e669ab/src/java/org/apache/cassandra/dht/Murmur3Partitioner.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/dht/Murmur3Partitioner.java b/src/java/org/apache/cassandra/dht/Murmur3Partitioner.java
index fa0c630..a969320 100644
--- a/src/java/org/apache/cassandra/dht/Murmur3Partitioner.java
+++ b/src/java/org/apache/cassandra/dht/Murmur3Partitioner.java
@@ -163,7 +163,7 @@ public class Murmur3Partitioner extends AbstractPartitioner<LongToken>
 
         public Token<Long> fromByteArray(ByteBuffer bytes)
         {
-            return new LongToken(bytes.getLong());
+            return new LongToken(ByteBufferUtil.toLong(bytes));
         }
 
         public String toString(Token<Long> longToken)


Mime
View raw message