Search in sources :

Example 16 with Table

use of org.apache.ignite.table.Table in project ignite-3 by apache.

the class TableManager method dropTableAsyncInternal.

/**
 * Internal method that drops a table with the name specified. If appropriate table does not be found, a future will be
 * completed with {@link TableNotFoundException}.
 *
 * @param name Table name.
 * @return Future representing pending completion of the operation.
 * @throws IgniteException If an unspecified platform exception has happened internally. Is thrown when:
 *                         <ul>
 *                             <li>the node is stopping.</li>
 *                         </ul>
 * @see TableNotFoundException
 */
@NotNull
private CompletableFuture<Void> dropTableAsyncInternal(String name) {
    CompletableFuture<Void> dropTblFut = new CompletableFuture<>();
    tableAsyncInternal(name).thenAccept(tbl -> {
        // distributed table and the local config has lagged behind.
        if (tbl == null) {
            dropTblFut.completeExceptionally(new TableNotFoundException(name));
        } else {
            tablesCfg.tables().change(change -> {
                if (change.get(name) == null) {
                    throw new TableNotFoundException(name);
                }
                change.delete(name);
            }).whenComplete((res, t) -> {
                if (t != null) {
                    Throwable ex = getRootCause(t);
                    if (ex instanceof TableNotFoundException) {
                        dropTblFut.completeExceptionally(ex);
                    } else {
                        LOG.error(IgniteStringFormatter.format("Table wasn't dropped [name={}]", name), ex);
                        dropTblFut.completeExceptionally(ex);
                    }
                } else {
                    dropTblFut.complete(res);
                }
            });
        }
    });
    return dropTblFut;
}
Also used : IgniteTablesInternal(org.apache.ignite.internal.table.IgniteTablesInternal) ExtendedTableConfiguration(org.apache.ignite.internal.configuration.schema.ExtendedTableConfiguration) TableAlreadyExistsException(org.apache.ignite.lang.TableAlreadyExistsException) ConfigurationUtil.directProxy(org.apache.ignite.internal.configuration.util.ConfigurationUtil.directProxy) ConfigurationUtil.getByInternalId(org.apache.ignite.internal.configuration.util.ConfigurationUtil.getByInternalId) ExtendedTableChange(org.apache.ignite.internal.configuration.schema.ExtendedTableChange) IgniteLogger(org.apache.ignite.lang.IgniteLogger) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Map(java.util.Map) DataRegion(org.apache.ignite.internal.storage.engine.DataRegion) TableNotFoundException(org.apache.ignite.lang.TableNotFoundException) Path(java.nio.file.Path) SchemaUtils(org.apache.ignite.internal.schema.SchemaUtils) ExtendedTableView(org.apache.ignite.internal.configuration.schema.ExtendedTableView) IgniteComponent(org.apache.ignite.internal.manager.IgniteComponent) SchemaConfiguration(org.apache.ignite.internal.configuration.schema.SchemaConfiguration) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) DataStorageConfiguration(org.apache.ignite.configuration.schemas.store.DataStorageConfiguration) TablesConfiguration(org.apache.ignite.configuration.schemas.table.TablesConfiguration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) DEFAULT_DATA_REGION_NAME(org.apache.ignite.configuration.schemas.store.DataStorageConfigurationSchema.DEFAULT_DATA_REGION_NAME) CompletionException(java.util.concurrent.CompletionException) Producer(org.apache.ignite.internal.manager.Producer) StorageEngine(org.apache.ignite.internal.storage.engine.StorageEngine) UUID(java.util.UUID) ConfigurationChangeException(org.apache.ignite.configuration.ConfigurationChangeException) Collectors(java.util.stream.Collectors) TxManager(org.apache.ignite.internal.tx.TxManager) TableView(org.apache.ignite.configuration.schemas.table.TableView) ClusterNode(org.apache.ignite.network.ClusterNode) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) IgniteStringFormatter(org.apache.ignite.lang.IgniteStringFormatter) NotNull(org.jetbrains.annotations.NotNull) InternalTable(org.apache.ignite.internal.table.InternalTable) IgniteException(org.apache.ignite.lang.IgniteException) Loza(org.apache.ignite.internal.raft.Loza) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TableConfiguration(org.apache.ignite.configuration.schemas.table.TableConfiguration) ByteUtils(org.apache.ignite.internal.util.ByteUtils) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) SchemaSerializerImpl(org.apache.ignite.internal.schema.marshaller.schema.SchemaSerializerImpl) Function(java.util.function.Function) Supplier(java.util.function.Supplier) SchemaView(org.apache.ignite.internal.configuration.schema.SchemaView) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TableImpl(org.apache.ignite.internal.table.TableImpl) IgniteSpinBusyLock(org.apache.ignite.internal.util.IgniteSpinBusyLock) IgniteTables(org.apache.ignite.table.manager.IgniteTables) NoSuchElementException(java.util.NoSuchElementException) VersionedValue(org.apache.ignite.internal.causality.VersionedValue) TopologyService(org.apache.ignite.network.TopologyService) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TableEventParameters(org.apache.ignite.internal.table.event.TableEventParameters) Files(java.nio.file.Files) NamedListView(org.apache.ignite.configuration.NamedListView) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) IgniteObjectName(org.apache.ignite.internal.util.IgniteObjectName) IOException(java.io.IOException) Ignite(org.apache.ignite.Ignite) BaselineManager(org.apache.ignite.internal.baseline.BaselineManager) TableStorage(org.apache.ignite.internal.storage.engine.TableStorage) ConfigurationNamedListListener(org.apache.ignite.configuration.notifications.ConfigurationNamedListListener) NetworkAddress(org.apache.ignite.network.NetworkAddress) Consumer(java.util.function.Consumer) ConfigurationNotificationEvent(org.apache.ignite.configuration.notifications.ConfigurationNotificationEvent) TableEvent(org.apache.ignite.internal.table.event.TableEvent) AffinityUtils(org.apache.ignite.internal.affinity.AffinityUtils) EventListener(org.apache.ignite.internal.manager.EventListener) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) Table(org.apache.ignite.table.Table) ConfigurationValidationException(org.apache.ignite.configuration.validation.ConfigurationValidationException) RocksDbStorageEngine(org.apache.ignite.internal.storage.rocksdb.RocksDbStorageEngine) TableChange(org.apache.ignite.configuration.schemas.table.TableChange) TableNotFoundException(org.apache.ignite.lang.TableNotFoundException) CompletableFuture(java.util.concurrent.CompletableFuture) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with Table

use of org.apache.ignite.table.Table in project ignite-3 by apache.

the class JdbcMetadataCatalog method getColumnsMeta.

/**
 * See {@link DatabaseMetaData#getColumns(String, String, String, String)} for details.
 *
 * <p>Ignite has only one possible CATALOG_NAME, it is handled on the client (driver) side.
 *
 * @param schemaNamePtrn Schema name java regex pattern.
 * @param tblNamePtrn    Table name java regex pattern.
 * @param colNamePtrn    Column name java regex pattern.
 * @return Future of the list of metadatas about columns that match specified schema/tablename/columnname criterias.
 */
public CompletableFuture<Collection<JdbcColumnMeta>> getColumnsMeta(String schemaNamePtrn, String tblNamePtrn, String colNamePtrn) {
    String schemaNameRegex = translateSqlWildcardsToRegex(schemaNamePtrn);
    String tlbNameRegex = translateSqlWildcardsToRegex(tblNamePtrn);
    String colNameRegex = translateSqlWildcardsToRegex(colNamePtrn);
    return tables.tablesAsync().thenApply(tablesList -> {
        return tablesList.stream().filter(t -> matches(getTblSchema(t.name()), schemaNameRegex)).filter(t -> matches(getTblName(t.name()), tlbNameRegex)).flatMap(tbl -> {
            SchemaDescriptor schema = ((TableImpl) tbl).schemaView().schema();
            List<Pair<String, Column>> tblColPairs = new ArrayList<>();
            for (Column column : schema.keyColumns().columns()) {
                tblColPairs.add(new Pair<>(tbl.name(), column));
            }
            for (Column column : schema.valueColumns().columns()) {
                tblColPairs.add(new Pair<>(tbl.name(), column));
            }
            return tblColPairs.stream();
        }).filter(e -> matches(e.getSecond().name(), colNameRegex)).sorted(bySchemaThenTabNameThenColOrder).map(pair -> createColumnMeta(pair.getFirst(), pair.getSecond())).collect(Collectors.toCollection(LinkedHashSet::new));
    });
}
Also used : JdbcColumnMeta(org.apache.ignite.client.proto.query.event.JdbcColumnMeta) Arrays(java.util.Arrays) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Pair(org.apache.ignite.internal.util.Pair) SortedSet(java.util.SortedSet) Collection(java.util.Collection) DatabaseMetaData(java.sql.DatabaseMetaData) CompletableFuture(java.util.concurrent.CompletableFuture) JdbcTableMeta(org.apache.ignite.client.proto.query.event.JdbcTableMeta) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Commons(org.apache.ignite.internal.sql.engine.util.Commons) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) List(java.util.List) Column(org.apache.ignite.internal.schema.Column) TableImpl(org.apache.ignite.internal.table.TableImpl) JdbcPrimaryKeyMeta(org.apache.ignite.client.proto.query.event.JdbcPrimaryKeyMeta) IgniteTables(org.apache.ignite.table.manager.IgniteTables) NativeType(org.apache.ignite.internal.schema.NativeType) Table(org.apache.ignite.table.Table) Comparator(java.util.Comparator) SchemaRegistry(org.apache.ignite.internal.schema.SchemaRegistry) LinkedHashSet(java.util.LinkedHashSet) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) ArrayList(java.util.ArrayList) Pair(org.apache.ignite.internal.util.Pair)

Example 18 with Table

use of org.apache.ignite.table.Table in project ignite-3 by apache.

the class ClientKeyValueBinaryViewTest method testRecordUpsertKvGet.

@Test
public void testRecordUpsertKvGet() {
    Table table = defaultTable();
    table.recordView().upsert(null, tuple());
    KeyValueView<Tuple, Tuple> kvView = table.keyValueView();
    Tuple key = defaultTupleKey();
    Tuple val = kvView.get(null, key);
    assertEquals(DEFAULT_NAME, val.value("name"));
    assertEquals(DEFAULT_NAME, val.value(0));
    assertEquals(1, val.columnCount());
}
Also used : Table(org.apache.ignite.table.Table) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 19 with Table

use of org.apache.ignite.table.Table in project ignite-3 by apache.

the class ClientKeyValueViewTest method testColumnWithDefaultValueNotSetReturnsDefault.

@Test
public void testColumnWithDefaultValueNotSetReturnsDefault() {
    Table table = tableWithDefaultValues();
    RecordView<Tuple> recordView = table.recordView();
    KeyValueView<Integer, NamePojo> pojoView = table.keyValueView(Integer.class, NamePojo.class);
    pojoView.put(null, 1, new NamePojo());
    var res = recordView.get(null, tupleKey(1));
    assertEquals("def_str", res.stringValue("str"));
    assertEquals("def_str2", res.stringValue("strNonNull"));
}
Also used : BigInteger(java.math.BigInteger) Table(org.apache.ignite.table.Table) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 20 with Table

use of org.apache.ignite.table.Table in project ignite-3 by apache.

the class ClientKeyValueViewTest method testBinaryPutPojoGet.

@Test
public void testBinaryPutPojoGet() {
    Table table = defaultTable();
    KeyValueView<Long, PersonPojo> pojoView = table.keyValueView(Mapper.of(Long.class), Mapper.of(PersonPojo.class));
    table.recordView().upsert(null, tuple());
    PersonPojo val = pojoView.get(null, DEFAULT_ID);
    PersonPojo missingVal = pojoView.get(null, -1L);
    assertEquals(DEFAULT_NAME, val.name);
    // Not mapped in value part.
    assertEquals(0, val.id);
    assertNull(missingVal);
}
Also used : Table(org.apache.ignite.table.Table) Test(org.junit.jupiter.api.Test)

Aggregations

Table (org.apache.ignite.table.Table)65 Test (org.junit.jupiter.api.Test)51 Tuple (org.apache.ignite.table.Tuple)29 Ignite (org.apache.ignite.Ignite)15 TableDefinition (org.apache.ignite.schema.definition.TableDefinition)15 List (java.util.List)12 UUID (java.util.UUID)12 CompletableFuture (java.util.concurrent.CompletableFuture)12 IgniteAbstractTest (org.apache.ignite.internal.testframework.IgniteAbstractTest)12 ArrayList (java.util.ArrayList)11 NodeStoppingException (org.apache.ignite.lang.NodeStoppingException)11 TableImpl (org.apache.ignite.internal.table.TableImpl)10 Function (java.util.function.Function)9 Collectors (java.util.stream.Collectors)9 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)9 SchemaBuilders (org.apache.ignite.schema.SchemaBuilders)8 ColumnType (org.apache.ignite.schema.definition.ColumnType)8 NotNull (org.jetbrains.annotations.NotNull)8 Consumer (java.util.function.Consumer)7 DataStorageConfiguration (org.apache.ignite.configuration.schemas.store.DataStorageConfiguration)7