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;
}
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));
});
}
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());
}
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"));
}
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);
}
Aggregations