use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class TupleMarshallerImpl method marshal.
/**
* {@inheritDoc}
*/
@Override
public Row marshal(@NotNull Tuple tuple) throws TupleMarshallerException {
try {
SchemaDescriptor schema = schemaReg.schema();
InternalTuple keyTuple0 = toInternalTuple(schema, tuple, true);
InternalTuple valTuple0 = toInternalTuple(schema, tuple, false);
if (valTuple0.knownColumns() + keyTuple0.knownColumns() != tuple.columnCount()) {
throw new SchemaMismatchException(String.format("Tuple doesn't match schema: schemaVersion=%s, extraColumns=%s", schema.version(), extraColumnNames(tuple, schema)));
}
return buildRow(schema, keyTuple0, valTuple0);
} catch (Exception ex) {
throw new TupleMarshallerException("Failed to marshal tuple.", ex);
}
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class TupleMarshallerImpl method marshalKey.
/**
* {@inheritDoc}
*/
@Override
public Row marshalKey(@NotNull Tuple keyTuple) throws TupleMarshallerException {
try {
final SchemaDescriptor schema = schemaReg.schema();
InternalTuple keyTuple0 = toInternalTuple(schema, keyTuple, true);
if (keyTuple0.knownColumns() < keyTuple.columnCount()) {
throw new SchemaMismatchException("Key tuple contains extra columns: " + extraColumnNames(keyTuple, true, schema));
}
final RowAssembler rowBuilder = createAssembler(schema, keyTuple0, InternalTuple.NO_VALUE);
Columns cols = schema.keyColumns();
for (int i = 0, len = cols.length(); i < len; i++) {
final Column col = cols.column(i);
writeColumn(rowBuilder, col, keyTuple0);
}
return new Row(schema, rowBuilder.build());
} catch (Exception ex) {
throw new TupleMarshallerException("Failed to marshal tuple.", ex);
}
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class StopCalciteModuleTest method before.
/**
* Before.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
@BeforeEach
public void before(TestInfo testInfo) {
when(clusterSrvc.messagingService()).thenReturn(msgSrvc);
when(clusterSrvc.topologyService()).thenReturn(topologySrvc);
when(clusterSrvc.localConfiguration()).thenReturn(localCfg);
ClusterNode node = new ClusterNode("mock-node-id", NODE_NAME, null);
when(topologySrvc.localMember()).thenReturn(node);
when(topologySrvc.allMembers()).thenReturn(Collections.singleton(node));
SchemaDescriptor schemaDesc = new SchemaDescriptor(1, new Column[] { new Column(0, "ID", NativeTypes.INT32, false) }, new Column[] { new Column(1, "VAL", NativeTypes.INT32, false) });
schemaReg = new SchemaRegistryImpl(1, (v) -> schemaDesc, () -> INITIAL_SCHEMA_VERSION);
when(tbl.name()).thenReturn("PUBLIC.TEST");
// Mock create table (notify on register listener).
doAnswer(invocation -> {
EventListener<TableEventParameters> clo = (EventListener<TableEventParameters>) invocation.getArguments()[1];
clo.notify(new TableEventParameters(0, UUID.randomUUID(), "TEST", new TableImpl(tbl, schemaReg)), null);
return null;
}).when(tableManager).listen(eq(TableEvent.CREATE), any());
RowAssembler asm = new RowAssembler(schemaReg.schema(), 0, 0, 0, 0);
asm.appendInt(0);
asm.appendInt(0);
BinaryRow binaryRow = asm.build();
// Mock table scan
doAnswer(invocation -> {
int part = (int) invocation.getArguments()[0];
return (Flow.Publisher<BinaryRow>) s -> {
s.onSubscribe(new Flow.Subscription() {
@Override
public void request(long n) {
}
@Override
public void cancel() {
}
});
if (part == 0) {
for (int i = 0; i < ROWS; ++i) {
s.onNext(binaryRow);
}
}
s.onComplete();
};
}).when(tbl).scan(anyInt(), any());
LOG.info(">>>> Starting test {}", testInfo.getTestMethod().orElseThrow().getName());
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class KvMarshallerTest method privateClass.
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void privateClass(MarshallerFactory factory) throws MarshallerException {
Column[] cols = new Column[] { new Column("primLongCol".toUpperCase(), INT64, false) };
SchemaDescriptor schema = new SchemaDescriptor(1, cols, cols);
final ObjectFactory<PrivateTestObject> objFactory = new ObjectFactory<>(PrivateTestObject.class);
final KvMarshaller<PrivateTestObject, PrivateTestObject> marshaller = factory.create(schema, PrivateTestObject.class, PrivateTestObject.class);
final PrivateTestObject key = PrivateTestObject.randomObject(rnd);
final PrivateTestObject val = PrivateTestObject.randomObject(rnd);
BinaryRow row = marshaller.marshal(key, objFactory.create());
Object key1 = marshaller.unmarshalKey(new Row(schema, row));
Object val1 = marshaller.unmarshalValue(new Row(schema, row));
assertTrue(key.getClass().isInstance(key1));
assertTrue(val.getClass().isInstance(val1));
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class KvMarshallerTest method classLoader.
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classLoader(MarshallerFactory factory) throws MarshallerException {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(new DynamicClassLoader(getClass().getClassLoader()));
Column[] keyCols = new Column[] { new Column("key".toUpperCase(), INT64, false) };
Column[] valCols = new Column[] { new Column("col0".toUpperCase(), INT64, false), new Column("col1".toUpperCase(), INT64, false), new Column("col2".toUpperCase(), INT64, false) };
SchemaDescriptor schema = new SchemaDescriptor(1, keyCols, valCols);
final Class<?> valClass = createGeneratedObjectClass();
final ObjectFactory<?> objFactory = new ObjectFactory<>(valClass);
KvMarshaller<Long, Object> marshaller = factory.create(schema, Long.class, (Class<Object>) valClass);
final Long key = rnd.nextLong();
BinaryRow row = marshaller.marshal(key, objFactory.create());
Long key1 = marshaller.unmarshalKey(new Row(schema, row));
Object val1 = marshaller.unmarshalValue(new Row(schema, row));
assertTrue(valClass.isInstance(val1));
assertEquals(key, key1);
} finally {
Thread.currentThread().setContextClassLoader(loader);
}
}
Aggregations