mirror of https://github.com/apache/cassandra
Merge branch cassandra-2.2 into cassandra-3.0
This commit is contained in:
commit
1b93eb403b
|
|
@ -269,6 +269,11 @@ public class ResultSet
|
|||
return names == null ? columnCount : names.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified column which will not be serialized.
|
||||
*
|
||||
* @param name the column
|
||||
*/
|
||||
public void addNonSerializedColumn(ColumnSpecification name)
|
||||
{
|
||||
// See comment above. Because columnCount doesn't account the newly added name, it
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ public abstract class UntypedResultSet implements Iterable<UntypedResultSet.Row>
|
|||
{
|
||||
if (cqlRows.size() != 1)
|
||||
throw new IllegalStateException("One row required, " + cqlRows.size() + " found");
|
||||
return new Row(cqlRows.metadata.names, cqlRows.rows.get(0));
|
||||
return new Row(cqlRows.metadata.requestNames(), cqlRows.rows.get(0));
|
||||
}
|
||||
|
||||
public Iterator<Row> iterator()
|
||||
|
|
@ -95,7 +95,7 @@ public abstract class UntypedResultSet implements Iterable<UntypedResultSet.Row>
|
|||
{
|
||||
if (!iter.hasNext())
|
||||
return endOfData();
|
||||
return new Row(cqlRows.metadata.names, iter.next());
|
||||
return new Row(cqlRows.metadata.requestNames(), iter.next());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -160,7 +160,7 @@ public abstract class UntypedResultSet implements Iterable<UntypedResultSet.Row>
|
|||
this.select = select;
|
||||
this.pager = pager;
|
||||
this.pageSize = pageSize;
|
||||
this.metadata = select.getResultMetadata().names;
|
||||
this.metadata = select.getResultMetadata().requestNames();
|
||||
}
|
||||
|
||||
public int size()
|
||||
|
|
|
|||
|
|
@ -125,23 +125,6 @@ public abstract class Selection
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the specified column.
|
||||
*
|
||||
* @param def the column definition
|
||||
* @return the index of the specified column
|
||||
*/
|
||||
public int indexOf(final ColumnDefinition def)
|
||||
{
|
||||
return Iterators.indexOf(getColumns().iterator(), new Predicate<ColumnDefinition>()
|
||||
{
|
||||
public boolean apply(ColumnDefinition n)
|
||||
{
|
||||
return def.name.equals(n.name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ResultSet.ResultMetadata getResultMetadata(boolean isJson)
|
||||
{
|
||||
if (!isJson)
|
||||
|
|
@ -199,6 +182,29 @@ public abstract class Selection
|
|||
: new SimpleSelection(cfm, defs, mapping, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the specified column within the resultset
|
||||
* @param c the column
|
||||
* @return the index of the specified column within the resultset or -1
|
||||
*/
|
||||
public int getResultSetIndex(ColumnDefinition c)
|
||||
{
|
||||
return getColumnIndex(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the specified column
|
||||
* @param c the column
|
||||
* @return the index of the specified column or -1
|
||||
*/
|
||||
protected final int getColumnIndex(ColumnDefinition c)
|
||||
{
|
||||
for (int i = 0, m = columns.size(); i < m; i++)
|
||||
if (columns.get(i).name.equals(c.name))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static SelectionColumnMapping collectColumnMappings(CFMetaData cfm,
|
||||
List<RawSelector> rawSelectors,
|
||||
SelectorFactories factories)
|
||||
|
|
@ -497,12 +503,27 @@ public abstract class Selection
|
|||
return factories.getFunctions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getResultSetIndex(ColumnDefinition c)
|
||||
{
|
||||
int index = getColumnIndex(c);
|
||||
|
||||
if (index < 0)
|
||||
return -1;
|
||||
|
||||
for (int i = 0, m = factories.size(); i < m; i++)
|
||||
if (factories.get(i).isSimpleSelectorFactory(index))
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addColumnForOrdering(ColumnDefinition c)
|
||||
{
|
||||
int index = super.addColumnForOrdering(c);
|
||||
factories.addSelectorForOrdering(c, index);
|
||||
return index;
|
||||
return factories.size() - 1;
|
||||
}
|
||||
|
||||
public boolean isAggregate()
|
||||
|
|
|
|||
|
|
@ -103,6 +103,18 @@ public abstract class Selector implements AssignmentTestable
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this factory creates <code>Selector</code>s that simply return the specified column.
|
||||
*
|
||||
* @param index the column index
|
||||
* @return <code>true</code> if this factory creates <code>Selector</code>s that simply return
|
||||
* the specified column, <code>false</code> otherwise.
|
||||
*/
|
||||
public boolean isSimpleSelectorFactory(int index)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the column corresponding to the output value of the selector instances created by
|
||||
* this factory.
|
||||
|
|
|
|||
|
|
@ -98,6 +98,17 @@ final class SelectorFactories implements Iterable<Selector.Factory>
|
|||
return functions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the factory with the specified index.
|
||||
*
|
||||
* @param i the factory index
|
||||
* @return the factory with the specified index
|
||||
*/
|
||||
public Selector.Factory get(int i)
|
||||
{
|
||||
return factories.get(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new <code>Selector.Factory</code> for a column that is needed only for ORDER BY purposes.
|
||||
* @param def the column that is needed for ordering
|
||||
|
|
@ -191,4 +202,13 @@ final class SelectorFactories implements Iterable<Selector.Factory>
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of factories.
|
||||
* @return the number of factories
|
||||
*/
|
||||
public int size()
|
||||
{
|
||||
return factories.size();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,12 @@ public final class SimpleSelector extends Selector
|
|||
{
|
||||
return new SimpleSelector(def.name.toString(), idx, def.type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSimpleSelectorFactory(int index)
|
||||
{
|
||||
return index == idx;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -907,7 +907,7 @@ public class SelectStatement implements CQLStatement
|
|||
final ColumnDefinition def = cfm.getColumnDefinition(column);
|
||||
if (def == null)
|
||||
handleUnrecognizedOrderingColumn(column);
|
||||
int index = selection.indexOf(def);
|
||||
int index = selection.getResultSetIndex(def);
|
||||
if (index < 0)
|
||||
index = selection.addColumnForOrdering(def);
|
||||
orderingIndexes.put(def.name, index);
|
||||
|
|
|
|||
|
|
@ -338,6 +338,58 @@ public class SelectOrderByTest extends CQLTester
|
|||
|
||||
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");
|
||||
execute("INSERT INTO %s (pk1, pk2, c, v) VALUES (?, ?, ?, ?)", 1, 2, 1, "B");
|
||||
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));
|
||||
|
||||
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 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");
|
||||
execute("INSERT INTO %s (pk1, pk2, c1, c2, v) VALUES (?, ?, ?, ?, ?)", 1, 2, 1, 2, "B");
|
||||
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));
|
||||
|
||||
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 as c2 FROM %s where pk1 = ? AND pk2 IN (?, ?) ORDER BY c1, c2; ", 1, 1, 2),
|
||||
row("B"),
|
||||
row("D"),
|
||||
row("A"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue