use of org.apache.ignite.internal.sql.engine.schema.IgniteTable in project ignite-3 by apache.
the class SqlSchemaManagerTest method testTableEventIsNotProcessed.
@Test
public void testTableEventIsNotProcessed() throws NodeStoppingException {
when(tableManager.table(eq(tableId))).thenReturn(table);
when(table.schemaView()).thenReturn(schemaRegistry);
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());
IgniteTable actTable = schemaManager.tableById(tableId, tableVer);
assertEquals(tableId, actTable.id());
Mockito.verify(tableManager).table(eq(tableId));
Mockito.verifyNoMoreInteractions(tableManager);
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteTable in project ignite-3 by apache.
the class SqlSchemaManagerTest method testTableEventIsProcessedRequiredVersionIsGreater.
@Test
public void testTableEventIsProcessedRequiredVersionIsGreater() throws NodeStoppingException {
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(tableVer - 1);
schemaManager.onTableCreated("TEST_SCHEMA", table, testRevisionRegister.actualToken() + 1);
testRevisionRegister.moveForward();
when(tableManager.table(eq(tableId))).thenReturn(table);
when(schemaRegistry.lastSchemaVersion()).thenReturn(tableVer);
IgniteTable actTable = schemaManager.tableById(tableId, tableVer);
assertEquals(tableId, actTable.id());
IgniteInternalException ex = assertThrows(IgniteInternalException.class, () -> schemaManager.tableById(tableId, tableVer + 1));
assertThat(ex.getMessage(), containsString("Table version not found"));
Mockito.verify(tableManager, times(2)).table(eq(tableId));
Mockito.verifyNoMoreInteractions(tableManager);
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteTable in project ignite-3 by apache.
the class SqlSchemaManagerTest method testTableEventIsProcessedRequiredVersionIsSame.
@Test
public void testTableEventIsProcessedRequiredVersionIsSame() {
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);
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 ProjectScanMergeRule method onMatch.
/**
* {@inheritDoc}
*/
@Override
public void onMatch(RelOptRuleCall call) {
LogicalProject relProject = call.rel(0);
T scan = call.rel(1);
RelOptCluster cluster = scan.getCluster();
List<RexNode> projects = relProject.getProjects();
RexNode cond = scan.condition();
ImmutableBitSet requiredColumns = scan.requiredColumns();
List<RexNode> scanProjects = scan.projects();
// Set default traits, real traits will be calculated for physical node.
RelTraitSet traits = cluster.traitSet();
IgniteTable tbl = scan.getTable().unwrap(IgniteTable.class);
IgniteTypeFactory typeFactory = Commons.typeFactory(cluster);
if (requiredColumns == null) {
assert scanProjects == null;
ImmutableBitSet.Builder builder = ImmutableBitSet.builder();
new RexShuttle() {
@Override
public RexNode visitInputRef(RexInputRef ref) {
builder.set(ref.getIndex());
return ref;
}
}.apply(projects);
new RexShuttle() {
@Override
public RexNode visitLocalRef(RexLocalRef inputRef) {
builder.set(inputRef.getIndex());
return inputRef;
}
}.apply(cond);
requiredColumns = builder.build();
Mappings.TargetMapping targetMapping = Commons.mapping(requiredColumns, tbl.getRowType(typeFactory).getFieldCount());
projects = new RexShuttle() {
@Override
public RexNode visitInputRef(RexInputRef ref) {
return new RexLocalRef(targetMapping.getTarget(ref.getIndex()), ref.getType());
}
}.apply(projects);
cond = new RexShuttle() {
@Override
public RexNode visitLocalRef(RexLocalRef ref) {
return new RexLocalRef(targetMapping.getTarget(ref.getIndex()), ref.getType());
}
}.apply(cond);
} else {
projects = RexUtils.replaceInputRefs(projects);
}
if (scanProjects != null) {
// Merge projects.
projects = new RexShuttle() {
@Override
public RexNode visitLocalRef(RexLocalRef ref) {
return scanProjects.get(ref.getIndex());
}
}.apply(projects);
}
if (RexUtils.isIdentity(projects, tbl.getRowType(typeFactory, requiredColumns), true)) {
projects = null;
}
call.transformTo(createNode(cluster, scan, traits, projects, cond, requiredColumns));
if (!RexUtils.hasCorrelation(relProject.getProjects())) {
cluster.getPlanner().prune(relProject);
}
}
Aggregations