Search in sources :

Example 21 with ByteBufferRow

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

the class RocksDbSortedIndexStorage method range.

@Override
public Cursor<IndexRow> range(IndexRowPrefix lowerBound, IndexRowPrefix upperBound) {
    RocksIterator iter = indexCf.newIterator();
    iter.seekToFirst();
    return new RocksIteratorAdapter<>(iter) {

        @Nullable
        private PrefixComparator lowerBoundComparator = new PrefixComparator(descriptor, lowerBound);

        private final PrefixComparator upperBoundComparator = new PrefixComparator(descriptor, upperBound);

        @Override
        public boolean hasNext() {
            while (super.hasNext()) {
                var row = new ByteBufferRow(it.key());
                if (lowerBoundComparator != null) {
                    // if lower comparator is not null, then the lower bound has not yet been reached
                    if (lowerBoundComparator.compare(row) < 0) {
                        it.next();
                        continue;
                    } else {
                        // once the lower bound is reached, we no longer need to check it
                        lowerBoundComparator = null;
                    }
                }
                return upperBoundComparator.compare(row) <= 0;
            }
            return false;
        }

        @Override
        protected IndexRow decodeEntry(byte[] key, byte[] value) {
            return new BinaryIndexRow(key, value);
        }
    };
}
Also used : ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) RocksIterator(org.rocksdb.RocksIterator) RocksIteratorAdapter(org.apache.ignite.internal.rocksdb.RocksIteratorAdapter)

Example 22 with ByteBufferRow

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

the class UpgradingRowAdapterTest method testVariousColumnTypes.

@Test
public void testVariousColumnTypes() {
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("keyUuidCol", NativeTypes.UUID, false) }, new Column[] { new Column("valByteCol", INT8, true), new Column("valShortCol", INT16, true), new Column("valIntCol", INT32, true), new Column("valLongCol", INT64, true), new Column("valFloatCol", FLOAT, true), new Column("valDoubleCol", DOUBLE, true), new Column("valDateCol", DATE, true), new Column("valTimeCol", time(), true), new Column("valDateTimeCol", datetime(), true), new Column("valTimeStampCol", timestamp(), true), new Column("valBitmask1Col", NativeTypes.bitmaskOf(22), true), new Column("valBytesCol", BYTES, false), new Column("valStringCol", STRING, false), new Column("valNumberCol", NativeTypes.numberOf(20), false), new Column("valDecimalCol", NativeTypes.decimalOf(25, 5), false) });
    SchemaDescriptor schema2 = new SchemaDescriptor(2, new Column[] { new Column("keyUuidCol", NativeTypes.UUID, false) }, new Column[] { new Column("added", INT8, true), new Column("valByteCol", INT8, true), new Column("valShortCol", INT16, true), new Column("valIntCol", INT32, true), new Column("valLongCol", INT64, true), new Column("valFloatCol", FLOAT, true), new Column("valDoubleCol", DOUBLE, true), new Column("valDateCol", DATE, true), new Column("valTimeCol", time(), true), new Column("valDateTimeCol", datetime(), true), new Column("valTimeStampCol", timestamp(), true), new Column("valBitmask1Col", NativeTypes.bitmaskOf(22), true), new Column("valBytesCol", BYTES, false), new Column("valStringCol", STRING, false), new Column("valNumberCol", NativeTypes.numberOf(20), false), new Column("valDecimalCol", NativeTypes.decimalOf(25, 5), false) });
    int addedColumnIndex = schema2.column("added").schemaIndex();
    schema2.columnMapping(new ColumnMapper() {

        @Override
        public ColumnMapper add(@NotNull Column col) {
            return null;
        }

        @Override
        public ColumnMapper add(int from, int to) {
            return null;
        }

        @Override
        public int map(int idx) {
            return idx < addedColumnIndex ? idx : idx == addedColumnIndex ? -1 : idx - 1;
        }

        @Override
        public Column mappedColumn(int idx) {
            return idx == addedColumnIndex ? schema2.column(idx) : null;
        }
    });
    List<Object> values = generateRowValues(schema);
    ByteBufferRow row = new ByteBufferRow(serializeValuesToRow(schema, values));
    // Validate row.
    validateRow(values, new SchemaRegistryImpl(1, v -> v == 1 ? schema : schema2, () -> INITIAL_SCHEMA_VERSION), row);
    // Validate upgraded row.
    values.add(addedColumnIndex, null);
    validateRow(values, new SchemaRegistryImpl(2, v -> v == 1 ? schema : schema2, () -> INITIAL_SCHEMA_VERSION), row);
}
Also used : DATE(org.apache.ignite.internal.schema.NativeTypes.DATE) BeforeEach(org.junit.jupiter.api.BeforeEach) LocalDateTime(java.time.LocalDateTime) Random(java.util.Random) IgniteLogger(org.apache.ignite.lang.IgniteLogger) ArrayList(java.util.ArrayList) DOUBLE(org.apache.ignite.internal.schema.NativeTypes.DOUBLE) BigDecimal(java.math.BigDecimal) INT64(org.apache.ignite.internal.schema.NativeTypes.INT64) Row(org.apache.ignite.internal.schema.row.Row) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) INITIAL_SCHEMA_VERSION(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl.INITIAL_SCHEMA_VERSION) INT8(org.apache.ignite.internal.schema.NativeTypes.INT8) LocalTime(java.time.LocalTime) BigInteger(java.math.BigInteger) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NativeType(org.apache.ignite.internal.schema.NativeType) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) FLOAT(org.apache.ignite.internal.schema.NativeTypes.FLOAT) NativeTypes.datetime(org.apache.ignite.internal.schema.NativeTypes.datetime) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) NativeTypes.timestamp(org.apache.ignite.internal.schema.NativeTypes.timestamp) SchemaTestUtils(org.apache.ignite.internal.schema.SchemaTestUtils) ColumnMapper(org.apache.ignite.internal.schema.mapping.ColumnMapper) Instant(java.time.Instant) NativeTypeSpec(org.apache.ignite.internal.schema.NativeTypeSpec) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Test(org.junit.jupiter.api.Test) BYTES(org.apache.ignite.internal.schema.NativeTypes.BYTES) List(java.util.List) NativeTypes(org.apache.ignite.internal.schema.NativeTypes) STRING(org.apache.ignite.internal.schema.NativeTypes.STRING) Column(org.apache.ignite.internal.schema.Column) LocalDate(java.time.LocalDate) NativeTypes.time(org.apache.ignite.internal.schema.NativeTypes.time) INT16(org.apache.ignite.internal.schema.NativeTypes.INT16) BitSet(java.util.BitSet) INT32(org.apache.ignite.internal.schema.NativeTypes.INT32) NotNull(org.jetbrains.annotations.NotNull) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) ColumnMapper(org.apache.ignite.internal.schema.mapping.ColumnMapper) Test(org.junit.jupiter.api.Test)

Aggregations

ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)22 Row (org.apache.ignite.internal.schema.row.Row)14 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)10 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)10 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)10 Tuple (org.apache.ignite.table.Tuple)10 Test (org.junit.jupiter.api.Test)10 RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)7 Random (java.util.Random)5 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)4 Column (org.apache.ignite.internal.schema.Column)3 SchemaAware (org.apache.ignite.internal.schema.SchemaAware)3 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)3 NativeTypeSpec (org.apache.ignite.internal.schema.NativeTypeSpec)2 Timestamp (org.apache.ignite.internal.tx.Timestamp)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 ByteBuffer (java.nio.ByteBuffer)1