Search in sources :

Example 16 with TableDefinition

use of org.apache.ignite.schema.definition.TableDefinition in project ignite-3 by apache.

the class ItOrToUnionRuleTest method initTestData.

/**
 * Before all.
 */
@BeforeAll
static void initTestData() {
    TableDefinition schTbl1 = SchemaBuilders.tableBuilder("PUBLIC", "PRODUCTS").columns(SchemaBuilders.column("ID", ColumnType.INT32).build(), SchemaBuilders.column("CATEGORY", ColumnType.string()).asNullable(true).build(), SchemaBuilders.column("CAT_ID", ColumnType.INT32).build(), SchemaBuilders.column("SUBCATEGORY", ColumnType.string()).asNullable(true).build(), SchemaBuilders.column("SUBCAT_ID", ColumnType.INT32).build(), SchemaBuilders.column("NAME", ColumnType.string()).asNullable(true).build()).withPrimaryKey("ID").withIndex(SchemaBuilders.sortedIndex(IDX_CATEGORY).addIndexColumn("CATEGORY").done().build()).withIndex(SchemaBuilders.sortedIndex(IDX_CAT_ID).addIndexColumn("CAT_ID").done().build()).withIndex(SchemaBuilders.sortedIndex(IDX_SUBCATEGORY).addIndexColumn("SUBCATEGORY").done().build()).withIndex(SchemaBuilders.sortedIndex(IDX_SUBCAT_ID).addIndexColumn("SUBCAT_ID").done().build()).build();
    Table tbl = CLUSTER_NODES.get(0).tables().createTable(schTbl1.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(schTbl1, tblCh).changeReplicas(1).changePartitions(10));
    insertData(tbl, new String[] { "ID", "CATEGORY", "CAT_ID", "SUBCATEGORY", "SUBCAT_ID", "NAME" }, new Object[][] { { 1, "Photo", 1, "Camera Media", 11, "Media 1" }, { 2, "Photo", 1, "Camera Media", 11, "Media 2" }, { 3, "Photo", 1, "Camera Lens", 12, "Lens 1" }, { 4, "Photo", 1, "Other", 12, "Charger 1" }, { 5, "Video", 2, "Camera Media", 21, "Media 3" }, { 6, "Video", 2, "Camera Lens", 22, "Lens 3" }, { 7, "Video", 1, null, 0, "Canon" }, { 8, null, 0, "Camera Lens", 11, "Zeiss" }, { 9, null, 0, null, 0, null }, { 10, null, 0, null, 30, null }, { 11, null, 0, null, 30, null }, { 12, null, 0, null, 31, null }, { 13, null, 0, null, 31, null }, { 14, null, 0, null, 32, null }, { 15, null, 0, null, 33, null }, { 16, null, 0, null, 34, null }, { 17, null, 0, null, 35, null }, { 18, null, 0, null, 36, null }, { 19, null, 0, null, 37, null }, { 20, null, 0, null, 38, null }, { 21, null, 0, null, 39, null }, { 22, null, 0, null, 40, null }, { 23, null, 0, null, 41, null } });
}
Also used : Table(org.apache.ignite.table.Table) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 17 with TableDefinition

use of org.apache.ignite.schema.definition.TableDefinition in project ignite-3 by apache.

the class ItProjectScanMergeRuleTest method initTestData.

/**
 * Before all.
 */
@BeforeAll
static void initTestData() {
    TableDefinition schTbl1 = SchemaBuilders.tableBuilder("PUBLIC", "PRODUCTS").columns(SchemaBuilders.column("ID", ColumnType.INT32).build(), SchemaBuilders.column("CATEGORY", ColumnType.string()).asNullable(true).build(), SchemaBuilders.column("CAT_ID", ColumnType.INT32).build(), SchemaBuilders.column("SUBCATEGORY", ColumnType.string()).asNullable(true).build(), SchemaBuilders.column("SUBCAT_ID", ColumnType.INT32).build(), SchemaBuilders.column("NAME", ColumnType.string()).asNullable(true).build()).withPrimaryKey("ID").withIndex(SchemaBuilders.sortedIndex(IDX_CAT_ID).addIndexColumn("CAT_ID").done().build()).build();
    Table tbl = CLUSTER_NODES.get(0).tables().createTable(schTbl1.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(schTbl1, tblCh).changeReplicas(1).changePartitions(10));
    insertData(tbl, new String[] { "ID", "CATEGORY", "CAT_ID", "SUBCATEGORY", "SUBCAT_ID", "NAME" }, new Object[][] { { 1, "prod1", 1, "cat1", 11, "noname1" }, { 2, "prod2", 2, "cat1", 11, "noname2" }, { 3, "prod3", 3, "cat1", 12, "noname3" }, { 4, "prod4", 4, "cat1", 13, "noname4" } });
}
Also used : Table(org.apache.ignite.table.Table) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 18 with TableDefinition

