Search in sources :

Example 16 with Row

use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.

the class ItTablePersistenceTest method snapshotCheckClosure.

/**
 * {@inheritDoc}
 */
@Override
public BooleanSupplier snapshotCheckClosure(JraftServerImpl restarted, boolean interactedAfterSnapshot) {
    VersionedRowStore storage = getListener(restarted, raftGroupId()).getStorage();
    Row key = interactedAfterSnapshot ? SECOND_KEY : FIRST_KEY;
    Row value = interactedAfterSnapshot ? SECOND_VALUE : FIRST_VALUE;
    return () -> {
        BinaryRow read = storage.get(key, null);
        if (read == null) {
            return false;
        }
        return Arrays.equals(value.bytes(), read.bytes());
    };
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) BinaryRow(org.apache.ignite.internal.schema.BinaryRow)

Example 17 with Row

use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.

the class ItTablePersistenceTest method createKeyRow.

/**
 * Creates a {@link Row} with the supplied key.
 *
 * @param id Key.
 * @return Row.
 */
private static Row createKeyRow(long id) {
    RowAssembler rowBuilder = new RowAssembler(SCHEMA, 0, 0);
    rowBuilder.appendLong(id);
    return new Row(SCHEMA, new ByteBufferRow(rowBuilder.toBytes()));
}
Also used : ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow)

Example 18 with Row

use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.

the class BinaryRowComparator method columnComparator.

/**
 * Creates a comparator for comparing table columns.
 */
private static Comparator<Row> columnComparator(Column column) {
    int schemaIndex = column.schemaIndex();
    NativeTypeSpec typeSpec = column.type().spec();
    switch(typeSpec) {
        case INT8:
            return (row1, row2) -> {
                byte value1 = row1.byteValue(schemaIndex);
                byte value2 = row2.byteValue(schemaIndex);
                return Byte.compare(value1, value2);
            };
        case INT16:
            return (row1, row2) -> {
                short value1 = row1.shortValue(schemaIndex);
                short value2 = row2.shortValue(schemaIndex);
                return Short.compare(value1, value2);
            };
        case INT32:
            return comparingInt(row -> row.intValue(schemaIndex));
        case INT64:
            return comparingLong(row -> row.longValue(schemaIndex));
        case FLOAT:
            return (row1, row2) -> {
                float value1 = row1.floatValue(schemaIndex);
                float value2 = row2.floatValue(schemaIndex);
                return Float.compare(value1, value2);
            };
        case DOUBLE:
            return comparingDouble(row -> row.doubleValue(schemaIndex));
        case BYTES:
            return comparing(row -> row.bytesValue(schemaIndex), Arrays::compare);
        case BITMASK:
            return comparing(row -> row.bitmaskValue(schemaIndex).toLongArray(), Arrays::compare);
        // all other types implement Comparable
        case DECIMAL:
        case UUID:
        case STRING:
        case NUMBER:
        case TIMESTAMP:
        case DATE:
        case TIME:
        case DATETIME:
            return comparing(row -> (Comparable) typeSpec.objectValue(row, schemaIndex));
        default:
            throw new IllegalArgumentException(String.format("Unsupported column schema for creating a sorted index. Column name: %s, column type: %s", column.name(), column.type()));
    }
}
Also used : ComparatorUtils.comparingNull(org.apache.ignite.internal.storage.rocksdb.index.ComparatorUtils.comparingNull) Comparator.comparingInt(java.util.Comparator.comparingInt) Arrays(java.util.Arrays) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) SortedIndexDescriptor(org.apache.ignite.internal.storage.index.SortedIndexDescriptor) Comparator.comparingDouble(java.util.Comparator.comparingDouble) NativeTypeSpec(org.apache.ignite.internal.schema.NativeTypeSpec) AbstractComparator(org.rocksdb.AbstractComparator) ByteBuffer(java.nio.ByteBuffer) ByteOrder(java.nio.ByteOrder) ComparatorOptions(org.rocksdb.ComparatorOptions) Comparator.comparingLong(java.util.Comparator.comparingLong) Row(org.apache.ignite.internal.schema.row.Row) Column(org.apache.ignite.internal.schema.Column) Comparator.comparing(java.util.Comparator.comparing) Comparator(java.util.Comparator) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) NativeTypeSpec(org.apache.ignite.internal.schema.NativeTypeSpec) Arrays(java.util.Arrays)

Example 19 with Row

use of org.apache.ignite.internal.schema.row.Row in project ignite-3 by apache.

the class BinaryRowComparator method rowComparator.

/**
 * Creates a comparator that compares two {@link Row}s by comparing individual columns.
 */
private static Comparator<Row> rowComparator(SortedIndexDescriptor descriptor) {
    return descriptor.indexRowColumns().stream().map(columnDescriptor -> {
        Column column = columnDescriptor.column();
        Comparator<Row> columnComparator = columnComparator(column);
        if (columnDescriptor.nullable()) {
            columnComparator = comparingNull(row -> row.hasNullValue(column.schemaIndex(), column.type().spec()) ? null : row, columnComparator);
        }
        return columnDescriptor.asc() ? columnComparator : columnComparator.reversed();
    }).reduce(Comparator::thenComparing).orElseThrow();
}
Also used : ComparatorUtils.comparingNull(org.apache.ignite.internal.storage.rocksdb.index.ComparatorUtils.comparingNull) Comparator.comparingInt(java.util.Comparator.comparingInt) Arrays(java.util.Arrays) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) SortedIndexDescriptor(org.apache.ignite.internal.storage.index.SortedIndexDescriptor) Comparator.comparingDouble(java.util.Comparator.comparingDouble) NativeTypeSpec(org.apache.ignite.internal.schema.NativeTypeSpec) AbstractComparator(org.rocksdb.AbstractComparator) ByteBuffer(java.nio.ByteBuffer) ByteOrder(java.nio.ByteOrder) ComparatorOptions(org.rocksdb.ComparatorOptions) Comparator.comparingLong(java.util.Comparator.comparingLong) Row(org.apache.ignite.internal.schema.row.Row) Column(org.apache.ignite.internal.schema.Column) Comparator.comparing(java.util.Comparator.comparing) Comparator(java.util.Comparator) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) Column(org.apache.ignite.internal.schema.Column) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow)

Example 20 with Row

use of org.apache.ignite.internal.schema.row.Row 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)

Aggregations

Row (org.apache.ignite.internal.schema.row.Row)83 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)55 Column (org.apache.ignite.internal.schema.Column)34 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)30 NotNull (org.jetbrains.annotations.NotNull)25 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 MethodSource (org.junit.jupiter.params.provider.MethodSource)22 Tuple (org.apache.ignite.table.Tuple)21 Test (org.junit.jupiter.api.Test)18 ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)17 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)15 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)15 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)15 RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)14 ArrayList (java.util.ArrayList)8 InternalTransaction (org.apache.ignite.internal.tx.InternalTransaction)6 Random (java.util.Random)5 MarshallerException (org.apache.ignite.internal.schema.marshaller.MarshallerException)5 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)5 IgniteException (org.apache.ignite.lang.IgniteException)5