Search in sources :

Example 1 with FLOAT

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

the class RecordViewOperationsTest method recordView.

/**
 * Creates RecordView.
 */
private RecordViewImpl<TestObjectWithAllTypes> recordView() {
    ClusterService clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
    Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(DummyInternalTableImpl.ADDR);
    TxManager txManager = new TxManagerImpl(clusterService, new HeapLockManager());
    MessagingService messagingService = MessagingServiceTestUtils.mockMessagingService(txManager);
    Mockito.when(clusterService.messagingService()).thenReturn(messagingService);
    DummyInternalTableImpl table = new DummyInternalTableImpl(new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager), txManager);
    Mapper<TestObjectWithAllTypes> recMapper = Mapper.of(TestObjectWithAllTypes.class);
    Column[] valCols = { new Column("primitiveByteCol".toUpperCase(), INT8, false), new Column("primitiveShortCol".toUpperCase(), INT16, false), new Column("primitiveIntCol".toUpperCase(), INT32, false), new Column("primitiveFloatCol".toUpperCase(), FLOAT, false), new Column("primitiveDoubleCol".toUpperCase(), DOUBLE, false), new Column("byteCol".toUpperCase(), INT8, true), new Column("shortCol".toUpperCase(), INT16, true), new Column("intCol".toUpperCase(), INT32, true), new Column("longCol".toUpperCase(), INT64, true), new Column("nullLongCol".toUpperCase(), INT64, true), new Column("floatCol".toUpperCase(), FLOAT, true), new Column("doubleCol".toUpperCase(), DOUBLE, true), new Column("dateCol".toUpperCase(), DATE, true), new Column("timeCol".toUpperCase(), time(), true), new Column("dateTimeCol".toUpperCase(), datetime(), true), new Column("timestampCol".toUpperCase(), timestamp(), true), new Column("uuidCol".toUpperCase(), NativeTypes.UUID, true), new Column("bitmaskCol".toUpperCase(), NativeTypes.bitmaskOf(42), true), new Column("stringCol".toUpperCase(), STRING, true), new Column("nullBytesCol".toUpperCase(), BYTES, true), new Column("bytesCol".toUpperCase(), BYTES, true), new Column("numberCol".toUpperCase(), NativeTypes.numberOf(12), true), new Column("decimalCol".toUpperCase(), NativeTypes.decimalOf(19, 3), true) };
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("primitiveLongCol".toUpperCase(), NativeTypes.INT64, false) }, valCols);
    // Validate all types are tested.
    Set<NativeTypeSpec> testedTypes = Arrays.stream(valCols).map(c -> c.type().spec()).collect(Collectors.toSet());
    Set<NativeTypeSpec> missedTypes = Arrays.stream(NativeTypeSpec.values()).filter(t -> !testedTypes.contains(t)).collect(Collectors.toSet());
    assertEquals(Collections.emptySet(), missedTypes);
    return new RecordViewImpl<>(table, new DummySchemaManagerImpl(schema), recMapper);
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) DATE(org.apache.ignite.internal.schema.NativeTypes.DATE) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) RecordView(org.apache.ignite.table.RecordView) Arrays(java.util.Arrays) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Random(java.util.Random) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) DOUBLE(org.apache.ignite.internal.schema.NativeTypes.DOUBLE) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) INT64(org.apache.ignite.internal.schema.NativeTypes.INT64) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) INT8(org.apache.ignite.internal.schema.NativeTypes.INT8) Mapper(org.apache.ignite.table.mapper.Mapper) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) MessagingService(org.apache.ignite.network.MessagingService) FLOAT(org.apache.ignite.internal.schema.NativeTypes.FLOAT) RETURNS_DEEP_STUBS(org.mockito.Answers.RETURNS_DEEP_STUBS) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) NativeTypes.datetime(org.apache.ignite.internal.schema.NativeTypes.datetime) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) NativeTypes.timestamp(org.apache.ignite.internal.schema.NativeTypes.timestamp) Collection(java.util.Collection) Set(java.util.Set) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) Collectors(java.util.stream.Collectors) NativeTypeSpec(org.apache.ignite.internal.schema.NativeTypeSpec) DummyInternalTableImpl(org.apache.ignite.internal.table.impl.DummyInternalTableImpl) TxManager(org.apache.ignite.internal.tx.TxManager) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) 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) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) NativeTypes.time(org.apache.ignite.internal.schema.NativeTypes.time) ClusterService(org.apache.ignite.network.ClusterService) INT16(org.apache.ignite.internal.schema.NativeTypes.INT16) INT32(org.apache.ignite.internal.schema.NativeTypes.INT32) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) NativeTypeSpec(org.apache.ignite.internal.schema.NativeTypeSpec) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) TxManager(org.apache.ignite.internal.tx.TxManager) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) MessagingService(org.apache.ignite.network.MessagingService) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) ClusterService(org.apache.ignite.network.ClusterService) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) Column(org.apache.ignite.internal.schema.Column) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) DummyInternalTableImpl(org.apache.ignite.internal.table.impl.DummyInternalTableImpl)

