Search in sources :

Example 1 with ColumnDescriptor

use of org.apache.ignite.internal.storage.index.SortedIndexDescriptor.ColumnDescriptor in project ignite-3 by apache.

the class PrefixComparator method compare.

/**
 * Compares a given row with the configured prefix.
 *
 * @param binaryRow Row to compare.
 * @return the value {@code 0} if the given row starts with the configured prefix;
 *         a value less than {@code 0} if the row's prefix is smaller than the prefix; and
 *         a value greater than {@code 0} if the row's prefix is larger than the prefix.
 */
int compare(BinaryRow binaryRow) {
    var row = new Row(descriptor.asSchemaDescriptor(), binaryRow);
    for (int i = 0; i < prefix.length; ++i) {
        ColumnDescriptor columnDescriptor = descriptor.indexRowColumns().get(i);
        int compare = compare(columnDescriptor.column(), row, prefix[i]);
        if (compare != 0) {
            return columnDescriptor.asc() ? compare : -compare;
        }
    }
    return 0;
}
Also used : ColumnDescriptor(org.apache.ignite.internal.storage.index.SortedIndexDescriptor.ColumnDescriptor) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row)

Example 2 with ColumnDescriptor

use of org.apache.ignite.internal.storage.index.SortedIndexDescriptor.ColumnDescriptor in project ignite-3 by apache.

the class IndexRowWrapper method randomRow.

/**
 * Creates an Entry with a random key that satisfies the given schema and a random value.
 */
static IndexRowWrapper randomRow(SortedIndexStorage indexStorage) {
    var random = new Random();
    Object[] columns = indexStorage.indexDescriptor().indexRowColumns().stream().map(ColumnDescriptor::column).map(column -> generateRandomValue(random, column.type())).toArray();
    var primaryKey = new ByteArraySearchRow(randomBytes(random, 25));
    IndexRow row = indexStorage.indexRowFactory().createIndexRow(columns, primaryKey);
    return new IndexRowWrapper(indexStorage, row, columns);
}
Also used : ComparatorUtils.comparingNull(org.apache.ignite.internal.storage.rocksdb.index.ComparatorUtils.comparingNull) IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) Array(java.lang.reflect.Array) SchemaTestUtils(org.apache.ignite.internal.schema.SchemaTestUtils) SortedIndexDescriptor(org.apache.ignite.internal.storage.index.SortedIndexDescriptor) Random(java.util.Random) IgniteTestUtils.randomBytes(org.apache.ignite.internal.testframework.IgniteTestUtils.randomBytes) Function(java.util.function.Function) Objects(java.util.Objects) ColumnDescriptor(org.apache.ignite.internal.storage.index.SortedIndexDescriptor.ColumnDescriptor) IndexRowPrefix(org.apache.ignite.internal.storage.index.IndexRowPrefix) SortedIndexStorage(org.apache.ignite.internal.storage.index.SortedIndexStorage) SchemaTestUtils.generateRandomValue(org.apache.ignite.internal.schema.SchemaTestUtils.generateRandomValue) Comparator.comparing(java.util.Comparator.comparing) BitSet(java.util.BitSet) Comparator(java.util.Comparator) NotNull(org.jetbrains.annotations.NotNull) IndexRow(org.apache.ignite.internal.storage.index.IndexRow) Random(java.util.Random) IndexRow(org.apache.ignite.internal.storage.index.IndexRow) ColumnDescriptor(org.apache.ignite.internal.storage.index.SortedIndexDescriptor.ColumnDescriptor)

Aggregations

ColumnDescriptor (org.apache.ignite.internal.storage.index.SortedIndexDescriptor.ColumnDescriptor)2 Array (java.lang.reflect.Array)1 Arrays (java.util.Arrays)1 BitSet (java.util.BitSet)1 Comparator (java.util.Comparator)1 Comparator.comparing (java.util.Comparator.comparing)1 Objects (java.util.Objects)1 Random (java.util.Random)1 Function (java.util.function.Function)1 IntStream (java.util.stream.IntStream)1 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)1 SchemaTestUtils (org.apache.ignite.internal.schema.SchemaTestUtils)1 SchemaTestUtils.generateRandomValue (org.apache.ignite.internal.schema.SchemaTestUtils.generateRandomValue)1 Row (org.apache.ignite.internal.schema.row.Row)1 IndexRow (org.apache.ignite.internal.storage.index.IndexRow)1 IndexRowPrefix (org.apache.ignite.internal.storage.index.IndexRowPrefix)1 SortedIndexDescriptor (org.apache.ignite.internal.storage.index.SortedIndexDescriptor)1 SortedIndexStorage (org.apache.ignite.internal.storage.index.SortedIndexStorage)1 ComparatorUtils.comparingNull (org.apache.ignite.internal.storage.rocksdb.index.ComparatorUtils.comparingNull)1 IgniteTestUtils.randomBytes (org.apache.ignite.internal.testframework.IgniteTestUtils.randomBytes)1