Skip to content

Commit 72eeb37

Browse files
adelapenadjatnieks
authored andcommitted
CNDB-12774: Not index empty non-literal values (#1556)
Also, prevent encoding error when searching empty varint and decimal values
1 parent 943c943 commit 72eeb37

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/java/org/apache/cassandra/index/sai/disk/v1/SSTableIndexWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ else if (shouldFlush(sstableRowId))
240240
currentBuilder = newSegmentBuilder(sstableRowId);
241241
}
242242

243-
if (term.remaining() == 0 && !indexContext.getValidator().allowsEmpty())
243+
if (term.remaining() == 0 && TypeUtil.skipsEmptyValue(indexContext.getValidator()))
244244
return;
245245

246246
long allocated = currentBuilder.addAll(term, type, key, sstableRowId);

src/java/org/apache/cassandra/index/sai/memory/TrieMemtableIndex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public ByteBuffer getMaxTerm()
168168
@Override
169169
public void index(DecoratedKey key, Clustering clustering, ByteBuffer value, Memtable memtable, OpOrder.Group opGroup)
170170
{
171-
if (value == null || (value.remaining() == 0 && !validator.allowsEmpty()))
171+
if (value == null || (value.remaining() == 0 && TypeUtil.skipsEmptyValue(validator)))
172172
return;
173173

174174
RequestSensors sensors = requestTracker.get();

src/java/org/apache/cassandra/index/sai/utils/TypeUtil.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ else if (isBigDecimal(type))
278278
*/
279279
public static ByteBuffer asIndexBytes(ByteBuffer value, AbstractType<?> type)
280280
{
281-
if (value == null)
282-
return null;
281+
if (value == null || value.remaining() == 0)
282+
return value;
283283

284284
if (isInetAddress(type))
285285
return encodeInetAddress(value);
@@ -649,6 +649,14 @@ public static boolean isComposite(AbstractType<?> type)
649649
return type instanceof CompositeType;
650650
}
651651

652+
/**
653+
* @return {@code true} if the empty values of the given type should be excluded from indexing, {@code false} otherwise.
654+
*/
655+
public static boolean skipsEmptyValue(AbstractType<?> type)
656+
{
657+
return !type.allowsEmpty() || !isLiteral(type);
658+
}
659+
652660
/**
653661
* @return base type if given type is reversed, otherwise return itself
654662
*/

0 commit comments

Comments
 (0)