Example 2 with FLOAT

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

the class KeyValueViewOperationsTest method kvView.

/**
 * Creates key-value view.
 */
private KeyValueViewImpl<TestKeyObject, TestObjectWithAllTypes> kvView() {
    ClusterService clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
    Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(DummyInternalTableImpl.ADDR);
    TxManager txManager = new TxManagerImpl(clusterService, new HeapLockManager());
    MessagingService messagingService = MessagingServiceTestUtils.mockMessagingService(txManager);
    Mockito.when(clusterService.messagingService()).thenReturn(messagingService);
    DummyInternalTableImpl table = new DummyInternalTableImpl(new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager), txManager);
    Mapper<TestKeyObject> keyMapper = Mapper.of(TestKeyObject.class);
    Mapper<TestObjectWithAllTypes> valMapper = Mapper.of(TestObjectWithAllTypes.class);
    Column[] valCols = { new Column("primitiveByteCol".toUpperCase(), INT8, false), new Column("primitiveShortCol".toUpperCase(), INT16, false), new Column("primitiveIntCol".toUpperCase(), INT32, false), new Column("primitiveLongCol".toUpperCase(), INT64, false), new Column("primitiveFloatCol".toUpperCase(), FLOAT, false), new Column("primitiveDoubleCol".toUpperCase(), DOUBLE, false), new Column("byteCol".toUpperCase(), INT8, true), new Column("shortCol".toUpperCase(), INT16, true), new Column("intCol".toUpperCase(), INT32, true), new Column("longCol".toUpperCase(), INT64, true), new Column("nullLongCol".toUpperCase(), INT64, true), new Column("floatCol".toUpperCase(), FLOAT, true), new Column("doubleCol".toUpperCase(), DOUBLE, true), new Column("dateCol".toUpperCase(), DATE, true), new Column("timeCol".toUpperCase(), time(), true), new Column("dateTimeCol".toUpperCase(), datetime(), true), new Column("timestampCol".toUpperCase(), timestamp(), true), new Column("uuidCol".toUpperCase(), NativeTypes.UUID, true), new Column("bitmaskCol".toUpperCase(), NativeTypes.bitmaskOf(42), true), new Column("stringCol".toUpperCase(), STRING, true), new Column("nullBytesCol".toUpperCase(), BYTES, true), new Column("bytesCol".toUpperCase(), BYTES, true), new Column("numberCol".toUpperCase(), NativeTypes.numberOf(12), true), new Column("decimalCol".toUpperCase(), NativeTypes.decimalOf(19, 3), true) };
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, valCols);
    // Validate all types are tested.
    Set<NativeTypeSpec> testedTypes = Arrays.stream(valCols).map(c -> c.type().spec()).collect(Collectors.toSet());
    Set<NativeTypeSpec> missedTypes = Arrays.stream(NativeTypeSpec.values()).filter(t -> !testedTypes.contains(t)).collect(Collectors.toSet());
    assertEquals(Collections.emptySet(), missedTypes);
    return new KeyValueViewImpl<>(table, new DummySchemaManagerImpl(schema), keyMapper, valMapper);
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) DATE(org.apache.ignite.internal.schema.NativeTypes.DATE) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Random(java.util.Random) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) DOUBLE(org.apache.ignite.internal.schema.NativeTypes.DOUBLE) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) INT64(org.apache.ignite.internal.schema.NativeTypes.INT64) KeyValueView(org.apache.ignite.table.KeyValueView) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) INT8(org.apache.ignite.internal.schema.NativeTypes.INT8) Mapper(org.apache.ignite.table.mapper.Mapper) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) MessagingService(org.apache.ignite.network.MessagingService) FLOAT(org.apache.ignite.internal.schema.NativeTypes.FLOAT) RETURNS_DEEP_STUBS(org.mockito.Answers.RETURNS_DEEP_STUBS) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) NativeTypes.datetime(org.apache.ignite.internal.schema.NativeTypes.datetime) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) NativeTypes.timestamp(org.apache.ignite.internal.schema.NativeTypes.timestamp) Set(java.util.Set) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) Collectors(java.util.stream.Collectors) NativeTypeSpec(org.apache.ignite.internal.schema.NativeTypeSpec) DummyInternalTableImpl(org.apache.ignite.internal.table.impl.DummyInternalTableImpl) TxManager(org.apache.ignite.internal.tx.TxManager) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) 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) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) NativeTypes.time(org.apache.ignite.internal.schema.NativeTypes.time) ClusterService(org.apache.ignite.network.ClusterService) INT16(org.apache.ignite.internal.schema.NativeTypes.INT16) INT32(org.apache.ignite.internal.schema.NativeTypes.INT32) Collections(java.util.Collections) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) NativeTypeSpec(org.apache.ignite.internal.schema.NativeTypeSpec) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) TxManager(org.apache.ignite.internal.tx.TxManager) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) MessagingService(org.apache.ignite.network.MessagingService) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) ClusterService(org.apache.ignite.network.ClusterService) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) Column(org.apache.ignite.internal.schema.Column) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) DummyInternalTableImpl(org.apache.ignite.internal.table.impl.DummyInternalTableImpl)