use of org.apache.ignite.schema.definition.TableDefinition in project ignite-3 by apache.

the class TableManagerTest method mockManagersAndCreateTableWithDelay.

/**
 * Instantiates a table and prepares Table manager. When the latch would open, the method completes.
 *
 * @param tableDefinition Configuration schema for a table.
 * @param tblManagerFut   Future for table manager.
 * @param phaser          Phaser for the wait.
 * @return Table manager.
 * @throws NodeStoppingException If something went wrong.
 */
@NotNull
private TableImpl mockManagersAndCreateTableWithDelay(TableDefinition tableDefinition, CompletableFuture<TableManager> tblManagerFut, Phaser phaser) throws NodeStoppingException {
    when(rm.prepareRaftGroup(any(), any(), any())).thenAnswer(mock -> {
        RaftGroupService raftGrpSrvcMock = mock(RaftGroupService.class);
        when(raftGrpSrvcMock.leader()).thenReturn(new Peer(new NetworkAddress("localhost", 47500)));
        return CompletableFuture.completedFuture(raftGrpSrvcMock);
    });
    when(ts.getByAddress(any(NetworkAddress.class))).thenReturn(new ClusterNode(UUID.randomUUID().toString(), "node0", new NetworkAddress("localhost", 47500)));
    try (MockedStatic<SchemaUtils> schemaServiceMock = mockStatic(SchemaUtils.class)) {
        schemaServiceMock.when(() -> SchemaUtils.prepareSchemaDescriptor(anyInt(), any())).thenReturn(mock(SchemaDescriptor.class));
    }
    try (MockedStatic<AffinityUtils> affinityServiceMock = mockStatic(AffinityUtils.class)) {
        ArrayList<List<ClusterNode>> assignment = new ArrayList<>(PARTITIONS);
        for (int part = 0; part < PARTITIONS; part++) {
            assignment.add(new ArrayList<>(Collections.singleton(node)));
        }
        affinityServiceMock.when(() -> AffinityUtils.calculateAssignments(any(), anyInt(), anyInt())).thenReturn(assignment);
    }
    TableManager tableManager = createTableManager(tblManagerFut);
    final int tablesBeforeCreation = tableManager.tables().size();
    tblsCfg.tables().listen(ctx -> {
        boolean createTbl = ctx.newValue().get(tableDefinition.canonicalName()) != null && ctx.oldValue().get(tableDefinition.canonicalName()) == null;
        boolean dropTbl = ctx.oldValue().get(tableDefinition.canonicalName()) != null && ctx.newValue().get(tableDefinition.canonicalName()) == null;
        if (!createTbl && !dropTbl) {
            return CompletableFuture.completedFuture(null);
        }
        if (phaser != null) {
            phaser.arriveAndAwaitAdvance();
        }
        return CompletableFuture.completedFuture(null);
    });
    TableImpl tbl2 = (TableImpl) tableManager.createTable(tableDefinition.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(tableDefinition, tblCh).changeReplicas(REPLICAS).changePartitions(PARTITIONS));
    assertNotNull(tbl2);
    assertEquals(tablesBeforeCreation + 1, tableManager.tables().size());
    return tbl2;
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) BeforeEach(org.junit.jupiter.api.BeforeEach) Disabled(org.junit.jupiter.api.Disabled) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) SchemaUtils(org.apache.ignite.internal.schema.SchemaUtils) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) SchemaConfigurationConverter(org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter) Collection(java.util.Collection) DataStorageConfiguration(org.apache.ignite.configuration.schemas.store.DataStorageConfiguration) TablesConfiguration(org.apache.ignite.configuration.schemas.table.TablesConfiguration) UUID(java.util.UUID) ColumnType(org.apache.ignite.schema.definition.ColumnType) TxManager(org.apache.ignite.internal.tx.TxManager) ClusterNode(org.apache.ignite.network.ClusterNode) Test(org.junit.jupiter.api.Test) List(java.util.List) MockedStatic(org.mockito.MockedStatic) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) NotNull(org.jetbrains.annotations.NotNull) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Strictness(org.mockito.quality.Strictness) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) HashIndexConfigurationSchema(org.apache.ignite.configuration.schemas.table.HashIndexConfigurationSchema) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) IgniteException(org.apache.ignite.lang.IgniteException) Mock(org.mockito.Mock) Mockito.mockStatic(org.mockito.Mockito.mockStatic) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Loza(org.apache.ignite.internal.raft.Loza) CompletableFuture(java.util.concurrent.CompletableFuture) PartialIndexConfigurationSchema(org.apache.ignite.configuration.schemas.table.PartialIndexConfigurationSchema) SortedIndexConfigurationSchema(org.apache.ignite.configuration.schemas.table.SortedIndexConfigurationSchema) ArrayList(java.util.ArrayList) InjectConfiguration(org.apache.ignite.internal.configuration.testframework.InjectConfiguration) ConfigurationExtension(org.apache.ignite.internal.configuration.testframework.ConfigurationExtension) RocksDbDataRegionConfigurationSchema(org.apache.ignite.configuration.schemas.store.RocksDbDataRegionConfigurationSchema) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) TableManager(org.apache.ignite.internal.table.distributed.TableManager) TopologyService(org.apache.ignite.network.TopologyService) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) ConfigurationStorageRevisionListenerHolder(org.apache.ignite.internal.configuration.notifications.ConfigurationStorageRevisionListenerHolder) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) BaselineManager(org.apache.ignite.internal.baseline.BaselineManager) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Mockito.verify(org.mockito.Mockito.verify) NetworkAddress(org.apache.ignite.network.NetworkAddress) Consumer(java.util.function.Consumer) LockManager(org.apache.ignite.internal.tx.LockManager) Peer(org.apache.ignite.raft.client.Peer) AfterEach(org.junit.jupiter.api.AfterEach) ExtendedTableConfigurationSchema(org.apache.ignite.internal.configuration.schema.ExtendedTableConfigurationSchema) Phaser(java.util.concurrent.Phaser) AffinityUtils(org.apache.ignite.internal.affinity.AffinityUtils) InjectRevisionListenerHolder(org.apache.ignite.internal.configuration.testframework.InjectRevisionListenerHolder) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest) SchemaBuilders(org.apache.ignite.schema.SchemaBuilders) Table(org.apache.ignite.table.Table) Collections(java.util.Collections) TableChange(org.apache.ignite.configuration.schemas.table.TableChange) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Peer(org.apache.ignite.raft.client.Peer) ArrayList(java.util.ArrayList) SchemaUtils(org.apache.ignite.internal.schema.SchemaUtils) NetworkAddress(org.apache.ignite.network.NetworkAddress) AffinityUtils(org.apache.ignite.internal.affinity.AffinityUtils) TableManager(org.apache.ignite.internal.table.distributed.TableManager) List(java.util.List) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull)

