use of org.apache.ignite.internal.sql.engine.schema.IgniteTable in project ignite-3 by apache.
the class SqlSchemaManagerTest method testTableEventIsProcessedRequiredVersionIsLess.
@Test
public void testTableEventIsProcessedRequiredVersionIsLess() {
when(table.schemaView()).thenReturn(schemaRegistry);
when(table.name()).thenReturn("TEST_SCHEMA.T");
InternalTable mock = mock(InternalTable.class);
when(mock.tableId()).thenReturn(tableId);
when(table.internalTable()).thenReturn(mock);
when(schemaRegistry.schema()).thenReturn(schemaDescriptor);
when(schemaRegistry.lastSchemaVersion()).thenReturn(schemaDescriptor.version());
schemaManager.onTableCreated("TEST_SCHEMA", table, testRevisionRegister.actualToken() + 1);
testRevisionRegister.moveForward();
IgniteTable actTable = schemaManager.tableById(tableId, tableVer - 1);
assertEquals(tableId, actTable.id());
Mockito.verifyNoMoreInteractions(tableManager);
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteTable in project ignite-3 by apache.
the class SqlSchemaManagerTest method testOnTableDroppedHandler.
@Test
public void testOnTableDroppedHandler() {
when(table.schemaView()).thenReturn(schemaRegistry);
when(table.name()).thenReturn("TEST_SCHEMA.T");
InternalTable mock = mock(InternalTable.class);
when(mock.tableId()).thenReturn(tableId);
when(table.internalTable()).thenReturn(mock);
when(schemaRegistry.schema()).thenReturn(schemaDescriptor);
when(schemaRegistry.lastSchemaVersion()).thenReturn(schemaDescriptor.version());
schemaManager.onTableCreated("TEST_SCHEMA", table, testRevisionRegister.actualToken() + 1);
testRevisionRegister.moveForward();
Table schemaTable = schemaManager.schema("TEST_SCHEMA").getTable("T");
assertNotNull(schemaTable);
IgniteTableImpl igniteTable = assertInstanceOf(IgniteTableImpl.class, schemaTable);
assertEquals(tableId, igniteTable.table().tableId());
schemaManager.onTableDropped("TEST_SCHEMA", table.name(), testRevisionRegister.actualToken() + 1);
testRevisionRegister.moveForward();
assertNull(schemaManager.schema("TEST_SCHEMA").getTable("T"));
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteTable in project ignite-3 by apache.
the class RelJsonReaderTest method fromJson.
/**
* Test verifies that during deserialization table being resolved by its ID.
*/
@Test
void fromJson() {
UUID tableId = UUID.randomUUID();
int tableVer = 2;
IgniteTable igniteTableMock = mock(IgniteTable.class);
when(igniteTableMock.getStatistic()).thenReturn(new Statistic() {
});
when(igniteTableMock.getRowType(any())).thenReturn(mock(RelDataType.class));
SqlSchemaManager schemaMock = mock(SqlSchemaManager.class);
when(schemaMock.tableById(tableId, tableVer)).thenReturn(igniteTableMock);
String json = "" + "{\n" + " \"rels\" : [ {\n" + " \"id\" : \"0\",\n" + " \"relOp\" : \"IgniteTableScan\",\n" + " \"table\" : [\"PUBLIC\", \"TEST\"],\n" + " \"tableId\" : \"" + tableId + "\",\n" + " \"tableVer\" : " + tableVer + ",\n" + " \"inputs\" : [ ]\n" + " } ]\n" + "}";
RelNode node = RelJsonReader.fromJson(schemaMock, json);
assertThat(node, isA(IgniteTableScan.class));
assertThat(node.getTable(), notNullValue());
assertThat(node.getTable().unwrap(IgniteTable.class), is(igniteTableMock));
Mockito.verify(schemaMock).tableById(tableId, tableVer);
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteTable in project ignite-3 by apache.
the class ProjectableFilterableTableScan method pushUpPredicate.
/**
* PushUpPredicate.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
public RexNode pushUpPredicate() {
if (condition == null || projects == null) {
return replaceLocalRefs(condition);
}
IgniteTypeFactory typeFactory = Commons.typeFactory(getCluster());
IgniteTable tbl = getTable().unwrap(IgniteTable.class);
Mappings.TargetMapping mapping = RexUtils.inversePermutation(projects, tbl.getRowType(typeFactory, requiredColumns), true);
RexShuttle shuttle = new RexShuttle() {
@Override
public RexNode visitLocalRef(RexLocalRef ref) {
int targetRef = mapping.getSourceOpt(ref.getIndex());
if (targetRef == -1) {
throw new ControlFlowException();
}
return new RexInputRef(targetRef, ref.getType());
}
};
List<RexNode> conjunctions = new ArrayList<>();
for (RexNode conjunction : RelOptUtil.conjunctions(condition)) {
try {
conjunctions.add(shuttle.apply(conjunction));
} catch (ControlFlowException ignore) {
// No-op
}
}
return RexUtil.composeConjunction(builder(getCluster()), conjunctions, true);
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteTable in project ignite-3 by apache.
the class AbstractPlannerTest method checkSplitAndSerialization.
protected void checkSplitAndSerialization(IgniteRel rel, IgniteSchema publicSchema) {
assertNotNull(rel);
rel = Cloner.clone(rel);
List<Fragment> fragments = new Splitter().go(rel);
List<String> serialized = new ArrayList<>(fragments.size());
for (Fragment fragment : fragments) {
serialized.add(toJson(fragment.root()));
}
assertNotNull(serialized);
List<String> nodes = new ArrayList<>(4);
for (int i = 0; i < 4; i++) {
nodes.add(UUID.randomUUID().toString());
}
List<RelNode> deserializedNodes = new ArrayList<>();
Map<UUID, IgniteTable> tableMap = publicSchema.getTableNames().stream().map(publicSchema::getTable).map(IgniteTable.class::cast).collect(Collectors.toMap(IgniteTable::id, Function.identity()));
for (String s : serialized) {
RelJsonReader reader = new RelJsonReader(new SqlSchemaManagerImpl(tableMap));
deserializedNodes.add(reader.read(s));
}
List<RelNode> expectedRels = fragments.stream().map(Fragment::root).collect(Collectors.toList());
assertEquals(expectedRels.size(), deserializedNodes.size(), "Invalid deserialization fragments count");
for (int i = 0; i < expectedRels.size(); ++i) {
RelNode expected = expectedRels.get(i);
RelNode deserialized = deserializedNodes.get(i);
clearTraits(expected);
clearTraits(deserialized);
if (!expected.deepEquals(deserialized)) {
assertTrue(expected.deepEquals(deserialized), "Invalid serialization / deserialization.\n" + "Expected:\n" + RelOptUtil.toString(expected) + "Deserialized:\n" + RelOptUtil.toString(deserialized));
}
}
}
Aggregations