Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CNDB-10964: Update TypeUtil#isFrozen not to include vectors #1305

Draft
wants to merge 1 commit into
base: main-5.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/java/org/apache/cassandra/index/sai/IndexContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public IndexContext(@Nonnull String keyspace,

this.maxTermSize = isVector() ? MAX_VECTOR_TERM_SIZE
: isAnalyzed ? MAX_ANALYZED_SIZE
: isFrozen() ? MAX_FROZEN_TERM_SIZE : MAX_STRING_TERM_SIZE;
: isNonVectorFrozenMultivalued() ? MAX_FROZEN_TERM_SIZE : MAX_STRING_TERM_SIZE;


logger.debug(logMessage("Initialized index context with index writer config: {}"), indexWriterConfig);
Expand Down Expand Up @@ -562,9 +562,9 @@ public boolean isCollection()
return column.type.isCollection();
}

public boolean isFrozen()
public boolean isNonVectorFrozenMultivalued()
{
return TypeUtil.isFrozen(column.type);
return TypeUtil.isNonVectorFrozenMultivalued(column.type);
}

public String getColumnName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public static Map<String, String> validateOptions(Map<String, String> options, T
{
for (AbstractType<?> subType : type.subTypes())
{
if (!SUPPORTED_TYPES.contains(subType.asCQL3Type()) && !TypeUtil.isFrozen(subType))
if (!SUPPORTED_TYPES.contains(subType.asCQL3Type()) && !TypeUtil.isNonVectorFrozenMultivalued(subType))
throw new InvalidRequestException("Unsupported composite type for SAI: " + subType.asCQL3Type());
}
}
Expand All @@ -360,7 +360,7 @@ else if (type.isVector())
logger.warn(error);
}
}
else if (!SUPPORTED_TYPES.contains(type.asCQL3Type()) && !TypeUtil.isFrozen(type))
else if (!SUPPORTED_TYPES.contains(type.asCQL3Type()) && !TypeUtil.isNonVectorFrozenMultivalued(type))
{
throw new InvalidRequestException("Unsupported type for SAI: " + type.asCQL3Type());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public IndexSearcher newIndexSearcher(SSTableContext sstableContext,
PerIndexFiles indexFiles,
SegmentMetadata segmentMetadata) throws IOException
{
if (indexContext.isVector())
return super.newIndexSearcher(sstableContext, indexContext, indexFiles, segmentMetadata);
if (indexContext.isLiteral())
return new V4InvertedIndexSearcher(sstableContext, indexFiles, segmentMetadata, indexContext);
return super.newIndexSearcher(sstableContext, indexContext, indexFiles, segmentMetadata);
Expand Down
20 changes: 11 additions & 9 deletions src/java/org/apache/cassandra/index/sai/utils/TypeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public static int comparePostFilter(Expression.Value requestedValue, Expression.
if (isInetAddress(type))
return compareInet(requestedValue.encoded, columnValue.encoded);
// Override comparisons for frozen collections
else if (isFrozen(type))
else if (isNonVectorFrozenMultivalued(type))
return FastByteOperations.compareUnsigned(requestedValue.raw, columnValue.raw);

return type.compare(requestedValue.raw, columnValue.raw);
Expand Down Expand Up @@ -345,7 +345,7 @@ private static boolean useFastByteOperations(AbstractType<?> type, Version versi
// composite types are compared using their AbstractType.
return isBigInteger(type)
|| isBigDecimal(type)
|| (!isComposite(type) && isFrozen(type))
|| (!isComposite(type) && isNonVectorFrozenMultivalued(type))
|| (isComposite(type) && !version.onOrAfter(Version.DB));
}

Expand Down Expand Up @@ -473,7 +473,7 @@ public static ByteBuffer encodeBigInteger(ByteBuffer value)
*/
public static boolean isLiteral(AbstractType<?> type)
{
return isUTF8OrAscii(type) || isCompositeOrFrozen(type) || baseType(type) instanceof BooleanType;
return isUTF8OrAscii(type) || isCompositeOrNonVectorFrozenMultivalued(type) || baseType(type) instanceof BooleanType;
}

/**
Expand All @@ -495,21 +495,23 @@ public static boolean isUTF8OrAscii(AbstractType<?> type)
// }
//
/**
* Returns <code>true</code> if given {@link AbstractType} is a Composite(map entry) or frozen.
* Returns <code>true</code> if given {@link AbstractType} is a Composite(map entry) or a non-vector frozen
* multivalued type (see {@link #isNonVectorFrozenMultivalued(AbstractType)}.
*/
public static boolean isCompositeOrFrozen(AbstractType<?> type)
public static boolean isCompositeOrNonVectorFrozenMultivalued(AbstractType<?> type)
{
type = baseType(type);
return type instanceof CompositeType || isFrozen(type);
return type instanceof CompositeType || isNonVectorFrozenMultivalued(type);
}

/**
* Returns <code>true</code> if given {@link AbstractType} is frozen.
* Returns <code>true</code> if given {@link AbstractType} has subtypes, and it's not multicell nor a vector.
* This should include frozen collections, tuples and UDTs.
*/
public static boolean isFrozen(AbstractType<?> type)
public static boolean isNonVectorFrozenMultivalued(AbstractType<?> type)
{
type = baseType(type);
return !type.subTypes().isEmpty() && !type.isMultiCell();
return !type.isVector() && !type.subTypes().isEmpty() && !type.isMultiCell();
}

/**
Expand Down
23 changes: 19 additions & 4 deletions test/unit/org/apache/cassandra/index/sai/disk/TypeUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.cassandra.cql3.statements.schema.IndexTarget;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.CompositeType;
import org.apache.cassandra.db.marshal.FloatType;
import org.apache.cassandra.db.marshal.Int32Type;
import org.apache.cassandra.db.marshal.IntegerType;
import org.apache.cassandra.db.marshal.ListType;
Expand All @@ -44,6 +45,7 @@
import org.apache.cassandra.db.marshal.TupleType;
import org.apache.cassandra.db.marshal.UTF8Type;
import org.apache.cassandra.db.marshal.UserType;
import org.apache.cassandra.db.marshal.VectorType;
import org.apache.cassandra.index.sai.StorageAttachedIndex;
import org.apache.cassandra.index.sai.analyzer.AbstractAnalyzer;
import org.apache.cassandra.index.sai.disk.format.Version;
Expand Down Expand Up @@ -127,12 +129,12 @@ public void testTuple()
{
TupleType type = new TupleType(Arrays.asList(elementType.getType(), elementType.getType()), true);
assertFalse(TypeUtil.isFrozenCollection(type));
assertFalse(TypeUtil.isFrozen(type));
assertFalse(TypeUtil.isNonVectorFrozenMultivalued(type));
assertFalse(TypeUtil.isLiteral(type));

type = new TupleType(Arrays.asList(elementType.getType(), elementType.getType()), false);
assertFalse(TypeUtil.isFrozenCollection(type));
assertTrue(TypeUtil.isFrozen(type));
assertTrue(TypeUtil.isNonVectorFrozenMultivalued(type));
assertTrue(TypeUtil.isLiteral(type));
}
}
Expand All @@ -148,19 +150,32 @@ public void testUDT()
true);

assertFalse(TypeUtil.isFrozenCollection(type));
assertFalse(TypeUtil.isFrozen(type));
assertFalse(TypeUtil.isNonVectorFrozenMultivalued(type));
assertFalse(TypeUtil.isLiteral(type));

type = new UserType("ks", ByteBufferUtil.bytes("myType"),
Arrays.asList(FieldIdentifier.forQuoted("f1"), FieldIdentifier.forQuoted("f2")),
Arrays.asList(elementType.getType(), elementType.getType()),
false);
assertFalse(TypeUtil.isFrozenCollection(type));
assertTrue(TypeUtil.isFrozen(type));
assertTrue(TypeUtil.isNonVectorFrozenMultivalued(type));
assertTrue(TypeUtil.isLiteral(type));
}
}

@Test
public void testVector()
{
for (int dimension = 1; dimension < 2; dimension++)
{
VectorType<Float> type = VectorType.getInstance(FloatType.instance, dimension);

assertFalse(TypeUtil.isFrozenCollection(type));
assertFalse(TypeUtil.isNonVectorFrozenMultivalued(type));
assertFalse(TypeUtil.isLiteral(type));
}
}

private static void testCollectionType(BiFunction<AbstractType<?>, Boolean, AbstractType<?>> init,
BiConsumer<AbstractType<?>, AbstractType<?>> nonFrozenCollectionTester)
{
Expand Down