Merge branch 'cassandra-2.0' into cassandra-2.1
Conflicts:
src/java/org/apache/cassandra/cql3/TypeCast.java
src/java/org/apache/cassandra/cql3/statements/Selection.java
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/9dcdb8b0
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/9dcdb8b0
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/9dcdb8b0
Branch: refs/heads/trunk
Commit: 9dcdb8b0b5bb5c92986b16380d650373c7f819d6
Parents: 2fe6de6 9da742d
Author: Tyler Hobbs <[email protected]>
Authored: Fri Jun 20 12:00:20 2014 -0500
Committer: Tyler Hobbs <[email protected]>
Committed: Fri Jun 20 12:00:20 2014 -0500
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../org/apache/cassandra/cql3/TypeCast.java | 2 +-
.../cassandra/cql3/functions/FunctionCall.java | 2 +-
.../cassandra/cql3/functions/Functions.java | 4 +-
.../cassandra/cql3/statements/Selection.java | 2 +-
.../cassandra/db/marshal/AbstractType.java | 23 +++++++--
.../apache/cassandra/db/marshal/BytesType.java | 2 +-
.../cassandra/db/marshal/CompositeType.java | 8 +--
.../apache/cassandra/db/marshal/DateType.java | 6 +++
.../cassandra/db/marshal/IntegerType.java | 6 +++
.../apache/cassandra/db/marshal/LongType.java | 6 +++
.../cassandra/db/marshal/ReversedType.java | 6 +++
.../cassandra/db/marshal/TimestampType.java | 6 +++
.../apache/cassandra/db/marshal/TupleType.java | 6 +--
.../apache/cassandra/db/marshal/UUIDType.java | 6 +++
.../org/apache/cassandra/cql3/TypeTest.java | 51 ++++++++++++++++++++
16 files changed, 119 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/9dcdb8b0/CHANGES.txt
----------------------------------------------------------------------
diff --cc CHANGES.txt
index 7288de6,dac254e..d7cb9ee
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@@ -1,30 -1,25 +1,31 @@@
-2.0.9
- * Fix assertion error in CL.ANY timeout handling (CASSANDRA-7364)
- * Handle empty CFs in Memtable#maybeUpdateLiveRatio() (CASSANDRA-7401)
+2.1.0-rc2
+ * Modify reconcile logic to always pick a tombstone over a counter cell
+ (CASSANDRA-7346)
+ * Avoid incremental compaction on Windows (CASSANDRA-7365)
+ * Fix exception when querying a composite-keyed table with a collection index
+ (CASSANDRA-7372)
+ * Use node's host id in place of counter ids (CASSANDRA-7366)
* Fix native protocol CAS batches (CASSANDRA-7337)
+ * Reduce likelihood of contention on local paxos locking (CASSANDRA-7359)
+ * Upgrade to Pig 0.12.1 (CASSANDRA-6556)
+ * Make sure we clear out repair sessions from netstats (CASSANDRA-7329)
+ * Don't fail streams on failure detector downs (CASSANDRA-3569)
+ * Add optional keyspace to DROP INDEX statement (CASSANDRA-7314)
+ * Reduce run time for CQL tests (CASSANDRA-7327)
+ * Fix heap size calculation on Windows (CASSANDRA-7352, 7353)
+ * RefCount native frames from netty (CASSANDRA-7245)
+ * Use tarball dir instead of /var for default paths (CASSANDRA-7136)
+ * Remove rows_per_partition_to_cache keyword (CASSANDRA-7193)
+ * Fix schema change response in native protocol v3 (CASSANDRA-7413)
+Merged from 2.0:
+ * Fix assertion error in CL.ANY timeout handling (CASSANDRA-7364)
* Add per-CF range read request latency metrics (CASSANDRA-7338)
* Fix NPE in StreamTransferTask.createMessageForRetry() (CASSANDRA-7323)
- * Add conditional CREATE/DROP USER support (CASSANDRA-7264)
- * Swap local and global default read repair chances (CASSANDRA-7320)
- * Add missing iso8601 patterns for date strings (CASSANDRA-6973)
- * Support selecting multiple rows in a partition using IN (CASSANDRA-6875)
- * cqlsh: always emphasize the partition key in DESC output (CASSANDRA-7274)
- * Copy compaction options to make sure they are reloaded (CASSANDRA-7290)
- * Add option to do more aggressive tombstone compactions (CASSANDRA-6563)
- * Don't try to compact already-compacting files in HHOM (CASSANDRA-7288)
- * Add authentication support to shuffle (CASSANDRA-6484)
- * Cqlsh counts non-empty lines for "Blank lines" warning (CASSANDRA-7325)
* Make StreamSession#closeSession() idempotent (CASSANDRA-7262)
* Fix infinite loop on exception while streaming (CASSANDRA-7330)
- * Reference sstables before populating key cache (CASSANDRA-7234)
* Account for range tombstones in min/max column names (CASSANDRA-7235)
* Improve sub range repair validation (CASSANDRA-7317)
+ * Accept subtypes for function results, type casts (CASSANDRA-6766)
Merged from 1.2:
* Handle possible integer overflow in FastByteArrayOutputStream
(CASSANDRA-7373)
* cqlsh: 'ascii' values weren't formatted as text (CASSANDRA-7407)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/9dcdb8b0/src/java/org/apache/cassandra/cql3/TypeCast.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/cql3/TypeCast.java
index 45e8c5b,64261fa..e325e4d
--- a/src/java/org/apache/cassandra/cql3/TypeCast.java
+++ b/src/java/org/apache/cassandra/cql3/TypeCast.java
@@@ -30,32 -30,25 +30,32 @@@ public class TypeCast implements Term.R
this.term = term;
}
- public Term prepare(ColumnSpecification receiver) throws
InvalidRequestException
+ public Term prepare(String keyspace, ColumnSpecification receiver) throws
InvalidRequestException
{
- if (!term.isAssignableTo(castedSpecOf(receiver)))
+ if (!term.isAssignableTo(keyspace, castedSpecOf(keyspace, receiver)))
throw new InvalidRequestException(String.format("Cannot cast
value %s to type %s", term, type));
- if (!isAssignableTo(receiver))
+ if (!isAssignableTo(keyspace, receiver))
throw new InvalidRequestException(String.format("Cannot assign
value %s to %s of type %s", this, receiver, receiver.type.asCQL3Type()));
- return term.prepare(receiver);
+ return term.prepare(keyspace, receiver);
}
- private ColumnSpecification castedSpecOf(ColumnSpecification receiver)
+ private ColumnSpecification castedSpecOf(String keyspace,
ColumnSpecification receiver) throws InvalidRequestException
{
- return new ColumnSpecification(receiver.ksName, receiver.cfName, new
ColumnIdentifier(toString(), true), type.getType());
+ return new ColumnSpecification(receiver.ksName, receiver.cfName, new
ColumnIdentifier(toString(), true), type.prepare(keyspace).getType());
}
- public boolean isAssignableTo(ColumnSpecification receiver)
+ public boolean isAssignableTo(String keyspace, ColumnSpecification
receiver) throws InvalidRequestException
{
- return receiver.type.isValueCompatibleWith(type.getType());
+ try
+ {
- return receiver.type.asCQL3Type().equals(type.prepare(keyspace));
++ return
receiver.type.isValueCompatibleWith(type.prepare(keyspace).getType());
+ }
+ catch (InvalidRequestException e)
+ {
+ throw new AssertionError();
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/cassandra/blob/9dcdb8b0/src/java/org/apache/cassandra/cql3/functions/FunctionCall.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/9dcdb8b0/src/java/org/apache/cassandra/cql3/functions/Functions.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/cql3/functions/Functions.java
index 72aac3f,4f108cb..605e7b3
--- a/src/java/org/apache/cassandra/cql3/functions/Functions.java
+++ b/src/java/org/apache/cassandra/cql3/functions/Functions.java
@@@ -109,9 -109,9 +109,9 @@@ public abstract class Function
return candidate;
}
- private static void validateTypes(Function fun, List<? extends
AssignementTestable> providedArgs, ColumnSpecification receiver) throws
InvalidRequestException
+ private static void validateTypes(String keyspace, Function fun, List<?
extends AssignementTestable> providedArgs, ColumnSpecification receiver) throws
InvalidRequestException
{
- if (!receiver.type.asCQL3Type().equals(fun.returnType().asCQL3Type()))
+ if (!receiver.type.isValueCompatibleWith(fun.returnType()))
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())
@@@ -132,9 -132,9 +132,9 @@@
}
}
- private static boolean isValidType(Function fun, List<? extends
AssignementTestable> providedArgs, ColumnSpecification receiver)
+ private static boolean isValidType(String keyspace, Function fun, List<?
extends AssignementTestable> providedArgs, ColumnSpecification receiver) throws
InvalidRequestException
{
- if (!receiver.type.asCQL3Type().equals(fun.returnType().asCQL3Type()))
+ if (!receiver.type.isValueCompatibleWith(fun.returnType()))
return false;
if (providedArgs.size() != fun.argsType().size())
http://git-wip-us.apache.org/repos/asf/cassandra/blob/9dcdb8b0/src/java/org/apache/cassandra/cql3/statements/Selection.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/cql3/statements/Selection.java
index f4e0885,37ab384..dc31dde
--- a/src/java/org/apache/cassandra/cql3/statements/Selection.java
+++ b/src/java/org/apache/cassandra/cql3/statements/Selection.java
@@@ -370,18 -344,12 +370,18 @@@ public abstract class Selectio
}
}
- private interface Selector extends AssignementTestable
+ private static abstract class Selector implements AssignementTestable
{
- public ByteBuffer compute(ResultSetBuilder rs) throws
InvalidRequestException;
+ public abstract ByteBuffer compute(ResultSetBuilder rs) throws
InvalidRequestException;
+ public abstract AbstractType<?> getType();
+
+ public boolean isAssignableTo(String keyspace, ColumnSpecification
receiver)
+ {
- return getType().asCQL3Type().equals(receiver.type.asCQL3Type());
++ return receiver.type.isValueCompatibleWith(getType());
+ }
}
- private static class SimpleSelector implements Selector
+ private static class SimpleSelector extends Selector
{
private final String columnName;
private final int idx;
http://git-wip-us.apache.org/repos/asf/cassandra/blob/9dcdb8b0/src/java/org/apache/cassandra/db/marshal/AbstractType.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/9dcdb8b0/src/java/org/apache/cassandra/db/marshal/BytesType.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/9dcdb8b0/src/java/org/apache/cassandra/db/marshal/CompositeType.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/9dcdb8b0/src/java/org/apache/cassandra/db/marshal/DateType.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/db/marshal/DateType.java
index 7003097,bf25d88..882e4cf
--- a/src/java/org/apache/cassandra/db/marshal/DateType.java
+++ b/src/java/org/apache/cassandra/db/marshal/DateType.java
@@@ -74,12 -81,13 +74,18 @@@ public class DateType extends AbstractT
return false;
}
+ public boolean isByteOrderComparable()
+ {
+ return true;
+ }
+
@Override
+ public boolean isValueCompatibleWithInternal(AbstractType<?> otherType)
+ {
+ return this == otherType || otherType == TimestampType.instance ||
otherType == LongType.instance;
+ }
+
+ @Override
public CQL3Type asCQL3Type()
{
return CQL3Type.Native.TIMESTAMP;
http://git-wip-us.apache.org/repos/asf/cassandra/blob/9dcdb8b0/src/java/org/apache/cassandra/db/marshal/LongType.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/9dcdb8b0/src/java/org/apache/cassandra/db/marshal/ReversedType.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/9dcdb8b0/src/java/org/apache/cassandra/db/marshal/TupleType.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/9dcdb8b0/src/java/org/apache/cassandra/db/marshal/UUIDType.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/9dcdb8b0/test/unit/org/apache/cassandra/cql3/TypeTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/cql3/TypeTest.java
index 0000000,f911a44..f22d49b
mode 000000,100644..100644
--- a/test/unit/org/apache/cassandra/cql3/TypeTest.java
+++ b/test/unit/org/apache/cassandra/cql3/TypeTest.java
@@@ -1,0 -1,144 +1,51 @@@
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ package org.apache.cassandra.cql3;
+
-import org.apache.cassandra.SchemaLoader;
-import org.apache.cassandra.db.ConsistencyLevel;
-import org.apache.cassandra.exceptions.RequestExecutionException;
-import org.apache.cassandra.exceptions.RequestValidationException;
-import org.apache.cassandra.gms.Gossiper;
-import org.apache.cassandra.service.ClientState;
-import org.apache.cassandra.service.QueryState;
-import org.apache.cassandra.transport.messages.ResultMessage;
-import org.apache.cassandra.utils.MD5Digest;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+ import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.apache.cassandra.cql3.QueryProcessor.process;
-import static org.apache.cassandra.cql3.QueryProcessor.processInternal;
+ import static org.junit.Assert.assertEquals;
+
-public class TypeTest
++public class TypeTest extends CQLTester
+ {
- private static final Logger logger =
LoggerFactory.getLogger(TypeTest.class);
- static ClientState clientState;
- static String keyspace = "cql3_type_test";
-
- @BeforeClass
- public static void setUpClass() throws Throwable
- {
- SchemaLoader.loadSchema();
- executeSchemaChange("CREATE KEYSPACE IF NOT EXISTS %s WITH
replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}");
- clientState = ClientState.forInternalCalls();
- }
-
- @AfterClass
- public static void stopGossiper()
- {
- Gossiper.instance.stop();
- }
-
- private static void executeSchemaChange(String query) throws Throwable
- {
- try
- {
- process(String.format(query, keyspace), ConsistencyLevel.ONE);
- } catch (RuntimeException exc)
- {
- throw exc.getCause();
- }
- }
-
- private static UntypedResultSet execute(String query) throws Throwable
- {
- try
- {
- return processInternal(String.format(query, keyspace));
- } catch (RuntimeException exc)
- {
- if (exc.getCause() != null)
- throw exc.getCause();
- throw exc;
- }
- }
-
- private MD5Digest prepare(String query) throws RequestValidationException
- {
- ResultMessage.Prepared prepared =
QueryProcessor.prepare(String.format(query, keyspace), clientState, false);
- return prepared.statementId;
- }
-
- private UntypedResultSet executePrepared(MD5Digest statementId,
QueryOptions options) throws RequestValidationException,
RequestExecutionException
- {
- CQLStatement statement =
QueryProcessor.instance.getPrepared(statementId);
- ResultMessage message =
statement.executeInternal(QueryState.forInternalCalls(), options);
-
- if (message instanceof ResultMessage.Rows)
- return new UntypedResultSet(((ResultMessage.Rows)message).result);
- else
- return null;
- }
-
+ @Test
+ public void testNowToUUIDCompatibility() throws Throwable
+ {
- executeSchemaChange("CREATE TABLE IF NOT EXISTS %s.uuid_now (a int, b
uuid, PRIMARY KEY (a, b))");
- String insert = "INSERT INTO %s.uuid_now (a, b) VALUES (0, now())";
- String select = "SELECT * FROM %s.uuid_now WHERE a=0 AND b < now()";
- execute(insert);
- UntypedResultSet results = execute(select);
++ createTable("CREATE TABLE %s (a int, b uuid, PRIMARY KEY (a, b))");
++ execute("INSERT INTO %s (a, b) VALUES (0, now())");
++ UntypedResultSet results = execute("SELECT * FROM %s WHERE a=0 AND b
< now()");
+ assertEquals(1, results.size());
-
- executePrepared(prepare(insert), QueryOptions.DEFAULT);
- results = executePrepared(prepare(select), QueryOptions.DEFAULT);
- assertEquals(2, results.size());
+ }
+
+ @Test
+ public void testDateCompatibility() throws Throwable
+ {
- executeSchemaChange("CREATE TABLE IF NOT EXISTS %s.date_compatibility
(a int, b timestamp, c bigint, d varint, PRIMARY KEY (a, b, c, d))");
- String insert = "INSERT INTO %s.date_compatibility (a, b, c, d)
VALUES (0, unixTimestampOf(now()), dateOf(now()), dateOf(now()))";
- String select = "SELECT * FROM %s.date_compatibility WHERE a=0 AND b
< unixTimestampOf(now())";
- execute(insert);
- UntypedResultSet results = execute(select);
++ createTable("CREATE TABLE %s (a int, b timestamp, c bigint, d varint,
PRIMARY KEY (a, b, c, d))");
++ execute("INSERT INTO %s (a, b, c, d) VALUES (0,
unixTimestampOf(now()), dateOf(now()), dateOf(now()))");
++ UntypedResultSet results = execute("SELECT * FROM %s WHERE a=0 AND b
< unixTimestampOf(now())");
+ assertEquals(1, results.size());
-
- executePrepared(prepare(insert), QueryOptions.DEFAULT);
- results = executePrepared(prepare(select), QueryOptions.DEFAULT);
- assertEquals(2, results.size());
+ }
+
+ @Test
+ public void testReversedTypeCompatibility() throws Throwable
+ {
- executeSchemaChange("CREATE TABLE IF NOT EXISTS %s.uuid_now_reversed
(a int, b timeuuid, PRIMARY KEY (a, b)) WITH CLUSTERING ORDER BY (b DESC)");
- String insert = "INSERT INTO %s.uuid_now_reversed (a, b) VALUES (0,
now())";
- String select = "SELECT * FROM %s.uuid_now_reversed WHERE a=0 AND b <
now()";
- execute(insert);
- UntypedResultSet results = execute(select);
++ createTable("CREATE TABLE %s (a int, b timeuuid, PRIMARY KEY (a, b))
WITH CLUSTERING ORDER BY (b DESC)");
++ execute("INSERT INTO %s (a, b) VALUES (0, now())");
++ UntypedResultSet results = execute("SELECT * FROM %s WHERE a=0 AND b
< now()");
+ assertEquals(1, results.size());
-
- executePrepared(prepare(insert), QueryOptions.DEFAULT);
- results = executePrepared(prepare(select), QueryOptions.DEFAULT);
- assertEquals(2, results.size());
+ }
+ }