Example 3 with FLOAT

use of org.apache.ignite.internal.schema.NativeTypes.FLOAT 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

List (java.util.List)3 Random (java.util.Random)3 Column (org.apache.ignite.internal.schema.Column)3 NativeTypeSpec (org.apache.ignite.internal.schema.NativeTypeSpec)3 NativeTypes (org.apache.ignite.internal.schema.NativeTypes)3 BYTES (org.apache.ignite.internal.schema.NativeTypes.BYTES)3 DATE (org.apache.ignite.internal.schema.NativeTypes.DATE)3 DOUBLE (org.apache.ignite.internal.schema.NativeTypes.DOUBLE)3 FLOAT (org.apache.ignite.internal.schema.NativeTypes.FLOAT)3 INT16 (org.apache.ignite.internal.schema.NativeTypes.INT16)3 INT32 (org.apache.ignite.internal.schema.NativeTypes.INT32)3 INT64 (org.apache.ignite.internal.schema.NativeTypes.INT64)3 INT8 (org.apache.ignite.internal.schema.NativeTypes.INT8)3 STRING (org.apache.ignite.internal.schema.NativeTypes.STRING)3 NativeTypes.datetime (org.apache.ignite.internal.schema.NativeTypes.datetime)3 NativeTypes.time (org.apache.ignite.internal.schema.NativeTypes.time)3 NativeTypes.timestamp (org.apache.ignite.internal.schema.NativeTypes.timestamp)3 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Arrays (java.util.Arrays)2