use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class TableManager method alterTableAsyncInternal.
/**
* Internal method that alters a cluster table. If an appropriate table does not exist, a future will be
* completed with {@link TableNotFoundException}.
*
* @param name Table name.
* @param tableChange Table changer.
* @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> alterTableAsyncInternal(String name, Consumer<TableChange> tableChange) {
CompletableFuture<Void> tblFut = new CompletableFuture<>();
tableAsync(name).thenAccept(tbl -> {
if (tbl == null) {
tblFut.completeExceptionally(new TableNotFoundException(name));
} else {
TableImpl tblImpl = (TableImpl) tbl;
tablesCfg.tables().change(ch -> {
if (ch.get(name) == null) {
throw new TableNotFoundException(name);
}
ch.update(name, tblCh -> {
tableChange.accept(tblCh);
((ExtendedTableChange) tblCh).changeSchemas(schemasCh -> schemasCh.createOrUpdate(String.valueOf(schemasCh.size() + 1), schemaCh -> {
ExtendedTableView currTableView = (ExtendedTableView) tablesCfg.tables().get(name).value();
SchemaDescriptor descriptor;
// here to ensure a valid configuration passed to prepareSchemaDescriptor() method.
try {
descriptor = SchemaUtils.prepareSchemaDescriptor(((ExtendedTableView) tblCh).schemas().size(), tblCh);
descriptor.columnMapping(SchemaUtils.columnMapper(tblImpl.schemaView().schema(currTableView.schemas().size()), currTableView, descriptor, tblCh));
} catch (IllegalArgumentException ex) {
// Convert unexpected exceptions here,
// because validation actually happens later,
// when bulk configuration update is applied.
ConfigurationValidationException e = new ConfigurationValidationException(ex.getMessage());
e.addSuppressed(ex);
throw e;
}
schemaCh.changeSchema(SchemaSerializerImpl.INSTANCE.serialize(descriptor));
}));
});
}).whenComplete((res, t) -> {
if (t != null) {
Throwable ex = getRootCause(t);
if (ex instanceof TableNotFoundException) {
tblFut.completeExceptionally(ex);
} else {
LOG.error(IgniteStringFormatter.format("Table wasn't altered [name={}]", name), ex);
tblFut.completeExceptionally(ex);
}
} else {
tblFut.complete(res);
}
});
}
});
return tblFut;
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class FakeSchemaRegistry method schema.
/**
* {@inheritDoc}
*/
@Override
@NotNull
public SchemaDescriptor schema(int ver) {
if (ver == 0) {
// Use last version (any version may be used) for 0 version, that mean row doens't contain value.
ver = lastVer;
}
SchemaDescriptor desc = schemaCache.get(ver);
if (desc != null) {
return desc;
}
desc = history.apply(ver);
if (desc != null) {
schemaCache.putIfAbsent(ver, desc);
return desc;
}
if (lastVer < ver || ver <= 0) {
throw new SchemaRegistryException("Incorrect schema version requested: ver=" + ver);
} else {
throw new SchemaRegistryException("Failed to find schema: ver=" + ver);
}
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class AbstractSerializerTest method schemaSerializeTest.
/**
* (de)Serialize schema test.
*/
@Test
public void schemaSerializeTest() {
AbstractSchemaSerializer assembler = SchemaSerializerImpl.INSTANCE;
SchemaDescriptor desc = new SchemaDescriptor(100500, new Column[] { new Column("A", NativeTypes.INT8, false), new Column("B", NativeTypes.INT16, false), new Column("C", NativeTypes.INT32, false), new Column("D", NativeTypes.INT64, false), new Column("E", NativeTypes.UUID, false), new Column("F", NativeTypes.FLOAT, false), new Column("G", NativeTypes.DOUBLE, false), new Column("H", NativeTypes.DATE, false) }, new Column[] { new Column("A1", NativeTypes.stringOf(128), false), new Column("B1", NativeTypes.numberOf(255), false), new Column("C1", NativeTypes.decimalOf(128, 64), false), new Column("D1", NativeTypes.bitmaskOf(256), false), new Column("E1", NativeTypes.datetime(8), false), new Column("F1", NativeTypes.time(8), false), new Column("G1", NativeTypes.timestamp(8), true) });
byte[] serialize = assembler.serialize(desc);
SchemaDescriptor deserialize = assembler.deserialize(serialize);
assertEquals(desc.version(), deserialize.version());
assertArrayEquals(desc.keyColumns().columns(), deserialize.keyColumns().columns());
assertArrayEquals(desc.valueColumns().columns(), deserialize.valueColumns().columns());
assertArrayEquals(desc.colocationColumns(), deserialize.colocationColumns());
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class NumericTypesSerializerTest method testDecimalMaxScale.
@Test
public void testDecimalMaxScale() throws TupleMarshallerException {
schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol", NativeTypes.decimalOf(Integer.MAX_VALUE, Integer.MAX_VALUE), false) });
final Tuple tup = createTuple().set("key", rnd.nextLong()).set("decimalCol", BigDecimal.valueOf(123, Integer.MAX_VALUE));
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
final Row row = marshaller.marshal(tup);
assertEquals(row.decimalValue(1), BigDecimal.valueOf(123, Integer.MAX_VALUE));
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class NumericTypesSerializerTest method testUpscaleForDecimal.
/**
* Test.
*/
@ParameterizedTest
@MethodSource("stringDecimalRepresentation")
public void testUpscaleForDecimal(String decimalStr) throws TupleMarshallerException {
schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, new Column[] { new Column("decimalCol1", NativeTypes.decimalOf(9, 0), false) });
final Tuple tup = createTuple().set("key", rnd.nextLong()).set("decimalCol1", new BigDecimal(decimalStr));
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema));
final Row row = marshaller.marshal(tup);
assertEquals(row.decimalValue(1), new BigDecimal(decimalStr).setScale(0, RoundingMode.HALF_UP));
}
Aggregations