mirror of https://github.com/apache/cassandra
Fix ColumnMetadata.cellValueType() return type and change sstabledump tool to use type.toJsonString()
patch by Zhao Yang, reviewed by Andres de la Peña for CASSANDRA-13573
This commit is contained in:
parent
918667929f
commit
3960260472
|
|
@ -1,4 +1,5 @@
|
|||
3.0.15
|
||||
* Fix ColumnDefinition.cellValueType() for non-frozen collection and change SSTabledump to use type.toJSONString() (CASSANDRA-13573)
|
||||
* Skip materialized view addition if the base table doesn't exist (CASSANDRA-13737)
|
||||
* Drop table should remove corresponding entries in dropped_columns table (CASSANDRA-13730)
|
||||
* Log warn message until legacy auth tables have been migrated (CASSANDRA-13371)
|
||||
|
|
|
|||
|
|
@ -391,13 +391,24 @@ public class ColumnDefinition extends ColumnSpecification implements Comparable<
|
|||
/**
|
||||
* The type of the cell values for cell belonging to this column.
|
||||
*
|
||||
* This is the same than the column type, except for collections where it's the 'valueComparator'
|
||||
* This is the same than the column type, except for non-frozen collections where it's the 'valueComparator'
|
||||
* of the collection.
|
||||
*
|
||||
* This method should not be used to get value type of non-frozon UDT.
|
||||
*/
|
||||
public AbstractType<?> cellValueType()
|
||||
{
|
||||
return type instanceof CollectionType
|
||||
? ((CollectionType)type).valueComparator()
|
||||
: type;
|
||||
assert !(type instanceof UserType && type.isMultiCell());
|
||||
return type instanceof CollectionType && type.isMultiCell()
|
||||
? ((CollectionType)type).valueComparator()
|
||||
: type;
|
||||
}
|
||||
|
||||
|
||||
public boolean isCounterColumn()
|
||||
{
|
||||
if (type instanceof CollectionType) // for thrift
|
||||
return ((CollectionType) type).valueComparator().isCounter();
|
||||
return type.isCounter();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ public class BTreeRow extends AbstractRow
|
|||
|
||||
public Row markCounterLocalToBeCleared()
|
||||
{
|
||||
return transformAndFilter(primaryKeyLivenessInfo, deletion, (cd) -> cd.column().cellValueType().isCounter()
|
||||
return transformAndFilter(primaryKeyLivenessInfo, deletion, (cd) -> cd.column().isCounterColumn()
|
||||
? cd.markCounterLocalToBeCleared()
|
||||
: cd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ public class BufferCell extends AbstractCell
|
|||
|
||||
public boolean isCounterCell()
|
||||
{
|
||||
return !isTombstone() && column.cellValueType().isCounter();
|
||||
return !isTombstone() && column.isCounterColumn();
|
||||
}
|
||||
|
||||
public boolean isLive(int nowInSec)
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import org.apache.cassandra.db.RangeTombstone;
|
|||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
import org.apache.cassandra.db.marshal.CollectionType;
|
||||
import org.apache.cassandra.db.marshal.CompositeType;
|
||||
import org.apache.cassandra.db.marshal.UserType;
|
||||
import org.apache.cassandra.db.rows.Cell;
|
||||
import org.apache.cassandra.db.rows.ColumnData;
|
||||
import org.apache.cassandra.db.rows.ComplexColumnData;
|
||||
|
|
@ -49,6 +50,7 @@ import org.apache.cassandra.db.rows.Row;
|
|||
import org.apache.cassandra.db.rows.Unfiltered;
|
||||
import org.apache.cassandra.db.rows.UnfilteredRowIterator;
|
||||
import org.apache.cassandra.io.sstable.ISSTableScanner;
|
||||
import org.apache.cassandra.transport.Server;
|
||||
import org.apache.cassandra.utils.ByteBufferUtil;
|
||||
import org.codehaus.jackson.JsonFactory;
|
||||
import org.codehaus.jackson.JsonGenerator;
|
||||
|
|
@ -411,7 +413,7 @@ public final class JsonTransformer
|
|||
AbstractType<?> type = cell.column().type;
|
||||
json.writeString(cell.column().name.toCQLString());
|
||||
|
||||
if (cell.path() != null && cell.path().size() > 0)
|
||||
if (type.isCollection() && type.isMultiCell()) // non-frozen collection
|
||||
{
|
||||
CollectionType ct = (CollectionType) type;
|
||||
json.writeFieldName("path");
|
||||
|
|
@ -437,7 +439,7 @@ public final class JsonTransformer
|
|||
else
|
||||
{
|
||||
json.writeFieldName("value");
|
||||
json.writeString(cell.column().cellValueType().getString(cell.value()));
|
||||
json.writeRawValue(cell.column().cellValueType().toJSONString(cell.value(), Server.CURRENT_VERSION));
|
||||
}
|
||||
if (liveInfo.isEmpty() || cell.timestamp() != liveInfo.timestamp())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1262,4 +1262,37 @@ public class ViewTest extends CQLTester
|
|||
|
||||
assertRows(execute("SELECT count(*) FROM mv_test"), row(1024L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFrozenCollectionsWithComplicatedInnerType() throws Throwable
|
||||
{
|
||||
createTable("CREATE TABLE %s (k int, intval int, listval frozen<list<tuple<text,text>>>, PRIMARY KEY (k))");
|
||||
|
||||
execute("USE " + keyspace());
|
||||
executeNet(protocolVersion, "USE " + keyspace());
|
||||
|
||||
createView("mv",
|
||||
"CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE k IS NOT NULL AND listval IS NOT NULL PRIMARY KEY (k, listval)");
|
||||
|
||||
updateView("INSERT INTO %s (k, intval, listval) VALUES (?, ?, fromJson(?))",
|
||||
0,
|
||||
0,
|
||||
"[[\"a\", \"1\"], [\"b\", \"2\"], [\"c\", \"3\"]]");
|
||||
|
||||
// verify input
|
||||
assertRows(execute("SELECT k, toJson(listval) FROM %s WHERE k = ?", 0),
|
||||
row(0, "[[\"a\", \"1\"], [\"b\", \"2\"], [\"c\", \"3\"]]"));
|
||||
assertRows(execute("SELECT k, toJson(listval) from mv"),
|
||||
row(0, "[[\"a\", \"1\"], [\"b\", \"2\"], [\"c\", \"3\"]]"));
|
||||
|
||||
// update listval with the same value and it will be compared in view generator
|
||||
updateView("INSERT INTO %s (k, listval) VALUES (?, fromJson(?))",
|
||||
0,
|
||||
"[[\"a\", \"1\"], [\"b\", \"2\"], [\"c\", \"3\"]]");
|
||||
// verify result
|
||||
assertRows(execute("SELECT k, toJson(listval) FROM %s WHERE k = ?", 0),
|
||||
row(0, "[[\"a\", \"1\"], [\"b\", \"2\"], [\"c\", \"3\"]]"));
|
||||
assertRows(execute("SELECT k, toJson(listval) from mv"),
|
||||
row(0, "[[\"a\", \"1\"], [\"b\", \"2\"], [\"c\", \"3\"]]"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue