mirror of https://github.com/apache/cassandra
Merge branch cassandra-3.0 into cassandra-3.9
This commit is contained in:
commit
cb97649f51
|
|
@ -99,6 +99,7 @@ Merged from 2.2:
|
|||
* Improve streaming synchronization and fault tolerance (CASSANDRA-11414)
|
||||
* MemoryUtil.getShort() should return an unsigned short also for architectures not supporting unaligned memory accesses (CASSANDRA-11973)
|
||||
Merged from 2.1:
|
||||
* Fix queries with empty ByteBuffer values in clustering column restrictions (CASSANDRA-12127)
|
||||
* Disable passing control to post-flush after flush failure to prevent data loss (CASSANDRA-11828)
|
||||
* Allow STCS-in-L0 compactions to reduce scope with LCS (CASSANDRA-12040)
|
||||
* cannot use cql since upgrading python to 2.7.11+ (CASSANDRA-11850)
|
||||
|
|
|
|||
9
NEWS.txt
9
NEWS.txt
|
|
@ -13,6 +13,15 @@ restore snapshots created with the previous major version using the
|
|||
'sstableloader' tool. You can upgrade the file format of your snapshots
|
||||
using the provided 'sstableupgrade' tool.
|
||||
|
||||
3.9
|
||||
===
|
||||
|
||||
Upgrading
|
||||
---------
|
||||
- The ReversedType behaviour has been corrected for clustering columns of
|
||||
BYTES type containing empty value. Scrub should be run on the existing
|
||||
SSTables containing a descending clustering column of BYTES type to correct
|
||||
their ordering. See CASSANDRA-12127 for more details.
|
||||
|
||||
3.8
|
||||
===
|
||||
|
|
|
|||
|
|
@ -19,10 +19,6 @@ package org.apache.cassandra.db;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.config.ColumnDefinition;
|
||||
import org.apache.cassandra.utils.memory.AbstractAllocator;
|
||||
|
||||
/**
|
||||
* The clustering column values for a row.
|
||||
* <p>
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ public abstract class AbstractSSTableIterator implements UnfilteredRowIterator
|
|||
private boolean isClosed;
|
||||
|
||||
protected final Slices slices;
|
||||
protected int slice;
|
||||
|
||||
@SuppressWarnings("resource") // We need this because the analysis is not able to determine that we do close
|
||||
// file on every path where we created it.
|
||||
|
|
@ -120,7 +119,7 @@ public abstract class AbstractSSTableIterator implements UnfilteredRowIterator
|
|||
}
|
||||
|
||||
if (reader != null && !slices.isEmpty())
|
||||
reader.setForSlice(slices.get(0));
|
||||
reader.setForSlice(nextSlice());
|
||||
|
||||
if (reader == null && file != null && shouldCloseFile)
|
||||
file.close();
|
||||
|
|
@ -145,6 +144,23 @@ public abstract class AbstractSSTableIterator implements UnfilteredRowIterator
|
|||
}
|
||||
}
|
||||
|
||||
private Slice nextSlice()
|
||||
{
|
||||
return slices.get(nextSliceIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the next slice to process.
|
||||
* @return the index of the next slice to process
|
||||
*/
|
||||
protected abstract int nextSliceIndex();
|
||||
|
||||
/**
|
||||
* Checks if there are more slice to process.
|
||||
* @return {@code true} if there are more slice to process, {@code false} otherwise.
|
||||
*/
|
||||
protected abstract boolean hasMoreSlices();
|
||||
|
||||
private static Row readStaticRow(SSTableReader sstable,
|
||||
FileDataInput file,
|
||||
SerializationHelper helper,
|
||||
|
|
@ -241,10 +257,10 @@ public abstract class AbstractSSTableIterator implements UnfilteredRowIterator
|
|||
if (reader.hasNext())
|
||||
return true;
|
||||
|
||||
if (++slice >= slices.size())
|
||||
if (!hasMoreSlices())
|
||||
return false;
|
||||
|
||||
slice(slices.get(slice));
|
||||
slice(nextSlice());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,11 @@ import org.apache.cassandra.io.util.SegmentedFile;
|
|||
*/
|
||||
public class SSTableIterator extends AbstractSSTableIterator
|
||||
{
|
||||
/**
|
||||
* The index of the slice being processed.
|
||||
*/
|
||||
private int slice;
|
||||
|
||||
public SSTableIterator(SSTableReader sstable,
|
||||
FileDataInput file,
|
||||
DecoratedKey key,
|
||||
|
|
@ -51,6 +56,18 @@ public class SSTableIterator extends AbstractSSTableIterator
|
|||
: new ForwardReader(file, shouldCloseFile);
|
||||
}
|
||||
|
||||
protected int nextSliceIndex()
|
||||
{
|
||||
int next = slice;
|
||||
slice++;
|
||||
return next;
|
||||
}
|
||||
|
||||
protected boolean hasMoreSlices()
|
||||
{
|
||||
return slice < slices.size();
|
||||
}
|
||||
|
||||
public boolean isReverseOrder()
|
||||
{
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -35,6 +35,11 @@ import org.apache.cassandra.utils.btree.BTree;
|
|||
*/
|
||||
public class SSTableReversedIterator extends AbstractSSTableIterator
|
||||
{
|
||||
/**
|
||||
* The index of the slice being processed.
|
||||
*/
|
||||
private int slice;
|
||||
|
||||
public SSTableReversedIterator(SSTableReader sstable,
|
||||
FileDataInput file,
|
||||
DecoratedKey key,
|
||||
|
|
@ -59,6 +64,18 @@ public class SSTableReversedIterator extends AbstractSSTableIterator
|
|||
return true;
|
||||
}
|
||||
|
||||
protected int nextSliceIndex()
|
||||
{
|
||||
int next = slice;
|
||||
slice++;
|
||||
return slices.size() - (next + 1);
|
||||
}
|
||||
|
||||
protected boolean hasMoreSlices()
|
||||
{
|
||||
return slice < slices.size();
|
||||
}
|
||||
|
||||
private class ReverseReader extends Reader
|
||||
{
|
||||
protected ReusablePartitionData buffer;
|
||||
|
|
@ -106,7 +123,7 @@ public class SSTableReversedIterator extends AbstractSSTableIterator
|
|||
buffer = createBuffer(1);
|
||||
// Note that we can reuse that buffer between slices (we could alternatively re-read from disk
|
||||
// every time, but that feels more wasteful) so we want to include everything from the beginning.
|
||||
// We can stop at the slice end however since any following slice will be before that.
|
||||
// We can stop at the last slice end however since any following slice will be before that.
|
||||
loadFromDisk(null, slice.end(), true);
|
||||
}
|
||||
setIterator(slice);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import java.util.*;
|
|||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
import org.apache.cassandra.config.CFMetaData;
|
||||
import org.apache.cassandra.db.*;
|
||||
import org.apache.cassandra.db.lifecycle.LifecycleTransaction;
|
||||
import org.apache.cassandra.db.rows.*;
|
||||
|
|
@ -210,21 +211,8 @@ public class Scrubber implements Closeable
|
|||
if (indexFile != null && dataStart != dataStartFromIndex)
|
||||
outputHandler.warn(String.format("Data file row position %d differs from index file row position %d", dataStart, dataStartFromIndex));
|
||||
|
||||
try (UnfilteredRowIterator iterator = withValidation(new RowMergingSSTableIterator(sstable, dataFile, key), dataFile.getPath()))
|
||||
{
|
||||
if (prevKey != null && prevKey.compareTo(key) > 0)
|
||||
{
|
||||
saveOutOfOrderRow(prevKey, key, iterator);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (writer.tryAppend(iterator) == null)
|
||||
emptyRows++;
|
||||
else
|
||||
goodRows++;
|
||||
}
|
||||
|
||||
prevKey = key;
|
||||
if (tryAppend(prevKey, key, writer))
|
||||
prevKey = key;
|
||||
}
|
||||
catch (Throwable th)
|
||||
{
|
||||
|
|
@ -241,21 +229,8 @@ public class Scrubber implements Closeable
|
|||
{
|
||||
dataFile.seek(dataStartFromIndex);
|
||||
|
||||
try (UnfilteredRowIterator iterator = withValidation(new SSTableIdentityIterator(sstable, dataFile, key), dataFile.getPath()))
|
||||
{
|
||||
if (prevKey != null && prevKey.compareTo(key) > 0)
|
||||
{
|
||||
saveOutOfOrderRow(prevKey, key, iterator);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (writer.tryAppend(iterator) == null)
|
||||
emptyRows++;
|
||||
else
|
||||
goodRows++;
|
||||
}
|
||||
|
||||
prevKey = key;
|
||||
if (tryAppend(prevKey, key, writer))
|
||||
prevKey = key;
|
||||
}
|
||||
catch (Throwable th2)
|
||||
{
|
||||
|
|
@ -324,6 +299,38 @@ public class Scrubber implements Closeable
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
private boolean tryAppend(DecoratedKey prevKey, DecoratedKey key, SSTableRewriter writer)
|
||||
{
|
||||
// OrderCheckerIterator will check, at iteration time, that the rows are in the proper order. If it detects
|
||||
// that one row is out of order, it will stop returning them. The remaining rows will be sorted and added
|
||||
// to the outOfOrder set that will be later written to a new SSTable.
|
||||
OrderCheckerIterator sstableIterator = new OrderCheckerIterator(new RowMergingSSTableIterator(sstable, dataFile, key),
|
||||
cfs.metadata.comparator);
|
||||
|
||||
try (UnfilteredRowIterator iterator = withValidation(sstableIterator, dataFile.getPath()))
|
||||
{
|
||||
if (prevKey != null && prevKey.compareTo(key) > 0)
|
||||
{
|
||||
saveOutOfOrderRow(prevKey, key, iterator);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (writer.tryAppend(iterator) == null)
|
||||
emptyRows++;
|
||||
else
|
||||
goodRows++;
|
||||
}
|
||||
|
||||
if (sstableIterator.hasRowsOutOfOrder())
|
||||
{
|
||||
outputHandler.warn(String.format("Out of order rows found in partition: %s", key));
|
||||
outOfOrder.add(sstableIterator.getRowsOutOfOrder());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateIndexKey()
|
||||
{
|
||||
currentIndexKey = nextIndexKey;
|
||||
|
|
@ -506,4 +513,106 @@ public class Scrubber implements Closeable
|
|||
return next;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* In some case like CASSANDRA-12127 the cells might have been stored in the wrong order. This decorator check the
|
||||
* cells order and collect the out of order cells to correct the problem.
|
||||
*/
|
||||
private static final class OrderCheckerIterator extends AbstractIterator<Unfiltered> implements UnfilteredRowIterator
|
||||
{
|
||||
/**
|
||||
* The decorated iterator.
|
||||
*/
|
||||
private final UnfilteredRowIterator iterator;
|
||||
|
||||
private final ClusteringComparator comparator;
|
||||
|
||||
private Unfiltered previous;
|
||||
|
||||
/**
|
||||
* The partition containing the rows which are out of order.
|
||||
*/
|
||||
private Partition rowsOutOfOrder;
|
||||
|
||||
public OrderCheckerIterator(UnfilteredRowIterator iterator, ClusteringComparator comparator)
|
||||
{
|
||||
this.iterator = iterator;
|
||||
this.comparator = comparator;
|
||||
}
|
||||
|
||||
public CFMetaData metadata()
|
||||
{
|
||||
return iterator.metadata();
|
||||
}
|
||||
|
||||
public boolean isReverseOrder()
|
||||
{
|
||||
return iterator.isReverseOrder();
|
||||
}
|
||||
|
||||
public PartitionColumns columns()
|
||||
{
|
||||
return iterator.columns();
|
||||
}
|
||||
|
||||
public DecoratedKey partitionKey()
|
||||
{
|
||||
return iterator.partitionKey();
|
||||
}
|
||||
|
||||
public Row staticRow()
|
||||
{
|
||||
return iterator.staticRow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return iterator.isEmpty();
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
iterator.close();
|
||||
}
|
||||
|
||||
public DeletionTime partitionLevelDeletion()
|
||||
{
|
||||
return iterator.partitionLevelDeletion();
|
||||
}
|
||||
|
||||
public EncodingStats stats()
|
||||
{
|
||||
return iterator.stats();
|
||||
}
|
||||
|
||||
public boolean hasRowsOutOfOrder()
|
||||
{
|
||||
return rowsOutOfOrder != null;
|
||||
}
|
||||
|
||||
public Partition getRowsOutOfOrder()
|
||||
{
|
||||
return rowsOutOfOrder;
|
||||
}
|
||||
|
||||
protected Unfiltered computeNext()
|
||||
{
|
||||
if (!iterator.hasNext())
|
||||
return endOfData();
|
||||
|
||||
Unfiltered next = iterator.next();
|
||||
|
||||
// If we detect that some rows are out of order we will store and sort the remaining ones to insert them
|
||||
// in a separate SSTable.
|
||||
if (previous != null && comparator.compare(next, previous) < 0)
|
||||
{
|
||||
rowsOutOfOrder = ImmutableBTreePartition.create(UnfilteredRowIterators.concat(next, iterator), false);
|
||||
return endOfData();
|
||||
}
|
||||
previous = next;
|
||||
return next;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,16 +68,6 @@ public class ReversedType<T> extends AbstractType<T>
|
|||
|
||||
public int compareCustom(ByteBuffer o1, ByteBuffer o2)
|
||||
{
|
||||
// An empty byte buffer is always smaller
|
||||
if (o1.remaining() == 0)
|
||||
{
|
||||
return o2.remaining() == 0 ? 0 : -1;
|
||||
}
|
||||
if (o2.remaining() == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return baseType.compare(o2, o1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -271,13 +271,18 @@ public abstract class AbstractBTreePartition implements Partition, Iterable<Row>
|
|||
}
|
||||
|
||||
protected static Holder build(UnfilteredRowIterator iterator, int initialRowCapacity)
|
||||
{
|
||||
return build(iterator, initialRowCapacity, true);
|
||||
}
|
||||
|
||||
protected static Holder build(UnfilteredRowIterator iterator, int initialRowCapacity, boolean ordered)
|
||||
{
|
||||
CFMetaData metadata = iterator.metadata();
|
||||
PartitionColumns columns = iterator.columns();
|
||||
boolean reversed = iterator.isReverseOrder();
|
||||
|
||||
BTree.Builder<Row> builder = BTree.builder(metadata.comparator, initialRowCapacity);
|
||||
builder.auto(false);
|
||||
builder.auto(!ordered);
|
||||
MutableDeletionInfo.Builder deletionBuilder = MutableDeletionInfo.builder(iterator.partitionLevelDeletion(), metadata.comparator, reversed);
|
||||
|
||||
while (iterator.hasNext())
|
||||
|
|
|
|||
|
|
@ -63,6 +63,21 @@ public class ImmutableBTreePartition extends AbstractBTreePartition
|
|||
return create(iterator, 16);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@code ImmutableBTreePartition} holding all the data of the provided iterator.
|
||||
*
|
||||
* Warning: Note that this method does not close the provided iterator and it is
|
||||
* up to the caller to do so.
|
||||
*
|
||||
* @param iterator the iterator to gather in memory.
|
||||
* @param ordered {@code true} if the iterator will return the rows in order, {@code false} otherwise.
|
||||
* @return the created partition.
|
||||
*/
|
||||
public static ImmutableBTreePartition create(UnfilteredRowIterator iterator, boolean ordered)
|
||||
{
|
||||
return create(iterator, 16, ordered);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@code ImmutableBTreePartition} holding all the data of the provided iterator.
|
||||
*
|
||||
|
|
@ -76,7 +91,24 @@ public class ImmutableBTreePartition extends AbstractBTreePartition
|
|||
*/
|
||||
public static ImmutableBTreePartition create(UnfilteredRowIterator iterator, int initialRowCapacity)
|
||||
{
|
||||
return new ImmutableBTreePartition(iterator.metadata(), iterator.partitionKey(), build(iterator, initialRowCapacity));
|
||||
return create(iterator, initialRowCapacity, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@code ImmutableBTreePartition} holding all the data of the provided iterator.
|
||||
*
|
||||
* Warning: Note that this method does not close the provided iterator and it is
|
||||
* up to the caller to do so.
|
||||
*
|
||||
* @param iterator the iterator to gather in memory.
|
||||
* @param initialRowCapacity sizing hint (in rows) to use for the created partition. It should ideally
|
||||
* correspond or be a good estimation of the number or rows in {@code iterator}.
|
||||
* @param ordered {@code true} if the iterator will return the rows in order, {@code false} otherwise.
|
||||
* @return the created partition.
|
||||
*/
|
||||
public static ImmutableBTreePartition create(UnfilteredRowIterator iterator, int initialRowCapacity, boolean ordered)
|
||||
{
|
||||
return new ImmutableBTreePartition(iterator.metadata(), iterator.partitionKey(), build(iterator, initialRowCapacity, ordered));
|
||||
}
|
||||
|
||||
protected Holder holder()
|
||||
|
|
|
|||
|
|
@ -229,6 +229,34 @@ public abstract class UnfilteredRowIterators
|
|||
return MoreRows.extend(iter1, new Extend());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator that concatenate the specified atom with the iterator.
|
||||
*/
|
||||
public static UnfilteredRowIterator concat(final Unfiltered first, final UnfilteredRowIterator rest)
|
||||
{
|
||||
return new WrappingUnfilteredRowIterator(rest)
|
||||
{
|
||||
private boolean hasReturnedFirst;
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return hasReturnedFirst ? super.hasNext() : true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Unfiltered next()
|
||||
{
|
||||
if (!hasReturnedFirst)
|
||||
{
|
||||
hasReturnedFirst = true;
|
||||
return first;
|
||||
}
|
||||
return super.next();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that the data of the provided iterator is valid, that is that the values
|
||||
* it contains are valid for the type they represent, and more generally that the
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ import org.apache.cassandra.utils.MD5Digest;
|
|||
import org.apache.cassandra.utils.Pair;
|
||||
|
||||
import static org.apache.cassandra.Util.throwAssert;
|
||||
import static org.apache.cassandra.utils.ByteBufferUtil.EMPTY_BYTE_BUFFER;
|
||||
import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
|
@ -1046,6 +1048,135 @@ public class SecondaryIndexTest extends CQLTester
|
|||
assertEmpty(execute("SELECT * FROM %s WHERE d = 3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithEmptyRestrictionValueAndSecondaryIndex() throws Throwable
|
||||
{
|
||||
createTable("CREATE TABLE %s (pk blob, c blob, v blob, PRIMARY KEY ((pk), c))");
|
||||
createIndex("CREATE INDEX on %s(c)");
|
||||
createIndex("CREATE INDEX on %s(v)");
|
||||
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)", bytes("foo123"), bytes("1"), bytes("1"));
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)", bytes("foo123"), bytes("2"), bytes("1"));
|
||||
|
||||
beforeAndAfterFlush(() -> {
|
||||
// Test clustering columns restrictions
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c = textAsBlob('');"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) = (textAsBlob(''));"));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c IN (textAsBlob(''), textAsBlob('1'));"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) IN ((textAsBlob('')), (textAsBlob('1')));"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c > textAsBlob('') AND v = textAsBlob('1') ALLOW FILTERING;"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("2"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c >= textAsBlob('') AND v = textAsBlob('1') ALLOW FILTERING;"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("2"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) >= (textAsBlob('')) AND v = textAsBlob('1') ALLOW FILTERING;"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("2"), bytes("1")));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c <= textAsBlob('') AND v = textAsBlob('1') ALLOW FILTERING;"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) <= (textAsBlob('')) AND v = textAsBlob('1') ALLOW FILTERING;"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) < (textAsBlob('')) AND v = textAsBlob('1') ALLOW FILTERING;"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c < textAsBlob('') AND v = textAsBlob('1') ALLOW FILTERING;"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c > textAsBlob('') AND c < textAsBlob('') AND v = textAsBlob('1') ALLOW FILTERING;"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) > (textAsBlob('')) AND (c) < (textAsBlob('')) AND v = textAsBlob('1') ALLOW FILTERING;"));
|
||||
});
|
||||
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)",
|
||||
bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"));
|
||||
|
||||
beforeAndAfterFlush(() -> {
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c = textAsBlob('');"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) = (textAsBlob(''));"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c IN (textAsBlob(''), textAsBlob('1'));"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) IN ((textAsBlob('')), (textAsBlob('1')));"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c > textAsBlob('') AND v = textAsBlob('1') ALLOW FILTERING;"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("2"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c >= textAsBlob('') AND v = textAsBlob('1') ALLOW FILTERING;"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("2"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) >= (textAsBlob('')) AND v = textAsBlob('1') ALLOW FILTERING;"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("2"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c <= textAsBlob('') AND v = textAsBlob('1') ALLOW FILTERING;"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) <= (textAsBlob('')) AND v = textAsBlob('1') ALLOW FILTERING;"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1")));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c < textAsBlob('') AND v = textAsBlob('1') ALLOW FILTERING;"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) < (textAsBlob('')) AND v = textAsBlob('1') ALLOW FILTERING;"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c >= textAsBlob('') AND c < textAsBlob('') AND v = textAsBlob('1') ALLOW FILTERING;"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) >= (textAsBlob('')) AND c < textAsBlob('') AND v = textAsBlob('1') ALLOW FILTERING;"));
|
||||
|
||||
// Test restrictions on non-primary key value
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND v = textAsBlob('');"));
|
||||
});
|
||||
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)",
|
||||
bytes("foo123"), bytes("3"), EMPTY_BYTE_BUFFER);
|
||||
|
||||
beforeAndAfterFlush(() -> {
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND v = textAsBlob('');"),
|
||||
row(bytes("foo123"), bytes("3"), EMPTY_BYTE_BUFFER));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyRestrictionValueWithSecondaryIndexAndCompactTables() throws Throwable
|
||||
{
|
||||
createTable("CREATE TABLE %s (pk blob, c blob, v blob, PRIMARY KEY ((pk), c)) WITH COMPACT STORAGE");
|
||||
assertInvalidMessage("Secondary indexes are not supported on COMPACT STORAGE tables that have clustering columns",
|
||||
"CREATE INDEX on %s(c)");
|
||||
|
||||
createTable("CREATE TABLE %s (pk blob PRIMARY KEY, v blob) WITH COMPACT STORAGE");
|
||||
createIndex("CREATE INDEX on %s(v)");
|
||||
|
||||
execute("INSERT INTO %s (pk, v) VALUES (?, ?)", bytes("foo123"), bytes("1"));
|
||||
|
||||
// Test restrictions on non-primary key value
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND v = textAsBlob('');"));
|
||||
|
||||
execute("INSERT INTO %s (pk, v) VALUES (?, ?)", bytes("foo124"), EMPTY_BYTE_BUFFER);
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE v = textAsBlob('');"),
|
||||
row(bytes("foo124"), EMPTY_BYTE_BUFFER));
|
||||
}
|
||||
|
||||
private ResultMessage.Prepared prepareStatement(String cql, boolean forThrift)
|
||||
{
|
||||
return QueryProcessor.prepare(String.format(cql, KEYSPACE, currentTable()),
|
||||
|
|
|
|||
|
|
@ -23,9 +23,14 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.cassandra.cql3.CQLTester;
|
||||
|
||||
import static org.apache.cassandra.utils.ByteBufferUtil.EMPTY_BYTE_BUFFER;
|
||||
import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
|
||||
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
|
@ -1131,4 +1136,112 @@ public class DeleteTest extends CQLTester
|
|||
row(9), row(8), row(1), row(0)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteWithEmptyRestrictionValue() throws Throwable
|
||||
{
|
||||
for (String options : new String[] { "", " WITH COMPACT STORAGE" })
|
||||
{
|
||||
createTable("CREATE TABLE %s (pk blob, c blob, v blob, PRIMARY KEY (pk, c))" + options);
|
||||
|
||||
if (StringUtils.isEmpty(options))
|
||||
{
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)", bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"));
|
||||
execute("DELETE FROM %s WHERE pk = textAsBlob('foo123') AND c = textAsBlob('');");
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s"));
|
||||
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)", bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"));
|
||||
execute("DELETE FROM %s WHERE pk = textAsBlob('foo123') AND c IN (textAsBlob(''), textAsBlob('1'));");
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s"));
|
||||
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)", bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"));
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)", bytes("foo123"), bytes("1"), bytes("1"));
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)", bytes("foo123"), bytes("2"), bytes("2"));
|
||||
|
||||
execute("DELETE FROM %s WHERE pk = textAsBlob('foo123') AND c > textAsBlob('')");
|
||||
|
||||
assertRows(execute("SELECT * FROM %s"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1")));
|
||||
|
||||
execute("DELETE FROM %s WHERE pk = textAsBlob('foo123') AND c >= textAsBlob('')");
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s"));
|
||||
}
|
||||
else
|
||||
{
|
||||
assertInvalid("Invalid empty or null value for column c",
|
||||
"DELETE FROM %s WHERE pk = textAsBlob('foo123') AND c = textAsBlob('')");
|
||||
assertInvalid("Invalid empty or null value for column c",
|
||||
"DELETE FROM %s WHERE pk = textAsBlob('foo123') AND c IN (textAsBlob(''), textAsBlob('1'))");
|
||||
}
|
||||
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)", bytes("foo123"), bytes("1"), bytes("1"));
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)", bytes("foo123"), bytes("2"), bytes("2"));
|
||||
|
||||
execute("DELETE FROM %s WHERE pk = textAsBlob('foo123') AND c > textAsBlob('')");
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s"));
|
||||
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)", bytes("foo123"), bytes("1"), bytes("1"));
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)", bytes("foo123"), bytes("2"), bytes("2"));
|
||||
|
||||
execute("DELETE FROM %s WHERE pk = textAsBlob('foo123') AND c <= textAsBlob('')");
|
||||
execute("DELETE FROM %s WHERE pk = textAsBlob('foo123') AND c < textAsBlob('')");
|
||||
|
||||
assertRows(execute("SELECT * FROM %s"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("2"), bytes("2")));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteWithMultipleClusteringColumnsAndEmptyRestrictionValue() throws Throwable
|
||||
{
|
||||
for (String options : new String[] { "", " WITH COMPACT STORAGE" })
|
||||
{
|
||||
createTable("CREATE TABLE %s (pk blob, c1 blob, c2 blob, v blob, PRIMARY KEY (pk, c1, c2))" + options);
|
||||
|
||||
execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)", bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"), bytes("1"));
|
||||
execute("DELETE FROM %s WHERE pk = textAsBlob('foo123') AND c1 = textAsBlob('');");
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s"));
|
||||
|
||||
execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)", bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"), bytes("1"));
|
||||
execute("DELETE FROM %s WHERE pk = textAsBlob('foo123') AND c1 IN (textAsBlob(''), textAsBlob('1')) AND c2 = textAsBlob('1');");
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s"));
|
||||
|
||||
execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)", bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"), bytes("0"));
|
||||
execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)", bytes("foo123"), bytes("1"), bytes("1"), bytes("1"));
|
||||
execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)", bytes("foo123"), bytes("1"), bytes("2"), bytes("3"));
|
||||
|
||||
execute("DELETE FROM %s WHERE pk = textAsBlob('foo123') AND c1 > textAsBlob('')");
|
||||
|
||||
assertRows(execute("SELECT * FROM %s"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"), bytes("0")));
|
||||
|
||||
execute("DELETE FROM %s WHERE pk = textAsBlob('foo123') AND c1 >= textAsBlob('')");
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s"));
|
||||
|
||||
execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)", bytes("foo123"), bytes("1"), bytes("1"), bytes("1"));
|
||||
execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)", bytes("foo123"), bytes("1"), bytes("2"), bytes("3"));
|
||||
|
||||
execute("DELETE FROM %s WHERE pk = textAsBlob('foo123') AND c1 > textAsBlob('')");
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s"));
|
||||
|
||||
execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)", bytes("foo123"), bytes("1"), bytes("1"), bytes("1"));
|
||||
execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)", bytes("foo123"), bytes("1"), bytes("2"), bytes("3"));
|
||||
|
||||
execute("DELETE FROM %s WHERE pk = textAsBlob('foo123') AND c1 <= textAsBlob('')");
|
||||
execute("DELETE FROM %s WHERE pk = textAsBlob('foo123') AND c1 < textAsBlob('')");
|
||||
|
||||
assertRows(execute("SELECT * FROM %s"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("2"), bytes("3")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,31 +36,33 @@ public class SelectOrderByTest extends CQLTester
|
|||
execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 1, 1);
|
||||
execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 2, 2);
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0, 0, 0),
|
||||
row(0, 1, 1),
|
||||
row(0, 2, 2)
|
||||
);
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertRows(execute("SELECT * FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0, 0, 0),
|
||||
row(0, 1, 1),
|
||||
row(0, 2, 2)
|
||||
);
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(0, 2, 2),
|
||||
row(0, 1, 1),
|
||||
row(0, 0, 0)
|
||||
);
|
||||
assertRows(execute("SELECT * FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(0, 2, 2),
|
||||
row(0, 1, 1),
|
||||
row(0, 0, 0)
|
||||
);
|
||||
|
||||
// order by the only column in the selection
|
||||
assertRows(execute("SELECT b FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0), row(1), row(2));
|
||||
// order by the only column in the selection
|
||||
assertRows(execute("SELECT b FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0), row(1), row(2));
|
||||
|
||||
assertRows(execute("SELECT b FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(2), row(1), row(0));
|
||||
assertRows(execute("SELECT b FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(2), row(1), row(0));
|
||||
|
||||
// order by a column not in the selection
|
||||
assertRows(execute("SELECT c FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0), row(1), row(2));
|
||||
// order by a column not in the selection
|
||||
assertRows(execute("SELECT c FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0), row(1), row(2));
|
||||
|
||||
assertRows(execute("SELECT c FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(2), row(1), row(0));
|
||||
assertRows(execute("SELECT c FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(2), row(1), row(0));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -74,22 +76,24 @@ public class SelectOrderByTest extends CQLTester
|
|||
execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 1, 1);
|
||||
execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 2, 2);
|
||||
|
||||
// order by the only column in the selection
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0), row(1), row(2));
|
||||
beforeAndAfterFlush(() -> {
|
||||
// order by the only column in the selection
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0), row(1), row(2));
|
||||
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(2), row(1), row(0));
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(2), row(1), row(0));
|
||||
|
||||
// order by a column not in the selection
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(c)) FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0), row(1), row(2));
|
||||
// order by a column not in the selection
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(c)) FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0), row(1), row(2));
|
||||
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(c)) FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(2), row(1), row(0));
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(c)) FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(2), row(1), row(0));
|
||||
|
||||
assertInvalid("SELECT * FROM %s WHERE a=? ORDER BY c ASC", 0);
|
||||
assertInvalid("SELECT * FROM %s WHERE a=? ORDER BY c DESC", 0);
|
||||
assertInvalid("SELECT * FROM %s WHERE a=? ORDER BY c ASC", 0);
|
||||
assertInvalid("SELECT * FROM %s WHERE a=? ORDER BY c DESC", 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -105,15 +109,17 @@ public class SelectOrderByTest extends CQLTester
|
|||
execute("INSERT INTO %s (a, b, c) VALUES (?, ?, {a: ?})", 0, 1, 1);
|
||||
execute("INSERT INTO %s (a, b, c) VALUES (?, ?, {a: ?})", 0, 2, 2);
|
||||
|
||||
// order by a column not in the selection
|
||||
assertRows(execute("SELECT c.a FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0), row(1), row(2));
|
||||
beforeAndAfterFlush(() -> {
|
||||
// order by a column not in the selection
|
||||
assertRows(execute("SELECT c.a FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0), row(1), row(2));
|
||||
|
||||
assertRows(execute("SELECT c.a FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(2), row(1), row(0));
|
||||
assertRows(execute("SELECT c.a FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(2), row(1), row(0));
|
||||
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(c.a)) FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(2), row(1), row(0));
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(c.a)) FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(2), row(1), row(0));
|
||||
});
|
||||
dropTable("DROP TABLE %s");
|
||||
}
|
||||
}
|
||||
|
|
@ -129,62 +135,64 @@ public class SelectOrderByTest extends CQLTester
|
|||
execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 1, 4);
|
||||
execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 2, 5);
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0, 0, 0, 0),
|
||||
row(0, 0, 1, 1),
|
||||
row(0, 0, 2, 2),
|
||||
row(0, 1, 0, 3),
|
||||
row(0, 1, 1, 4),
|
||||
row(0, 1, 2, 5)
|
||||
);
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertRows(execute("SELECT * FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0, 0, 0, 0),
|
||||
row(0, 0, 1, 1),
|
||||
row(0, 0, 2, 2),
|
||||
row(0, 1, 0, 3),
|
||||
row(0, 1, 1, 4),
|
||||
row(0, 1, 2, 5)
|
||||
);
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(0, 1, 2, 5),
|
||||
row(0, 1, 1, 4),
|
||||
row(0, 1, 0, 3),
|
||||
row(0, 0, 2, 2),
|
||||
row(0, 0, 1, 1),
|
||||
row(0, 0, 0, 0)
|
||||
);
|
||||
assertRows(execute("SELECT * FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(0, 1, 2, 5),
|
||||
row(0, 1, 1, 4),
|
||||
row(0, 1, 0, 3),
|
||||
row(0, 0, 2, 2),
|
||||
row(0, 0, 1, 1),
|
||||
row(0, 0, 0, 0)
|
||||
);
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE a=? ORDER BY b DESC, c DESC", 0),
|
||||
row(0, 1, 2, 5),
|
||||
row(0, 1, 1, 4),
|
||||
row(0, 1, 0, 3),
|
||||
row(0, 0, 2, 2),
|
||||
row(0, 0, 1, 1),
|
||||
row(0, 0, 0, 0)
|
||||
);
|
||||
assertRows(execute("SELECT * FROM %s WHERE a=? ORDER BY b DESC, c DESC", 0),
|
||||
row(0, 1, 2, 5),
|
||||
row(0, 1, 1, 4),
|
||||
row(0, 1, 0, 3),
|
||||
row(0, 0, 2, 2),
|
||||
row(0, 0, 1, 1),
|
||||
row(0, 0, 0, 0)
|
||||
);
|
||||
|
||||
assertInvalid("SELECT * FROM %s WHERE a=? ORDER BY c ASC", 0);
|
||||
assertInvalid("SELECT * FROM %s WHERE a=? ORDER BY c DESC", 0);
|
||||
assertInvalid("SELECT * FROM %s WHERE a=? ORDER BY b ASC, c DESC", 0);
|
||||
assertInvalid("SELECT * FROM %s WHERE a=? ORDER BY b DESC, c ASC", 0);
|
||||
assertInvalid("SELECT * FROM %s WHERE a=? ORDER BY d ASC", 0);
|
||||
assertInvalid("SELECT * FROM %s WHERE a=? ORDER BY c ASC", 0);
|
||||
assertInvalid("SELECT * FROM %s WHERE a=? ORDER BY c DESC", 0);
|
||||
assertInvalid("SELECT * FROM %s WHERE a=? ORDER BY b ASC, c DESC", 0);
|
||||
assertInvalid("SELECT * FROM %s WHERE a=? ORDER BY b DESC, c ASC", 0);
|
||||
assertInvalid("SELECT * FROM %s WHERE a=? ORDER BY d ASC", 0);
|
||||
|
||||
// select and order by b
|
||||
assertRows(execute("SELECT b FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0), row(0), row(0), row(1), row(1), row(1));
|
||||
assertRows(execute("SELECT b FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(1), row(1), row(1), row(0), row(0), row(0));
|
||||
// select and order by b
|
||||
assertRows(execute("SELECT b FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0), row(0), row(0), row(1), row(1), row(1));
|
||||
assertRows(execute("SELECT b FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(1), row(1), row(1), row(0), row(0), row(0));
|
||||
|
||||
// select c, order by b
|
||||
assertRows(execute("SELECT c FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0), row(1), row(2), row(0), row(1), row(2));
|
||||
assertRows(execute("SELECT c FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(2), row(1), row(0), row(2), row(1), row(0));
|
||||
// select c, order by b
|
||||
assertRows(execute("SELECT c FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0), row(1), row(2), row(0), row(1), row(2));
|
||||
assertRows(execute("SELECT c FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(2), row(1), row(0), row(2), row(1), row(0));
|
||||
|
||||
// select c, order by b, c
|
||||
assertRows(execute("SELECT c FROM %s WHERE a=? ORDER BY b ASC, c ASC", 0),
|
||||
row(0), row(1), row(2), row(0), row(1), row(2));
|
||||
assertRows(execute("SELECT c FROM %s WHERE a=? ORDER BY b DESC, c DESC", 0),
|
||||
row(2), row(1), row(0), row(2), row(1), row(0));
|
||||
// select c, order by b, c
|
||||
assertRows(execute("SELECT c FROM %s WHERE a=? ORDER BY b ASC, c ASC", 0),
|
||||
row(0), row(1), row(2), row(0), row(1), row(2));
|
||||
assertRows(execute("SELECT c FROM %s WHERE a=? ORDER BY b DESC, c DESC", 0),
|
||||
row(2), row(1), row(0), row(2), row(1), row(0));
|
||||
|
||||
// select d, order by b, c
|
||||
assertRows(execute("SELECT d FROM %s WHERE a=? ORDER BY b ASC, c ASC", 0),
|
||||
row(0), row(1), row(2), row(3), row(4), row(5));
|
||||
assertRows(execute("SELECT d FROM %s WHERE a=? ORDER BY b DESC, c DESC", 0),
|
||||
row(5), row(4), row(3), row(2), row(1), row(0));
|
||||
// select d, order by b, c
|
||||
assertRows(execute("SELECT d FROM %s WHERE a=? ORDER BY b ASC, c ASC", 0),
|
||||
row(0), row(1), row(2), row(3), row(4), row(5));
|
||||
assertRows(execute("SELECT d FROM %s WHERE a=? ORDER BY b DESC, c DESC", 0),
|
||||
row(5), row(4), row(3), row(2), row(1), row(0));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -198,41 +206,42 @@ public class SelectOrderByTest extends CQLTester
|
|||
execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 1, 4);
|
||||
execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 2, 5);
|
||||
|
||||
assertInvalid("SELECT blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY c ASC", 0);
|
||||
assertInvalid("SELECT blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY c DESC", 0);
|
||||
assertInvalid("SELECT blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY b ASC, c DESC", 0);
|
||||
assertInvalid("SELECT blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY b DESC, c ASC", 0);
|
||||
assertInvalid("SELECT blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY d ASC", 0);
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertInvalid("SELECT blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY c ASC", 0);
|
||||
assertInvalid("SELECT blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY c DESC", 0);
|
||||
assertInvalid("SELECT blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY b ASC, c DESC", 0);
|
||||
assertInvalid("SELECT blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY b DESC, c ASC", 0);
|
||||
assertInvalid("SELECT blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY d ASC", 0);
|
||||
|
||||
// select and order by b
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0), row(0), row(0), row(1), row(1), row(1));
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(1), row(1), row(1), row(0), row(0), row(0));
|
||||
// select and order by b
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0), row(0), row(0), row(1), row(1), row(1));
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(1), row(1), row(1), row(0), row(0), row(0));
|
||||
|
||||
assertRows(execute("SELECT b, blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0, 0), row(0, 0), row(0, 0), row(1, 1), row(1, 1), row(1, 1));
|
||||
assertRows(execute("SELECT b, blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(1, 1), row(1, 1), row(1, 1), row(0, 0), row(0, 0), row(0, 0));
|
||||
assertRows(execute("SELECT b, blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0, 0), row(0, 0), row(0, 0), row(1, 1), row(1, 1), row(1, 1));
|
||||
assertRows(execute("SELECT b, blobAsInt(intAsBlob(b)) FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(1, 1), row(1, 1), row(1, 1), row(0, 0), row(0, 0), row(0, 0));
|
||||
|
||||
// select c, order by b
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(c)) FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0), row(1), row(2), row(0), row(1), row(2));
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(c)) FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(2), row(1), row(0), row(2), row(1), row(0));
|
||||
// select c, order by b
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(c)) FROM %s WHERE a=? ORDER BY b ASC", 0),
|
||||
row(0), row(1), row(2), row(0), row(1), row(2));
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(c)) FROM %s WHERE a=? ORDER BY b DESC", 0),
|
||||
row(2), row(1), row(0), row(2), row(1), row(0));
|
||||
|
||||
// select c, order by b, c
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(c)) FROM %s WHERE a=? ORDER BY b ASC, c ASC", 0),
|
||||
row(0), row(1), row(2), row(0), row(1), row(2));
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(c)) FROM %s WHERE a=? ORDER BY b DESC, c DESC", 0),
|
||||
row(2), row(1), row(0), row(2), row(1), row(0));
|
||||
|
||||
// select d, order by b, c
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(d)) FROM %s WHERE a=? ORDER BY b ASC, c ASC", 0),
|
||||
row(0), row(1), row(2), row(3), row(4), row(5));
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(d)) FROM %s WHERE a=? ORDER BY b DESC, c DESC", 0),
|
||||
row(5), row(4), row(3), row(2), row(1), row(0));
|
||||
// select c, order by b, c
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(c)) FROM %s WHERE a=? ORDER BY b ASC, c ASC", 0),
|
||||
row(0), row(1), row(2), row(0), row(1), row(2));
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(c)) FROM %s WHERE a=? ORDER BY b DESC, c DESC", 0),
|
||||
row(2), row(1), row(0), row(2), row(1), row(0));
|
||||
|
||||
// select d, order by b, c
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(d)) FROM %s WHERE a=? ORDER BY b ASC, c ASC", 0),
|
||||
row(0), row(1), row(2), row(3), row(4), row(5));
|
||||
assertRows(execute("SELECT blobAsInt(intAsBlob(d)) FROM %s WHERE a=? ORDER BY b DESC, c DESC", 0),
|
||||
row(5), row(4), row(3), row(2), row(1), row(0));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -247,8 +256,10 @@ public class SelectOrderByTest extends CQLTester
|
|||
for (int i = 0; i < 10; i++)
|
||||
execute("INSERT INTO %s (k, c, v) VALUES (0, ?, ?)", i, i);
|
||||
|
||||
assertRows(execute("SELECT v FROM %s WHERE k = 0 ORDER BY c DESC"),
|
||||
row(9), row(8), row(7), row(6), row(5), row(4), row(3), row(2), row(1), row(0));
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertRows(execute("SELECT v FROM %s WHERE k = 0 ORDER BY c DESC"),
|
||||
row(9), row(8), row(7), row(6), row(5), row(4), row(3), row(2), row(1), row(0));
|
||||
});
|
||||
|
||||
createTable("CREATE TABLE %s (k int, c1 int, c2 int, v int, PRIMARY KEY (k, c1, c2)) WITH COMPACT STORAGE");
|
||||
|
||||
|
|
@ -256,15 +267,17 @@ public class SelectOrderByTest extends CQLTester
|
|||
for (int j = 0; j < 2; j++)
|
||||
execute("INSERT INTO %s (k, c1, c2, v) VALUES (0, ?, ?, ?)", i, j, i * 2 + j);
|
||||
|
||||
assertInvalid("SELECT v FROM %s WHERE k = 0 ORDER BY c DESC");
|
||||
assertInvalid("SELECT v FROM %s WHERE k = 0 ORDER BY c2 DESC");
|
||||
assertInvalid("SELECT v FROM %s WHERE k = 0 ORDER BY k DESC");
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertInvalid("SELECT v FROM %s WHERE k = 0 ORDER BY c DESC");
|
||||
assertInvalid("SELECT v FROM %s WHERE k = 0 ORDER BY c2 DESC");
|
||||
assertInvalid("SELECT v FROM %s WHERE k = 0 ORDER BY k DESC");
|
||||
|
||||
assertRows(execute("SELECT v FROM %s WHERE k = 0 ORDER BY c1 DESC"),
|
||||
row(7), row(6), row(5), row(4), row(3), row(2), row(1), row(0));
|
||||
assertRows(execute("SELECT v FROM %s WHERE k = 0 ORDER BY c1 DESC"),
|
||||
row(7), row(6), row(5), row(4), row(3), row(2), row(1), row(0));
|
||||
|
||||
assertRows(execute("SELECT v FROM %s WHERE k = 0 ORDER BY c1"),
|
||||
row(0), row(1), row(2), row(3), row(4), row(5), row(6), row(7));
|
||||
assertRows(execute("SELECT v FROM %s WHERE k = 0 ORDER BY c1"),
|
||||
row(0), row(1), row(2), row(3), row(4), row(5), row(6), row(7));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -281,23 +294,25 @@ public class SelectOrderByTest extends CQLTester
|
|||
execute("INSERT INTO %s (row, number, string) VALUES ('row', 3, 'three')");
|
||||
execute("INSERT INTO %s (row, number, string) VALUES ('row', 4, 'four')");
|
||||
|
||||
assertRows(execute("SELECT number FROM %s WHERE row='row' AND number < 3 ORDER BY number ASC"),
|
||||
row(1), row(2));
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertRows(execute("SELECT number FROM %s WHERE row='row' AND number < 3 ORDER BY number ASC"),
|
||||
row(1), row(2));
|
||||
|
||||
assertRows(execute("SELECT number FROM %s WHERE row='row' AND number >= 3 ORDER BY number ASC"),
|
||||
row(3), row(4));
|
||||
assertRows(execute("SELECT number FROM %s WHERE row='row' AND number >= 3 ORDER BY number ASC"),
|
||||
row(3), row(4));
|
||||
|
||||
assertRows(execute("SELECT number FROM %s WHERE row='row' AND number < 3 ORDER BY number DESC"),
|
||||
row(2), row(1));
|
||||
assertRows(execute("SELECT number FROM %s WHERE row='row' AND number < 3 ORDER BY number DESC"),
|
||||
row(2), row(1));
|
||||
|
||||
assertRows(execute("SELECT number FROM %s WHERE row='row' AND number >= 3 ORDER BY number DESC"),
|
||||
row(4), row(3));
|
||||
assertRows(execute("SELECT number FROM %s WHERE row='row' AND number >= 3 ORDER BY number DESC"),
|
||||
row(4), row(3));
|
||||
|
||||
assertRows(execute("SELECT number FROM %s WHERE row='row' AND number > 3 ORDER BY number DESC"),
|
||||
row(4));
|
||||
assertRows(execute("SELECT number FROM %s WHERE row='row' AND number > 3 ORDER BY number DESC"),
|
||||
row(4));
|
||||
|
||||
assertRows(execute("SELECT number FROM %s WHERE row='row' AND number <= 3 ORDER BY number DESC"),
|
||||
row(3), row(2), row(1));
|
||||
assertRows(execute("SELECT number FROM %s WHERE row='row' AND number <= 3 ORDER BY number DESC"),
|
||||
row(3), row(2), row(1));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -330,20 +345,22 @@ public class SelectOrderByTest extends CQLTester
|
|||
execute("INSERT INTO %s (my_id, col1, value) VALUES ( 'key3', 2, 'b')");
|
||||
execute("INSERT INTO %s (my_id, col1, value) VALUES ( 'key4', 4, 'd')");
|
||||
|
||||
assertRows(execute("SELECT col1 FROM %s WHERE my_id in('key1', 'key2', 'key3') ORDER BY col1"),
|
||||
row(1), row(2), row(3));
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertRows(execute("SELECT col1 FROM %s WHERE my_id in('key1', 'key2', 'key3') ORDER BY col1"),
|
||||
row(1), row(2), row(3));
|
||||
|
||||
assertRows(execute("SELECT col1 FROM %s WHERE my_id in('key1', 'key2', 'key3') ORDER BY col1 LIMIT 2"),
|
||||
row(1), row(2));
|
||||
assertRows(execute("SELECT col1 FROM %s WHERE my_id in('key1', 'key2', 'key3') ORDER BY col1 LIMIT 2"),
|
||||
row(1), row(2));
|
||||
|
||||
assertRows(execute("SELECT col1 FROM %s WHERE my_id in('key1', 'key2', 'key3') ORDER BY col1 LIMIT 10"),
|
||||
row(1), row(2), row(3));
|
||||
assertRows(execute("SELECT col1 FROM %s WHERE my_id in('key1', 'key2', 'key3') ORDER BY col1 LIMIT 10"),
|
||||
row(1), row(2), row(3));
|
||||
|
||||
assertRows(execute("SELECT col1, my_id FROM %s WHERE my_id in('key1', 'key2', 'key3') ORDER BY col1"),
|
||||
row(1, "key1"), row(2, "key3"), row(3, "key2"));
|
||||
assertRows(execute("SELECT col1, my_id FROM %s WHERE my_id in('key1', 'key2', 'key3') ORDER BY col1"),
|
||||
row(1, "key1"), row(2, "key3"), row(3, "key2"));
|
||||
|
||||
assertRows(execute("SELECT my_id, col1 FROM %s WHERE my_id in('key1', 'key2', 'key3') ORDER BY col1"),
|
||||
row("key1", 1), row("key3", 2), row("key2", 3));
|
||||
assertRows(execute("SELECT my_id, col1 FROM %s WHERE my_id in('key1', 'key2', 'key3') ORDER BY col1"),
|
||||
row("key1", 1), row("key3", 2), row("key2", 3));
|
||||
});
|
||||
|
||||
createTable("CREATE TABLE %s (pk1 int, pk2 int, c int, v text, PRIMARY KEY ((pk1, pk2), c) )");
|
||||
execute("INSERT INTO %s (pk1, pk2, c, v) VALUES (?, ?, ?, ?)", 1, 1, 2, "A");
|
||||
|
|
@ -351,34 +368,36 @@ public class SelectOrderByTest extends CQLTester
|
|||
execute("INSERT INTO %s (pk1, pk2, c, v) VALUES (?, ?, ?, ?)", 1, 3, 3, "C");
|
||||
execute("INSERT INTO %s (pk1, pk2, c, v) VALUES (?, ?, ?, ?)", 1, 1, 4, "D");
|
||||
|
||||
assertRows(execute("SELECT v, ttl(v), c FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c; ", 1, 1, 2),
|
||||
row("B", null, 1),
|
||||
row("A", null, 2),
|
||||
row("D", null, 4));
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertRows(execute("SELECT v, ttl(v), c FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c; ", 1, 1, 2),
|
||||
row("B", null, 1),
|
||||
row("A", null, 2),
|
||||
row("D", null, 4));
|
||||
|
||||
assertRows(execute("SELECT v, ttl(v), c as name_1 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c; ", 1, 1, 2),
|
||||
row("B", null, 1),
|
||||
row("A", null, 2),
|
||||
row("D", null, 4));
|
||||
assertRows(execute("SELECT v, ttl(v), c as name_1 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c; ", 1, 1, 2),
|
||||
row("B", null, 1),
|
||||
row("A", null, 2),
|
||||
row("D", null, 4));
|
||||
|
||||
assertRows(execute("SELECT v FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c; ", 1, 1, 2),
|
||||
row("B"),
|
||||
row("A"),
|
||||
row("D"));
|
||||
assertRows(execute("SELECT v FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c; ", 1, 1, 2),
|
||||
row("B"),
|
||||
row("A"),
|
||||
row("D"));
|
||||
|
||||
assertRows(execute("SELECT v FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c LIMIT 2; ", 1, 1, 2),
|
||||
row("B"),
|
||||
row("A"));
|
||||
assertRows(execute("SELECT v FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c LIMIT 2; ", 1, 1, 2),
|
||||
row("B"),
|
||||
row("A"));
|
||||
|
||||
assertRows(execute("SELECT v FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c LIMIT 10; ", 1, 1, 2),
|
||||
row("B"),
|
||||
row("A"),
|
||||
row("D"));
|
||||
assertRows(execute("SELECT v FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c LIMIT 10; ", 1, 1, 2),
|
||||
row("B"),
|
||||
row("A"),
|
||||
row("D"));
|
||||
|
||||
assertRows(execute("SELECT v as c FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c; ", 1, 1, 2),
|
||||
row("B"),
|
||||
row("A"),
|
||||
row("D"));
|
||||
assertRows(execute("SELECT v as c FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c; ", 1, 1, 2),
|
||||
row("B"),
|
||||
row("A"),
|
||||
row("D"));
|
||||
});
|
||||
|
||||
createTable("CREATE TABLE %s (pk1 int, pk2 int, c1 int, c2 int, v text, PRIMARY KEY ((pk1, pk2), c1, c2) )");
|
||||
execute("INSERT INTO %s (pk1, pk2, c1, c2, v) VALUES (?, ?, ?, ?, ?)", 1, 1, 4, 4, "A");
|
||||
|
|
@ -386,51 +405,53 @@ public class SelectOrderByTest extends CQLTester
|
|||
execute("INSERT INTO %s (pk1, pk2, c1, c2, v) VALUES (?, ?, ?, ?, ?)", 1, 3, 3, 3, "C");
|
||||
execute("INSERT INTO %s (pk1, pk2, c1, c2, v) VALUES (?, ?, ?, ?, ?)", 1, 1, 4, 1, "D");
|
||||
|
||||
assertRows(execute("SELECT v, ttl(v), c1, c2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1, c2; ", 1, 1, 2),
|
||||
row("B", null, 1, 2),
|
||||
row("D", null, 4, 1),
|
||||
row("A", null, 4, 4));
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertRows(execute("SELECT v, ttl(v), c1, c2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1, c2; ", 1, 1, 2),
|
||||
row("B", null, 1, 2),
|
||||
row("D", null, 4, 1),
|
||||
row("A", null, 4, 4));
|
||||
|
||||
assertRows(execute("SELECT v, ttl(v), c1 as name_1, c2 as name_2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1, c2; ", 1, 1, 2),
|
||||
row("B", null, 1, 2),
|
||||
row("D", null, 4, 1),
|
||||
row("A", null, 4, 4));
|
||||
assertRows(execute("SELECT v, ttl(v), c1 as name_1, c2 as name_2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1, c2; ", 1, 1, 2),
|
||||
row("B", null, 1, 2),
|
||||
row("D", null, 4, 1),
|
||||
row("A", null, 4, 4));
|
||||
|
||||
assertRows(execute("SELECT v FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1, c2; ", 1, 1, 2),
|
||||
row("B"),
|
||||
row("D"),
|
||||
row("A"));
|
||||
assertRows(execute("SELECT v FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1, c2; ", 1, 1, 2),
|
||||
row("B"),
|
||||
row("D"),
|
||||
row("A"));
|
||||
|
||||
assertRows(execute("SELECT v as c2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1, c2; ", 1, 1, 2),
|
||||
row("B"),
|
||||
row("D"),
|
||||
row("A"));
|
||||
assertRows(execute("SELECT v as c2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1, c2; ", 1, 1, 2),
|
||||
row("B"),
|
||||
row("D"),
|
||||
row("A"));
|
||||
|
||||
assertRows(execute("SELECT v as c2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1, c2 LIMIT 2; ", 1, 1, 2),
|
||||
row("B"),
|
||||
row("D"));
|
||||
assertRows(execute("SELECT v as c2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1, c2 LIMIT 2; ", 1, 1, 2),
|
||||
row("B"),
|
||||
row("D"));
|
||||
|
||||
assertRows(execute("SELECT v as c2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1, c2 LIMIT 10; ", 1, 1, 2),
|
||||
row("B"),
|
||||
row("D"),
|
||||
row("A"));
|
||||
assertRows(execute("SELECT v as c2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1, c2 LIMIT 10; ", 1, 1, 2),
|
||||
row("B"),
|
||||
row("D"),
|
||||
row("A"));
|
||||
|
||||
assertRows(execute("SELECT v as c2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1 DESC , c2 DESC; ", 1, 1, 2),
|
||||
row("A"),
|
||||
row("D"),
|
||||
row("B"));
|
||||
assertRows(execute("SELECT v as c2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1 DESC , c2 DESC; ", 1, 1, 2),
|
||||
row("A"),
|
||||
row("D"),
|
||||
row("B"));
|
||||
|
||||
assertRows(execute("SELECT v as c2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1 DESC , c2 DESC LIMIT 2; ", 1, 1, 2),
|
||||
row("A"),
|
||||
row("D"));
|
||||
assertRows(execute("SELECT v as c2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1 DESC , c2 DESC LIMIT 2; ", 1, 1, 2),
|
||||
row("A"),
|
||||
row("D"));
|
||||
|
||||
assertRows(execute("SELECT v as c2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1 DESC , c2 DESC LIMIT 10; ", 1, 1, 2),
|
||||
row("A"),
|
||||
row("D"),
|
||||
row("B"));
|
||||
assertRows(execute("SELECT v as c2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1 DESC , c2 DESC LIMIT 10; ", 1, 1, 2),
|
||||
row("A"),
|
||||
row("D"),
|
||||
row("B"));
|
||||
|
||||
assertInvalidMessage("LIMIT must be strictly positive",
|
||||
"SELECT v as c2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1 DESC , c2 DESC LIMIT 0; ", 1, 1, 2);
|
||||
assertInvalidMessage("LIMIT must be strictly positive",
|
||||
"SELECT v as c2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1 DESC , c2 DESC LIMIT 0; ", 1, 1, 2);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -447,33 +468,35 @@ public class SelectOrderByTest extends CQLTester
|
|||
execute("UPDATE %s SET s = 2 WHERE a = 2");
|
||||
execute("UPDATE %s SET s = 3 WHERE a = 3");
|
||||
|
||||
assertRows(execute("SELECT a, b, c, d, s FROM %s WHERE a IN (1, 2, 3) ORDER BY b DESC"),
|
||||
row(2, 2, 2, 1, 2),
|
||||
row(2, 2, 1, 1, 2),
|
||||
row(1, 1, 2, 1, 1),
|
||||
row(1, 1, 1, 1, 1),
|
||||
row(3, null, null, null, 3));
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertRows(execute("SELECT a, b, c, d, s FROM %s WHERE a IN (1, 2, 3) ORDER BY b DESC"),
|
||||
row(2, 2, 2, 1, 2),
|
||||
row(2, 2, 1, 1, 2),
|
||||
row(1, 1, 2, 1, 1),
|
||||
row(1, 1, 1, 1, 1),
|
||||
row(3, null, null, null, 3));
|
||||
|
||||
assertRows(execute("SELECT a, b, c, d, s FROM %s WHERE a IN (1, 2, 3) ORDER BY b ASC"),
|
||||
row(3, null, null, null, 3),
|
||||
row(1, 1, 1, 1, 1),
|
||||
row(1, 1, 2, 1, 1),
|
||||
row(2, 2, 1, 1, 2),
|
||||
row(2, 2, 2, 1, 2));
|
||||
assertRows(execute("SELECT a, b, c, d, s FROM %s WHERE a IN (1, 2, 3) ORDER BY b ASC"),
|
||||
row(3, null, null, null, 3),
|
||||
row(1, 1, 1, 1, 1),
|
||||
row(1, 1, 2, 1, 1),
|
||||
row(2, 2, 1, 1, 2),
|
||||
row(2, 2, 2, 1, 2));
|
||||
|
||||
assertRows(execute("SELECT a, b, c, d, s FROM %s WHERE a IN (1, 2, 3) ORDER BY b DESC , c DESC"),
|
||||
row(2, 2, 2, 1, 2),
|
||||
row(2, 2, 1, 1, 2),
|
||||
row(1, 1, 2, 1, 1),
|
||||
row(1, 1, 1, 1, 1),
|
||||
row(3, null, null, null, 3));
|
||||
assertRows(execute("SELECT a, b, c, d, s FROM %s WHERE a IN (1, 2, 3) ORDER BY b DESC , c DESC"),
|
||||
row(2, 2, 2, 1, 2),
|
||||
row(2, 2, 1, 1, 2),
|
||||
row(1, 1, 2, 1, 1),
|
||||
row(1, 1, 1, 1, 1),
|
||||
row(3, null, null, null, 3));
|
||||
|
||||
assertRows(execute("SELECT a, b, c, d, s FROM %s WHERE a IN (1, 2, 3) ORDER BY b ASC, c ASC"),
|
||||
row(3, null, null, null, 3),
|
||||
row(1, 1, 1, 1, 1),
|
||||
row(1, 1, 2, 1, 1),
|
||||
row(2, 2, 1, 1, 2),
|
||||
row(2, 2, 2, 1, 2));
|
||||
assertRows(execute("SELECT a, b, c, d, s FROM %s WHERE a IN (1, 2, 3) ORDER BY b ASC, c ASC"),
|
||||
row(3, null, null, null, 3),
|
||||
row(1, 1, 1, 1, 1),
|
||||
row(1, 1, 2, 1, 1),
|
||||
row(2, 2, 1, 1, 2),
|
||||
row(2, 2, 2, 1, 2));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -488,13 +511,15 @@ public class SelectOrderByTest extends CQLTester
|
|||
for(int i =0; i < 10; i++)
|
||||
execute("INSERT INTO %s (k, c, v) VALUES (0, ?, ?)", i, i);
|
||||
|
||||
assertRows(execute("SELECT c, v FROM %s WHERE k = 0 ORDER BY c ASC"),
|
||||
row(0, 0), row(1, 1), row(2, 2), row(3, 3), row(4, 4),
|
||||
row(5, 5), row(6, 6), row(7, 7), row(8, 8), row(9, 9));
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertRows(execute("SELECT c, v FROM %s WHERE k = 0 ORDER BY c ASC"),
|
||||
row(0, 0), row(1, 1), row(2, 2), row(3, 3), row(4, 4),
|
||||
row(5, 5), row(6, 6), row(7, 7), row(8, 8), row(9, 9));
|
||||
|
||||
assertRows(execute("SELECT c, v FROM %s WHERE k = 0 ORDER BY c DESC"),
|
||||
row(9, 9), row(8, 8), row(7, 7), row(6, 6), row(5, 5),
|
||||
row(4, 4), row(3, 3), row(2, 2), row(1, 1), row(0, 0));
|
||||
assertRows(execute("SELECT c, v FROM %s WHERE k = 0 ORDER BY c DESC"),
|
||||
row(9, 9), row(8, 8), row(7, 7), row(6, 6), row(5, 5),
|
||||
row(4, 4), row(3, 3), row(2, 2), row(1, 1), row(0, 0));
|
||||
});
|
||||
|
||||
createTable("CREATE TABLE %s (k int, c1 int, c2 int, v text, PRIMARY KEY (k, c1, c2)) WITH CLUSTERING ORDER BY (c1 ASC, c2 DESC)");
|
||||
|
||||
|
|
@ -502,28 +527,30 @@ public class SelectOrderByTest extends CQLTester
|
|||
for(int j = 0; j < 10; j++)
|
||||
execute("INSERT INTO %s (k, c1, c2, v) VALUES (0, ?, ?, ?)", i, j, String.format("%d%d", i, j));
|
||||
|
||||
assertInvalid("SELECT c1, c2, v FROM %s WHERE k = 0 ORDER BY c1 ASC, c2 ASC");
|
||||
assertInvalid("SELECT c1, c2, v FROM %s WHERE k = 0 ORDER BY c1 DESC, c2 DESC");
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertInvalid("SELECT c1, c2, v FROM %s WHERE k = 0 ORDER BY c1 ASC, c2 ASC");
|
||||
assertInvalid("SELECT c1, c2, v FROM %s WHERE k = 0 ORDER BY c1 DESC, c2 DESC");
|
||||
|
||||
Object[][] expectedRows = new Object[100][];
|
||||
for(int i = 0; i < 10; i++)
|
||||
for(int j = 9; j >= 0; j--)
|
||||
expectedRows[i * 10 + (9 - j)] = row(i, j, String.format("%d%d", i, j));
|
||||
Object[][] expectedRows = new Object[100][];
|
||||
for(int i = 0; i < 10; i++)
|
||||
for(int j = 9; j >= 0; j--)
|
||||
expectedRows[i * 10 + (9 - j)] = row(i, j, String.format("%d%d", i, j));
|
||||
|
||||
assertRows(execute("SELECT c1, c2, v FROM %s WHERE k = 0 ORDER BY c1 ASC"),
|
||||
expectedRows);
|
||||
assertRows(execute("SELECT c1, c2, v FROM %s WHERE k = 0 ORDER BY c1 ASC"),
|
||||
expectedRows);
|
||||
|
||||
assertRows(execute("SELECT c1, c2, v FROM %s WHERE k = 0 ORDER BY c1 ASC, c2 DESC"),
|
||||
expectedRows);
|
||||
assertRows(execute("SELECT c1, c2, v FROM %s WHERE k = 0 ORDER BY c1 ASC, c2 DESC"),
|
||||
expectedRows);
|
||||
|
||||
for(int i = 9; i >= 0; i--)
|
||||
for(int j = 0; j < 10; j++)
|
||||
expectedRows[(9 - i) * 10 + j] = row(i, j, String.format("%d%d", i, j));
|
||||
for(int i = 9; i >= 0; i--)
|
||||
for(int j = 0; j < 10; j++)
|
||||
expectedRows[(9 - i) * 10 + j] = row(i, j, String.format("%d%d", i, j));
|
||||
|
||||
assertRows(execute("SELECT c1, c2, v FROM %s WHERE k = 0 ORDER BY c1 DESC, c2 ASC"),
|
||||
expectedRows);
|
||||
assertRows(execute("SELECT c1, c2, v FROM %s WHERE k = 0 ORDER BY c1 DESC, c2 ASC"),
|
||||
expectedRows);
|
||||
|
||||
assertInvalid("SELECT c1, c2, v FROM %s WHERE k = 0 ORDER BY c2 DESC, c1 ASC");
|
||||
assertInvalid("SELECT c1, c2, v FROM %s WHERE k = 0 ORDER BY c2 DESC, c1 ASC");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -538,18 +565,20 @@ public class SelectOrderByTest extends CQLTester
|
|||
for (int j = 0; j < 2; j++)
|
||||
execute("INSERT INTO %s (k, c1, c2) VALUES ('foo', ?, ?)", i, j);
|
||||
|
||||
assertRows(execute("SELECT c1, c2 FROM %s WHERE k = 'foo'"),
|
||||
row(0, 1), row(0, 0), row(1, 1), row(1, 0));
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertRows(execute("SELECT c1, c2 FROM %s WHERE k = 'foo'"),
|
||||
row(0, 1), row(0, 0), row(1, 1), row(1, 0));
|
||||
|
||||
assertRows(execute("SELECT c1, c2 FROM %s WHERE k = 'foo' ORDER BY c1 ASC, c2 DESC"),
|
||||
row(0, 1), row(0, 0), row(1, 1), row(1, 0));
|
||||
assertRows(execute("SELECT c1, c2 FROM %s WHERE k = 'foo' ORDER BY c1 ASC, c2 DESC"),
|
||||
row(0, 1), row(0, 0), row(1, 1), row(1, 0));
|
||||
|
||||
assertRows(execute("SELECT c1, c2 FROM %s WHERE k = 'foo' ORDER BY c1 DESC, c2 ASC"),
|
||||
row(1, 0), row(1, 1), row(0, 0), row(0, 1));
|
||||
assertRows(execute("SELECT c1, c2 FROM %s WHERE k = 'foo' ORDER BY c1 DESC, c2 ASC"),
|
||||
row(1, 0), row(1, 1), row(0, 0), row(0, 1));
|
||||
|
||||
assertInvalid("SELECT c1, c2 FROM %s WHERE k = 'foo' ORDER BY c2 DESC");
|
||||
assertInvalid("SELECT c1, c2 FROM %s WHERE k = 'foo' ORDER BY c2 ASC");
|
||||
assertInvalid("SELECT c1, c2 FROM %s WHERE k = 'foo' ORDER BY c1 ASC, c2 ASC");
|
||||
assertInvalid("SELECT c1, c2 FROM %s WHERE k = 'foo' ORDER BY c2 DESC");
|
||||
assertInvalid("SELECT c1, c2 FROM %s WHERE k = 'foo' ORDER BY c2 ASC");
|
||||
assertInvalid("SELECT c1, c2 FROM %s WHERE k = 'foo' ORDER BY c1 ASC, c2 ASC");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -563,9 +592,11 @@ public class SelectOrderByTest extends CQLTester
|
|||
execute("INSERT INTO %s(k, c1, c2) VALUES (0, 0, 1)");
|
||||
execute("INSERT INTO %s(k, c1, c2) VALUES (0, 0, 2)");
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE k=0 AND c1 = 0 AND c2 IN (2, 0) ORDER BY c1 DESC"),
|
||||
row(0, 0, 2),
|
||||
row(0, 0, 0));
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertRows(execute("SELECT * FROM %s WHERE k=0 AND c1 = 0 AND c2 IN (2, 0) ORDER BY c1 DESC"),
|
||||
row(0, 0, 2),
|
||||
row(0, 0, 0));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -584,45 +615,47 @@ public class SelectOrderByTest extends CQLTester
|
|||
execute("INSERT INTO %s (k, c1, c2, v) VALUES (1, 1, 1, 4)");
|
||||
execute("INSERT INTO %s (k, c1, c2, v) VALUES (1, 1, 2, 5)");
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE k=0 AND c1 = 0 AND c2 IN (2, 0)"),
|
||||
row(0, 0, 0, 0),
|
||||
row(0, 0, 2, 2));
|
||||
assertRows(execute("SELECT * FROM %s WHERE k=0 AND c1 = 0 AND c2 IN (2, 0) ORDER BY c1 ASC, c2 ASC"),
|
||||
row(0, 0, 0, 0),
|
||||
row(0, 0, 2, 2));
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertRows(execute("SELECT * FROM %s WHERE k=0 AND c1 = 0 AND c2 IN (2, 0)"),
|
||||
row(0, 0, 0, 0),
|
||||
row(0, 0, 2, 2));
|
||||
assertRows(execute("SELECT * FROM %s WHERE k=0 AND c1 = 0 AND c2 IN (2, 0) ORDER BY c1 ASC, c2 ASC"),
|
||||
row(0, 0, 0, 0),
|
||||
row(0, 0, 2, 2));
|
||||
|
||||
// check that we don 't need to select the column on which we order
|
||||
assertRows(execute("SELECT v FROM %s WHERE k=0 AND c1 = 0 AND c2 IN (2, 0)"),
|
||||
row(0),
|
||||
row(2));
|
||||
assertRows(execute("SELECT v FROM %s WHERE k=0 AND c1 = 0 AND c2 IN (2, 0) ORDER BY c1 ASC"),
|
||||
row(0),
|
||||
row(2));
|
||||
assertRows(execute("SELECT v FROM %s WHERE k=0 AND c1 = 0 AND c2 IN (2, 0) ORDER BY c1 DESC"),
|
||||
row(2),
|
||||
row(0));
|
||||
// check that we don 't need to select the column on which we order
|
||||
assertRows(execute("SELECT v FROM %s WHERE k=0 AND c1 = 0 AND c2 IN (2, 0)"),
|
||||
row(0),
|
||||
row(2));
|
||||
assertRows(execute("SELECT v FROM %s WHERE k=0 AND c1 = 0 AND c2 IN (2, 0) ORDER BY c1 ASC"),
|
||||
row(0),
|
||||
row(2));
|
||||
assertRows(execute("SELECT v FROM %s WHERE k=0 AND c1 = 0 AND c2 IN (2, 0) ORDER BY c1 DESC"),
|
||||
row(2),
|
||||
row(0));
|
||||
|
||||
assertRows(execute("SELECT v FROM %s WHERE k IN (1, 0)"),
|
||||
row(0),
|
||||
row(1),
|
||||
row(2),
|
||||
row(3),
|
||||
row(4),
|
||||
row(5));
|
||||
assertRows(execute("SELECT v FROM %s WHERE k IN (1, 0)"),
|
||||
row(0),
|
||||
row(1),
|
||||
row(2),
|
||||
row(3),
|
||||
row(4),
|
||||
row(5));
|
||||
|
||||
assertRows(execute("SELECT v FROM %s WHERE k IN (1, 0) ORDER BY c1 ASC"),
|
||||
row(0),
|
||||
row(1),
|
||||
row(2),
|
||||
row(3),
|
||||
row(4),
|
||||
row(5));
|
||||
assertRows(execute("SELECT v FROM %s WHERE k IN (1, 0) ORDER BY c1 ASC"),
|
||||
row(0),
|
||||
row(1),
|
||||
row(2),
|
||||
row(3),
|
||||
row(4),
|
||||
row(5));
|
||||
|
||||
// we should also be able to use functions in the select clause (additional test for CASSANDRA - 8286)
|
||||
Object[][] results = getRows(execute("SELECT writetime(v) FROM %s WHERE k IN (1, 0) ORDER BY c1 ASC"));
|
||||
// we should also be able to use functions in the select clause (additional test for CASSANDRA - 8286)
|
||||
Object[][] results = getRows(execute("SELECT writetime(v) FROM %s WHERE k IN (1, 0) ORDER BY c1 ASC"));
|
||||
|
||||
// since we don 't know the write times, just assert that the order matches the order we expect
|
||||
assertTrue(isFirstIntSorted(results));
|
||||
// since we don 't know the write times, just assert that the order matches the order we expect
|
||||
assertTrue(isFirstIntSorted(results));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -637,33 +670,35 @@ public class SelectOrderByTest extends CQLTester
|
|||
execute("INSERT INTO %s (col_1, col_2, col_3) VALUES(?, ?, ?)", 1, 2, 10);
|
||||
execute("INSERT INTO %s (col_1, col_2, col_3) VALUES(?, ?, ?)", 1, 2, 11);
|
||||
|
||||
assertRows(execute("select * from %s where col_1=? and col_2 IN (?, ?) order by col_3;", 1, 1, 2),
|
||||
row(1, 1, 1),
|
||||
row(1, 1, 2),
|
||||
row(1, 2, 10),
|
||||
row(1, 2, 11),
|
||||
row(1, 1, 13));
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertRows(execute("select * from %s where col_1=? and col_2 IN (?, ?) order by col_3;", 1, 1, 2),
|
||||
row(1, 1, 1),
|
||||
row(1, 1, 2),
|
||||
row(1, 2, 10),
|
||||
row(1, 2, 11),
|
||||
row(1, 1, 13));
|
||||
|
||||
assertRows(execute("select * from %s where col_1=? and col_2 IN (?, ?) order by col_3 desc;", 1, 1, 2),
|
||||
row(1, 1, 13),
|
||||
row(1, 2, 11),
|
||||
row(1, 2, 10),
|
||||
row(1, 1, 2),
|
||||
row(1, 1, 1));
|
||||
assertRows(execute("select * from %s where col_1=? and col_2 IN (?, ?) order by col_3 desc;", 1, 1, 2),
|
||||
row(1, 1, 13),
|
||||
row(1, 2, 11),
|
||||
row(1, 2, 10),
|
||||
row(1, 1, 2),
|
||||
row(1, 1, 1));
|
||||
|
||||
assertRows(execute("select * from %s where col_2 IN (?, ?) and col_1=? order by col_3;", 1, 2, 1),
|
||||
row(1, 1, 1),
|
||||
row(1, 1, 2),
|
||||
row(1, 2, 10),
|
||||
row(1, 2, 11),
|
||||
row(1, 1, 13));
|
||||
assertRows(execute("select * from %s where col_2 IN (?, ?) and col_1=? order by col_3;", 1, 2, 1),
|
||||
row(1, 1, 1),
|
||||
row(1, 1, 2),
|
||||
row(1, 2, 10),
|
||||
row(1, 2, 11),
|
||||
row(1, 1, 13));
|
||||
|
||||
assertRows(execute("select * from %s where col_2 IN (?, ?) and col_1=? order by col_3 desc;", 1, 2, 1),
|
||||
row(1, 1, 13),
|
||||
row(1, 2, 11),
|
||||
row(1, 2, 10),
|
||||
row(1, 1, 2),
|
||||
row(1, 1, 1));
|
||||
assertRows(execute("select * from %s where col_2 IN (?, ?) and col_1=? order by col_3 desc;", 1, 2, 1),
|
||||
row(1, 1, 13),
|
||||
row(1, 2, 11),
|
||||
row(1, 2, 10),
|
||||
row(1, 1, 2),
|
||||
row(1, 1, 1));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,16 +21,18 @@ import java.nio.ByteBuffer;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.Assert;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.apache.cassandra.cql3.CQLTester;
|
||||
import org.apache.cassandra.cql3.UntypedResultSet;
|
||||
import org.apache.cassandra.cql3.restrictions.StatementRestrictions;
|
||||
import org.apache.cassandra.exceptions.InvalidRequestException;
|
||||
import org.apache.cassandra.utils.ByteBufferUtil;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.apache.cassandra.utils.ByteBufferUtil.EMPTY_BYTE_BUFFER;
|
||||
import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
|
||||
|
||||
|
||||
/**
|
||||
* Test column ranges and ordering with static column in table
|
||||
|
|
@ -2254,8 +2256,8 @@ public class SelectTest extends CQLTester
|
|||
createTable("CREATE TABLE %s (a int, b int, c blob, PRIMARY KEY (a, b))");
|
||||
createIndex("CREATE INDEX test ON %s (c)");
|
||||
|
||||
execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 0, ByteBufferUtil.bytes(1));
|
||||
execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 1, ByteBufferUtil.bytes(2));
|
||||
execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 0, bytes(1));
|
||||
execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", 0, 1, bytes(2));
|
||||
|
||||
assertInvalidMessage("Index expression values may not be larger than 64K",
|
||||
"SELECT * FROM %s WHERE c = ? ALLOW FILTERING", TOO_BIG);
|
||||
|
|
@ -2991,4 +2993,349 @@ public class SelectTest extends CQLTester
|
|||
row(1, 2, 3),
|
||||
row(1, 1, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyRestrictionValue() throws Throwable
|
||||
{
|
||||
for (String options : new String[] { "", " WITH COMPACT STORAGE" })
|
||||
{
|
||||
createTable("CREATE TABLE %s (pk blob, c blob, v blob, PRIMARY KEY ((pk), c))" + options);
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)",
|
||||
bytes("foo123"), bytes("1"), bytes("1"));
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)",
|
||||
bytes("foo123"), bytes("2"), bytes("2"));
|
||||
|
||||
beforeAndAfterFlush(() -> {
|
||||
|
||||
assertInvalidMessage("Key may not be empty", "SELECT * FROM %s WHERE pk = textAsBlob('');");
|
||||
assertInvalidMessage("Key may not be empty", "SELECT * FROM %s WHERE pk IN (textAsBlob(''), textAsBlob('1'));");
|
||||
|
||||
assertInvalidMessage("Key may not be empty",
|
||||
"INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)",
|
||||
EMPTY_BYTE_BUFFER, bytes("2"), bytes("2"));
|
||||
|
||||
// Test clustering columns restrictions
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c = textAsBlob('');"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) = (textAsBlob(''));"));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c IN (textAsBlob(''), textAsBlob('1'));"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) IN ((textAsBlob('')), (textAsBlob('1')));"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c > textAsBlob('');"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("2"), bytes("2")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) > (textAsBlob(''));"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("2"), bytes("2")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c >= textAsBlob('');"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("2"), bytes("2")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) >= (textAsBlob(''));"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("2"), bytes("2")));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c <= textAsBlob('');"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) <= (textAsBlob(''));"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c < textAsBlob('');"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) < (textAsBlob(''));"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c > textAsBlob('') AND c < textAsBlob('');"));
|
||||
});
|
||||
|
||||
if (options.contains("COMPACT"))
|
||||
{
|
||||
assertInvalidMessage("Invalid empty or null value for column c",
|
||||
"INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)",
|
||||
bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("4"));
|
||||
}
|
||||
else
|
||||
{
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)",
|
||||
bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("4"));
|
||||
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c = textAsBlob('');"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("4")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) = (textAsBlob(''));"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("4")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c IN (textAsBlob(''), textAsBlob('1'));"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("4")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) IN ((textAsBlob('')), (textAsBlob('1')));"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("4")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c > textAsBlob('');"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("2"), bytes("2")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) > (textAsBlob(''));"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("2"), bytes("2")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c >= textAsBlob('');"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("4")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("2"), bytes("2")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) >= (textAsBlob(''));"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("4")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("2"), bytes("2")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c <= textAsBlob('');"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("4")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) <= (textAsBlob(''));"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("4")));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c < textAsBlob('');"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c) < (textAsBlob(''));"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c >= textAsBlob('') AND c < textAsBlob('');"));
|
||||
});
|
||||
}
|
||||
|
||||
// Test restrictions on non-primary key value
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND v = textAsBlob('') ALLOW FILTERING;"));
|
||||
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)",
|
||||
bytes("foo123"), bytes("3"), EMPTY_BYTE_BUFFER);
|
||||
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND v = textAsBlob('') ALLOW FILTERING;"),
|
||||
row(bytes("foo123"), bytes("3"), EMPTY_BYTE_BUFFER));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyRestrictionValueWithMultipleClusteringColumns() throws Throwable
|
||||
{
|
||||
for (String options : new String[] { "", " WITH COMPACT STORAGE" })
|
||||
{
|
||||
createTable("CREATE TABLE %s (pk blob, c1 blob, c2 blob, v blob, PRIMARY KEY (pk, c1, c2))" + options);
|
||||
execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)", bytes("foo123"), bytes("1"), bytes("1"), bytes("1"));
|
||||
execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)", bytes("foo123"), bytes("1"), bytes("2"), bytes("2"));
|
||||
|
||||
beforeAndAfterFlush(() -> {
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c1 = textAsBlob('');"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c1 = textAsBlob('1') AND c2 = textAsBlob('');"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c1, c2) = (textAsBlob('1'), textAsBlob(''));"));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c1 IN (textAsBlob(''), textAsBlob('1')) AND c2 = textAsBlob('1');"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c1 = textAsBlob('1') AND c2 IN (textAsBlob(''), textAsBlob('1'));"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c1, c2) IN ((textAsBlob(''), textAsBlob('1')), (textAsBlob('1'), textAsBlob('1')));"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c1 > textAsBlob('');"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("2"), bytes("2")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c1 = textAsBlob('1') AND c2 > textAsBlob('');"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("2"), bytes("2")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c1, c2) > (textAsBlob(''), textAsBlob('1'));"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("2"), bytes("2")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c1 = textAsBlob('1') AND c2 >= textAsBlob('');"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("2"), bytes("2")));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c1 = textAsBlob('1') AND c2 <= textAsBlob('');"));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c1, c2) <= (textAsBlob('1'), textAsBlob(''));"));
|
||||
});
|
||||
|
||||
execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)",
|
||||
bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"), bytes("4"));
|
||||
|
||||
beforeAndAfterFlush(() -> {
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c1 = textAsBlob('');"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"), bytes("4")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c1 = textAsBlob('') AND c2 = textAsBlob('1');"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"), bytes("4")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c1, c2) = (textAsBlob(''), textAsBlob('1'));"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"), bytes("4")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c1 IN (textAsBlob(''), textAsBlob('1')) AND c2 = textAsBlob('1');"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"), bytes("4")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c1, c2) IN ((textAsBlob(''), textAsBlob('1')), (textAsBlob('1'), textAsBlob('1')));"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"), bytes("4")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c1, c2) > (textAsBlob(''), textAsBlob('1'));"),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("2"), bytes("2")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c1, c2) >= (textAsBlob(''), textAsBlob('1'));"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"), bytes("4")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("2"), bytes("2")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c1, c2) <= (textAsBlob(''), textAsBlob('1'));"),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"), bytes("4")));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c1, c2) < (textAsBlob(''), textAsBlob('1'));"));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyRestrictionValueWithOrderBy() throws Throwable
|
||||
{
|
||||
for (String options : new String[] { "",
|
||||
" WITH COMPACT STORAGE",
|
||||
" WITH CLUSTERING ORDER BY (c DESC)",
|
||||
" WITH COMPACT STORAGE AND CLUSTERING ORDER BY (c DESC)"})
|
||||
{
|
||||
String orderingClause = options.contains("ORDER") ? "" : "ORDER BY c DESC" ;
|
||||
|
||||
createTable("CREATE TABLE %s (pk blob, c blob, v blob, PRIMARY KEY ((pk), c))" + options);
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)",
|
||||
bytes("foo123"),
|
||||
bytes("1"),
|
||||
bytes("1"));
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)",
|
||||
bytes("foo123"),
|
||||
bytes("2"),
|
||||
bytes("2"));
|
||||
|
||||
beforeAndAfterFlush(() -> {
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c > textAsBlob('')" + orderingClause),
|
||||
row(bytes("foo123"), bytes("2"), bytes("2")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c >= textAsBlob('')" + orderingClause),
|
||||
row(bytes("foo123"), bytes("2"), bytes("2")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c < textAsBlob('')" + orderingClause));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c <= textAsBlob('')" + orderingClause));
|
||||
|
||||
});
|
||||
|
||||
if (options.contains("COMPACT"))
|
||||
{
|
||||
assertInvalidMessage("Invalid empty or null value for column c",
|
||||
"INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)",
|
||||
bytes("foo123"),
|
||||
EMPTY_BYTE_BUFFER,
|
||||
bytes("4"));
|
||||
}
|
||||
else
|
||||
{
|
||||
execute("INSERT INTO %s (pk, c, v) VALUES (?, ?, ?)",
|
||||
bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("4"));
|
||||
|
||||
beforeAndAfterFlush(() -> {
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c IN (textAsBlob(''), textAsBlob('1'))" + orderingClause),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("4")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c > textAsBlob('')" + orderingClause),
|
||||
row(bytes("foo123"), bytes("2"), bytes("2")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c >= textAsBlob('')" + orderingClause),
|
||||
row(bytes("foo123"), bytes("2"), bytes("2")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("4")));
|
||||
|
||||
assertEmpty(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c < textAsBlob('')" + orderingClause));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c <= textAsBlob('')" + orderingClause),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("4")));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyRestrictionValueWithMultipleClusteringColumnsAndOrderBy() throws Throwable
|
||||
{
|
||||
for (String options : new String[] { "",
|
||||
" WITH COMPACT STORAGE",
|
||||
" WITH CLUSTERING ORDER BY (c1 DESC, c2 DESC)",
|
||||
" WITH COMPACT STORAGE AND CLUSTERING ORDER BY (c1 DESC, c2 DESC)"})
|
||||
{
|
||||
String orderingClause = options.contains("ORDER") ? "" : "ORDER BY c1 DESC, c2 DESC" ;
|
||||
|
||||
createTable("CREATE TABLE %s (pk blob, c1 blob, c2 blob, v blob, PRIMARY KEY (pk, c1, c2))" + options);
|
||||
execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)", bytes("foo123"), bytes("1"), bytes("1"), bytes("1"));
|
||||
execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)", bytes("foo123"), bytes("1"), bytes("2"), bytes("2"));
|
||||
|
||||
beforeAndAfterFlush(() -> {
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c1 > textAsBlob('')" + orderingClause),
|
||||
row(bytes("foo123"), bytes("1"), bytes("2"), bytes("2")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c1 = textAsBlob('1') AND c2 > textAsBlob('')" + orderingClause),
|
||||
row(bytes("foo123"), bytes("1"), bytes("2"), bytes("2")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c1, c2) > (textAsBlob(''), textAsBlob('1'))" + orderingClause),
|
||||
row(bytes("foo123"), bytes("1"), bytes("2"), bytes("2")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c1 = textAsBlob('1') AND c2 >= textAsBlob('')" + orderingClause),
|
||||
row(bytes("foo123"), bytes("1"), bytes("2"), bytes("2")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")));
|
||||
});
|
||||
|
||||
execute("INSERT INTO %s (pk, c1, c2, v) VALUES (?, ?, ?, ?)",
|
||||
bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"), bytes("4"));
|
||||
|
||||
beforeAndAfterFlush(() -> {
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND c1 IN (textAsBlob(''), textAsBlob('1')) AND c2 = textAsBlob('1')" + orderingClause),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"), bytes("4")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c1, c2) IN ((textAsBlob(''), textAsBlob('1')), (textAsBlob('1'), textAsBlob('1')))" + orderingClause),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"), bytes("4")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c1, c2) > (textAsBlob(''), textAsBlob('1'))" + orderingClause),
|
||||
row(bytes("foo123"), bytes("1"), bytes("2"), bytes("2")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")));
|
||||
|
||||
assertRows(execute("SELECT * FROM %s WHERE pk = textAsBlob('foo123') AND (c1, c2) >= (textAsBlob(''), textAsBlob('1'))" + orderingClause),
|
||||
row(bytes("foo123"), bytes("1"), bytes("2"), bytes("2")),
|
||||
row(bytes("foo123"), bytes("1"), bytes("1"), bytes("1")),
|
||||
row(bytes("foo123"), EMPTY_BYTE_BUFFER, bytes("1"), bytes("4")));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ public class ReversedTypeTest
|
|||
assert t.compare(bytes(4L), bytes(2L)) < 0;
|
||||
|
||||
// the empty byte buffer is always the smaller
|
||||
assert t.compare(EMPTY_BYTE_BUFFER, bytes(2L)) < 0;
|
||||
assert t.compare(bytes(2L), EMPTY_BYTE_BUFFER) > 0;
|
||||
assert t.compare(EMPTY_BYTE_BUFFER, bytes(2L)) > 0;
|
||||
assert t.compare(bytes(2L), EMPTY_BYTE_BUFFER) < 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue