Search in sources :

Example 26 with TableDefinition

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

the class TableManagerTest method testDropTable.

/**
 * Tests drop a table through public API.
 *
 * @throws Exception If failed.
 */
@Test
public void testDropTable() throws Exception {
    TableDefinition scmTbl = SchemaBuilders.tableBuilder("PUBLIC", DYNAMIC_TABLE_FOR_DROP_NAME).columns(SchemaBuilders.column("key", ColumnType.INT64).build(), SchemaBuilders.column("val", ColumnType.INT64).asNullable(true).build()).withPrimaryKey("key").build();
    mockManagersAndCreateTable(scmTbl, tblManagerFut);
    TableManager tableManager = tblManagerFut.join();
    tableManager.dropTable(scmTbl.canonicalName());
    assertNull(tableManager.table(scmTbl.canonicalName()));
    assertEquals(0, tableManager.tables().size());
}
Also used : TableDefinition(org.apache.ignite.schema.definition.TableDefinition) TableManager(org.apache.ignite.internal.table.distributed.TableManager) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 27 with TableDefinition

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

the class PlatformTestNodeRunner method main.

/**
 * Entry point.
 *
 * @param args Args.
 */
public static void main(String[] args) throws Exception {
    System.out.println("Starting test node runner...");
    for (int i = 0; i < args.length; i++) {
        System.out.println("Arg " + i + ": " + args[i]);
    }
    if (args.length > 0 && "dry-run".equals(args[0])) {
        System.out.println("Dry run succeeded.");
        return;
    }
    IgniteUtils.deleteIfExists(BASE_PATH);
    Files.createDirectories(BASE_PATH);
    List<Ignite> startedNodes = new ArrayList<>();
    nodesBootstrapCfg.forEach((nodeName, configStr) -> startedNodes.add(IgnitionManager.start(nodeName, configStr, BASE_PATH.resolve(nodeName))));
    var keyCol = "key";
    var valCol = "val";
    TableDefinition schTbl = SchemaBuilders.tableBuilder(SCHEMA_NAME, TABLE_NAME).columns(SchemaBuilders.column(keyCol, ColumnType.INT64).build(), SchemaBuilders.column(valCol, ColumnType.string()).asNullable(true).build()).withPrimaryKey(keyCol).build();
    startedNodes.get(0).tables().createTable(schTbl.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(schTbl, tblCh).changeReplicas(1).changePartitions(10));
    String ports = startedNodes.stream().map(n -> String.valueOf(getPort((IgniteImpl) n))).collect(Collectors.joining(","));
    System.out.println("THIN_CLIENT_PORTS=" + ports);
    Thread.sleep(RUN_TIME_MINUTES * 60_000);
    System.out.println("Exiting after " + RUN_TIME_MINUTES + " minutes.");
}
Also used : IgniteImpl(org.apache.ignite.internal.app.IgniteImpl) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Files(java.nio.file.Files) SchemaConfigurationConverter(org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter) Ignite(org.apache.ignite.Ignite) ColumnType(org.apache.ignite.schema.definition.ColumnType) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) IgnitionManager(org.apache.ignite.IgnitionManager) List(java.util.List) Map(java.util.Map) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) SchemaBuilders(org.apache.ignite.schema.SchemaBuilders) Path(java.nio.file.Path) IgniteImpl(org.apache.ignite.internal.app.IgniteImpl) ArrayList(java.util.ArrayList) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Ignite(org.apache.ignite.Ignite)

Example 28 with TableDefinition

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

the class ItDataSchemaSyncTest method createTable.

/**
 * Creates a table with the passed name on the specific schema.
 *
 * @param node           Cluster node.
 * @param schemaName     Schema name.
 * @param shortTableName Table name.
 */
protected void createTable(Ignite node, String schemaName, String shortTableName) {
    // Create table on node 0.
    TableDefinition schTbl1 = SchemaBuilders.tableBuilder(schemaName, shortTableName).columns(SchemaBuilders.column("key", ColumnType.INT64).build(), SchemaBuilders.column("valInt", ColumnType.INT32).asNullable(true).build(), SchemaBuilders.column("valStr", ColumnType.string()).withDefaultValueExpression("default").build()).withPrimaryKey("key").build();
    node.tables().createTable(schTbl1.canonicalName(), tblCh -> convert(schTbl1, tblCh).changeReplicas(2).changePartitions(10));
}
Also used : TableDefinition(org.apache.ignite.schema.definition.TableDefinition)

Example 29 with TableDefinition

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

the class ItJdbcResultSetSelfTest method beforeClass.

@BeforeAll
public static void beforeClass() {
    Ignite ignite = clusterNodes.get(0);
    List<ColumnDefinition> columns = new ArrayList<>();
    columns.add(SchemaBuilders.column("ID", ColumnType.INT32).build());
    columns.add(SchemaBuilders.column("BOOLVAL", ColumnType.INT8).asNullable(true).build());
    columns.add(SchemaBuilders.column("BYTEVAL", ColumnType.INT8).asNullable(true).build());
    columns.add(SchemaBuilders.column("SHORTVAL", ColumnType.INT16).asNullable(true).build());
    columns.add(SchemaBuilders.column("INTVAL", ColumnType.INT32).asNullable(true).build());
    columns.add(SchemaBuilders.column("LONGVAL", ColumnType.INT64).asNullable(true).build());
    columns.add(SchemaBuilders.column("FLOATVAL", ColumnType.FLOAT).asNullable(true).build());
    columns.add(SchemaBuilders.column("DOUBLEVAL", ColumnType.DOUBLE).asNullable(true).build());
    columns.add(SchemaBuilders.column("BIGVAL", ColumnType.decimalOf()).asNullable(true).build());
    columns.add(SchemaBuilders.column("STRVAL", ColumnType.string()).asNullable(true).build());
    columns.add(SchemaBuilders.column("ARRVAL", ColumnType.blobOf()).asNullable(true).build());
    columns.add(SchemaBuilders.column("DATEVAL", ColumnType.DATE).asNullable(true).build());
    columns.add(SchemaBuilders.column("TIMEVAL", ColumnType.TemporalColumnType.time()).asNullable(true).build());
    columns.add(SchemaBuilders.column("TSVAL", ColumnType.TemporalColumnType.timestamp()).asNullable(true).build());
    columns.add(SchemaBuilders.column("URLVAL", ColumnType.blobOf()).asNullable(true).build());
    TableDefinition personTableDef = SchemaBuilders.tableBuilder("PUBLIC", "TEST").columns(columns).withPrimaryKey("ID").build();
    ignite.tables().createTable(personTableDef.canonicalName(), (tableChange) -> SchemaConfigurationConverter.convert(personTableDef, tableChange).changeReplicas(1).changePartitions(10));
    RecordView<Tuple> tupleRecordView = ignite.tables().table("PUBLIC.TEST").recordView();
    Tuple tuple = Tuple.create();
    tuple.set("BOOLVAL", (byte) 1).set("BYTEVAL", (byte) 1).set("SHORTVAL", (short) 1).set("INTVAL", 1).set("LONGVAL", 1L).set("FLOATVAL", 1.0f).set("DOUBLEVAL", 1.0d).set("BIGVAL", new BigDecimal("1")).set("STRVAL", "1").set("DATEVAL", LocalDate.parse("1901-02-01")).set("TIMEVAL", LocalTime.parse("01:01:01")).set("TSVAL", Instant.ofEpochMilli(1));
    tupleRecordView.insert(null, tuple.set("ID", 1));
    tupleRecordView.insert(null, tuple.set("ID", 2));
}
Also used : ArrayList(java.util.ArrayList) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Ignite(org.apache.ignite.Ignite) Tuple(org.apache.ignite.table.Tuple) BigDecimal(java.math.BigDecimal) ColumnDefinition(org.apache.ignite.schema.definition.ColumnDefinition) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 30 with TableDefinition

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

the class AbstractSchemaChangeTest method createTable.

/**
 * Creates tables.
 *
 * @param nodes Cluster nodes.
 */
protected static void createTable(List<Ignite> nodes) {
    // Create table on node 0.
    TableDefinition schTbl1 = SchemaBuilders.tableBuilder("PUBLIC", "tbl1").columns(SchemaBuilders.column("key", ColumnType.INT64).build(), SchemaBuilders.column("valInt", ColumnType.INT32).asNullable(true).build(), SchemaBuilders.column("valBlob", ColumnType.blobOf()).asNullable(true).build(), SchemaBuilders.column("valDecimal", ColumnType.decimalOf()).asNullable(true).build(), SchemaBuilders.column("valBigInt", ColumnType.numberOf()).asNullable(true).build(), SchemaBuilders.column("valStr", ColumnType.string()).withDefaultValueExpression("default").build()).withPrimaryKey("key").build();
    nodes.get(0).tables().createTable(schTbl1.canonicalName(), tblCh -> convert(schTbl1, tblCh).changeReplicas(1).changePartitions(10));
}
Also used : 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