Example 19 with TableDefinition

use of org.apache.ignite.schema.definition.TableDefinition in project ignite-3 by apache.

the class ItFunctionsTest method testRangeWithCache.

@Test
public void testRangeWithCache() {
    TableDefinition tblDef = SchemaBuilders.tableBuilder("PUBLIC", "TEST").columns(SchemaBuilders.column("ID", ColumnType.INT32).build(), SchemaBuilders.column("VAL", ColumnType.INT32).build()).withPrimaryKey("ID").build();
    String tblName = tblDef.canonicalName();
    RecordView<Tuple> tbl = CLUSTER_NODES.get(0).tables().createTable(tblDef.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(tblDef, tblCh).changeReplicas(1).changePartitions(10)).recordView();
    try {
        for (int i = 0; i < 100; i++) {
            tbl.insert(null, Tuple.create().set("ID", i).set("VAL", i));
        }
        // Correlated INNER join.
        assertQuery("SELECT t.val FROM test t WHERE t.val < 5 AND " + "t.id in (SELECT x FROM table(system_range(t.val, t.val))) ").returns(0).returns(1).returns(2).returns(3).returns(4).check();
        // Correlated LEFT joins.
        assertQuery("SELECT t.val FROM test t WHERE t.val < 5 AND " + "EXISTS (SELECT x FROM table(system_range(t.val, t.val)) WHERE mod(x, 2) = 0) ").returns(0).returns(2).returns(4).check();
        assertQuery("SELECT t.val FROM test t WHERE t.val < 5 AND " + "NOT EXISTS (SELECT x FROM table(system_range(t.val, t.val)) WHERE mod(x, 2) = 0) ").returns(1).returns(3).check();
        assertQuery("SELECT t.val FROM test t WHERE " + "EXISTS (SELECT x FROM table(system_range(t.val, null))) ").check();
        // Non-correlated join.
        assertQuery("SELECT t.val FROM test t JOIN table(system_range(1, 50)) as r ON t.id = r.x " + "WHERE mod(r.x, 10) = 0").returns(10).returns(20).returns(30).returns(40).returns(50).check();
    } finally {
        CLUSTER_NODES.get(0).tables().dropTable(tblName);
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) RecordView(org.apache.ignite.table.RecordView) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Time(java.sql.Time) LongFunction(java.util.function.LongFunction) IgniteException(org.apache.ignite.lang.IgniteException) SchemaConfigurationConverter(org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter) Timestamp(java.sql.Timestamp) SqlValidatorException(org.apache.calcite.sql.validate.SqlValidatorException) ColumnType(org.apache.ignite.schema.definition.ColumnType) Disabled(org.junit.jupiter.api.Disabled) Date(java.sql.Date) Test(org.junit.jupiter.api.Test) IgniteTestUtils(org.apache.ignite.internal.testframework.IgniteTestUtils) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SchemaBuilders(org.apache.ignite.schema.SchemaBuilders) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IgniteStringFormatter(org.apache.ignite.lang.IgniteStringFormatter) Tuple(org.apache.ignite.table.Tuple) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 20 with TableDefinition

use of org.apache.ignite.schema.definition.TableDefinition in project ignite-3 by apache.

the class AbstractBasicIntegrationTest method createAndPopulateTable.

protected static Table createAndPopulateTable() {
    TableDefinition schTbl1 = SchemaBuilders.tableBuilder("PUBLIC", "PERSON").columns(SchemaBuilders.column("ID", ColumnType.INT32).build(), SchemaBuilders.column("NAME", ColumnType.string()).asNullable(true).build(), SchemaBuilders.column("SALARY", ColumnType.DOUBLE).asNullable(true).build()).withPrimaryKey("ID").build();
    Table tbl = CLUSTER_NODES.get(0).tables().createTable(schTbl1.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(schTbl1, tblCh).changeReplicas(1).changePartitions(10));
    int idx = 0;
    insertData(tbl, new String[] { "ID", "NAME", "SALARY" }, new Object[][] { { idx++, "Igor", 10d }, { idx++, null, 15d }, { idx++, "Ilya", 15d }, { idx++, "Roma", 10d }, { idx, "Roma", 10d } });
    return tbl;
}
Also used : Table(org.apache.ignite.table.Table) TableDefinition(org.apache.ignite.schema.definition.TableDefinition)

Aggregations

TableDefinition (org.apache.ignite.schema.definition.TableDefinition)37 Test (org.junit.jupiter.api.Test)25 Table (org.apache.ignite.table.Table)14 List (java.util.List)11 SchemaBuilders (org.apache.ignite.schema.SchemaBuilders)11 ColumnType (org.apache.ignite.schema.definition.ColumnType)11 Disabled (org.junit.jupiter.api.Disabled)11 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)10 Collection (java.util.Collection)9 TableDefinitionBuilder (org.apache.ignite.schema.definition.builder.TableDefinitionBuilder)9 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)9 Collections (java.util.Collections)8 DataStorageConfiguration (org.apache.ignite.configuration.schemas.store.DataStorageConfiguration)8 RocksDbDataRegionConfigurationSchema (org.apache.ignite.configuration.schemas.store.RocksDbDataRegionConfigurationSchema)8 HashIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.HashIndexConfigurationSchema)8 PartialIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.PartialIndexConfigurationSchema)8 SortedIndexConfigurationSchema (org.apache.ignite.configuration.schemas.table.SortedIndexConfigurationSchema)8 TablesConfiguration (org.apache.ignite.configuration.schemas.table.TablesConfiguration)8 AfterEach (org.junit.jupiter.api.AfterEach)8 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)8