maedhroz commented on code in PR #2916: URL: https://github.com/apache/cassandra/pull/2916#discussion_r1397976468
########## src/java/org/apache/cassandra/index/sai/utils/IndexTermType.java: ########## @@ -0,0 +1,858 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.index.sai.utils; + +import java.math.BigInteger; +import java.net.InetAddress; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; + +import com.google.common.base.MoreObjects; +import com.google.common.collect.ImmutableSet; + +import com.googlecode.concurrenttrees.radix.ConcurrentRadixTree; +import org.apache.cassandra.cql3.CQL3Type; +import org.apache.cassandra.cql3.Operator; +import org.apache.cassandra.cql3.statements.schema.IndexTarget; +import org.apache.cassandra.db.DecoratedKey; +import org.apache.cassandra.db.filter.RowFilter; +import org.apache.cassandra.db.marshal.AbstractType; +import org.apache.cassandra.db.marshal.AsciiType; +import org.apache.cassandra.db.marshal.BooleanType; +import org.apache.cassandra.db.marshal.ByteBufferAccessor; +import org.apache.cassandra.db.marshal.CollectionType; +import org.apache.cassandra.db.marshal.CompositeType; +import org.apache.cassandra.db.marshal.DecimalType; +import org.apache.cassandra.db.marshal.InetAddressType; +import org.apache.cassandra.db.marshal.IntegerType; +import org.apache.cassandra.db.marshal.LongType; +import org.apache.cassandra.db.marshal.StringType; +import org.apache.cassandra.db.marshal.UTF8Type; +import org.apache.cassandra.db.marshal.UUIDType; +import org.apache.cassandra.db.marshal.VectorType; +import org.apache.cassandra.db.rows.Cell; +import org.apache.cassandra.db.rows.ComplexColumnData; +import org.apache.cassandra.db.rows.Row; +import org.apache.cassandra.index.sai.plan.Expression; +import org.apache.cassandra.schema.ColumnMetadata; +import org.apache.cassandra.serializers.MarshalException; +import org.apache.cassandra.utils.ByteBufferUtil; +import org.apache.cassandra.utils.FastByteOperations; +import org.apache.cassandra.utils.bytecomparable.ByteComparable; +import org.apache.cassandra.utils.bytecomparable.ByteSource; +import org.apache.cassandra.utils.bytecomparable.ByteSourceInverse; + +/** + * This class is a representation of an {@link AbstractType} as an indexable type. It is responsible for determining the + * capabilities of the type and provides helper methods for handling term values associated with the type. + */ +public class IndexTermType +{ + private static final Set<AbstractType<?>> EQ_ONLY_TYPES = ImmutableSet.of(UTF8Type.instance, + AsciiType.instance, + BooleanType.instance, + UUIDType.instance); + + private static final byte[] IPV4_PREFIX = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1 }; + + /** + * DecimalType / BigDecimal values are indexed by truncating their asComparableBytes representation to this size, + * padding on the right with zero-value-bytes until this size is reached (if necessary). This causes + * false-positives that must be filtered in a separate step after hitting the index and reading the associated + * (full) values. + */ + private static final int DECIMAL_APPROXIMATION_BYTES = 24; + private static final int BIG_INTEGER_APPROXIMATION_BYTES = 20; + private static final int INET_ADDRESS_SIZE = 16; + private static final int DEFAULT_FIXED_LENGTH = 16; + + private static final int IS_LITERAL = 1; + private static final int IS_STRING = 1 << 1; + private static final int IS_VECTOR = 1 << 2; + private static final int IS_REVERSED = 1 << 3; + private static final int IS_FROZEN = 1 << 4; + private static final int IS_NON_FROZEN_COLLECTION = 1 << 5; + private static final int IS_COMPOSITE = 1 << 6; + private static final int IS_INET_ADDRESS = 1 << 7; + private static final int IS_BIG_INTEGER = 1 << 8; + private static final int IS_BIG_DECIMAL = 1 << 9; + private static final int IS_LONG = 1 << 10; + private static final int IS_COMPOSITE_PARTITION = 1 << 11; Review Comment: ...and usage... ``` private boolean isCompositePartition() { return capabilities.contains(Flag.IS_COMPOSITE_PARTITION); } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

