Merge branch cassandra-3.0 into trunk

This commit is contained in:
blerer 2015-09-11 11:23:56 +02:00
commit 492507de65
5 changed files with 42 additions and 0 deletions

View File

@ -27,6 +27,7 @@ import org.apache.cassandra.cql3.ColumnSpecification;
import org.apache.cassandra.cql3.functions.Function;
import org.apache.cassandra.cql3.selection.Selection.ResultSetBuilder;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.ReversedType;
import org.apache.cassandra.exceptions.InvalidRequestException;
/**
@ -180,6 +181,9 @@ public abstract class Selector implements AssignmentTestable
if (getType().isFrozenCollection())
receiverType = receiverType.freeze();
if (getType().isReversed())
receiverType = ReversedType.getInstance(receiverType);
if (receiverType.equals(getType()))
return AssignmentTestable.TestResult.EXACT_MATCH;

View File

@ -225,6 +225,11 @@ public abstract class AbstractType<T> implements Comparator<ByteBuffer>
return isCollection() && !isMultiCell();
}
public boolean isReversed()
{
return false;
}
public static AbstractType<?> parseDefaultParameters(AbstractType<?> baseType, TypeParser parser) throws SyntaxException
{
Map<String, String> parameters = parser.getKeyValueParameters();

View File

@ -141,6 +141,12 @@ public class ReversedType<T> extends AbstractType<T>
return baseType.valueLengthIfFixed();
}
@Override
public boolean isReversed()
{
return true;
}
@Override
public String toString()
{

View File

@ -423,6 +423,21 @@ public class UFTest extends CQLTester
assertEmpty(execute("SELECT v FROM %s WHERE v=" + fRepeat + "(?, ?)", "a", 2));
}
@Test
public void testFunctionExecutionWithReversedTypeAsOutput() throws Throwable
{
createTable("CREATE TABLE %s (k int, v text, PRIMARY KEY(k, v)) WITH CLUSTERING ORDER BY (v DESC)");
String fRepeat = createFunction(KEYSPACE_PER_TEST, "text",
"CREATE FUNCTION %s(v text) " +
"RETURNS NULL ON NULL INPUT " +
"RETURNS text " +
"LANGUAGE java " +
"AS 'return v + v;'");
execute("INSERT INTO %s(k, v) VALUES (?, " + fRepeat + "(?))", 1, "a");
}
@Test
public void testFunctionOverloading() throws Throwable
{

View File

@ -276,6 +276,18 @@ public class AggregationTest extends CQLTester
assertInvalidSyntax("SELECT COUNT(2) FROM %s");
}
@Test
public void testReversedType() throws Throwable
{
createTable("CREATE TABLE %s (a int, b int, c int, primary key (a, b)) WITH CLUSTERING ORDER BY (b DESC)");
execute("INSERT INTO %s (a, b, c) VALUES (1, 1, 10)");
execute("INSERT INTO %s (a, b, c) VALUES (1, 2, 9)");
execute("INSERT INTO %s (a, b, c) VALUES (1, 3, 8)");
execute("INSERT INTO %s (a, b, c) VALUES (1, 4, 7)");
assertRows(execute("SELECT max(c), min(c), avg(c) FROM %s WHERE a = 1 AND b > 1"), row(9, 7, 8));
}
@Test
public void testNestedFunctions() throws Throwable
{