diff --git a/src/java/org/apache/cassandra/index/sai/IndexContext.java b/src/java/org/apache/cassandra/index/sai/IndexContext.java index 43924707326f..c79c91f05a2d 100644 --- a/src/java/org/apache/cassandra/index/sai/IndexContext.java +++ b/src/java/org/apache/cassandra/index/sai/IndexContext.java @@ -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); @@ -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() diff --git a/src/java/org/apache/cassandra/index/sai/StorageAttachedIndex.java b/src/java/org/apache/cassandra/index/sai/StorageAttachedIndex.java index 3135f3f51a1d..ac96ae9fd4b3 100644 --- a/src/java/org/apache/cassandra/index/sai/StorageAttachedIndex.java +++ b/src/java/org/apache/cassandra/index/sai/StorageAttachedIndex.java @@ -333,7 +333,7 @@ public static Map validateOptions(Map 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()); } } @@ -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()); } diff --git a/src/java/org/apache/cassandra/index/sai/disk/v4/V4OnDiskFormat.java b/src/java/org/apache/cassandra/index/sai/disk/v4/V4OnDiskFormat.java index c6fd9d3e9aa8..8b597ee4d347 100644 --- a/src/java/org/apache/cassandra/index/sai/disk/v4/V4OnDiskFormat.java +++ b/src/java/org/apache/cassandra/index/sai/disk/v4/V4OnDiskFormat.java @@ -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); diff --git a/src/java/org/apache/cassandra/index/sai/utils/TypeUtil.java b/src/java/org/apache/cassandra/index/sai/utils/TypeUtil.java index 1ddeb4da88c6..228532cd2ef2 100644 --- a/src/java/org/apache/cassandra/index/sai/utils/TypeUtil.java +++ b/src/java/org/apache/cassandra/index/sai/utils/TypeUtil.java @@ -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); @@ -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)); } @@ -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; } /** @@ -495,21 +495,23 @@ public static boolean isUTF8OrAscii(AbstractType type) // } // /** - * Returns true if given {@link AbstractType} is a Composite(map entry) or frozen. + * Returns true 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 true if given {@link AbstractType} is frozen. + * Returns true 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(); } /** diff --git a/test/unit/org/apache/cassandra/index/sai/disk/TypeUtilTest.java b/test/unit/org/apache/cassandra/index/sai/disk/TypeUtilTest.java index b5d23d2d4cc3..a955a97b6bea 100644 --- a/test/unit/org/apache/cassandra/index/sai/disk/TypeUtilTest.java +++ b/test/unit/org/apache/cassandra/index/sai/disk/TypeUtilTest.java @@ -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; @@ -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; @@ -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)); } } @@ -148,7 +150,7 @@ 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"), @@ -156,11 +158,24 @@ public void testUDT() 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 type = VectorType.getInstance(FloatType.instance, dimension); + + assertFalse(TypeUtil.isFrozenCollection(type)); + assertFalse(TypeUtil.isNonVectorFrozenMultivalued(type)); + assertFalse(TypeUtil.isLiteral(type)); + } + } + private static void testCollectionType(BiFunction, Boolean, AbstractType> init, BiConsumer, AbstractType> nonFrozenCollectionTester) {