Search in sources :

Example 6 with IgniteTable

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);
}
Also used : IgniteTable(org.apache.ignite.internal.sql.engine.schema.IgniteTable) InternalTable(org.apache.ignite.internal.table.InternalTable) Test(org.junit.jupiter.api.Test)

Example 7 with IgniteTable

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);
}
Also used : IgniteTable(org.apache.ignite.internal.sql.engine.schema.IgniteTable) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) InternalTable(org.apache.ignite.internal.table.InternalTable) Test(org.junit.jupiter.api.Test)

Example 8 with IgniteTable

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);
}
Also used : IgniteTable(org.apache.ignite.internal.sql.engine.schema.IgniteTable) InternalTable(org.apache.ignite.internal.table.InternalTable) Test(org.junit.jupiter.api.Test)

Example 9 with IgniteTable

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);
    }
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) RexShuttle(org.apache.calcite.rex.RexShuttle) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) IgniteTable(org.apache.ignite.internal.sql.engine.schema.IgniteTable) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) RelTraitSet(org.apache.calcite.plan.RelTraitSet) Mappings(org.apache.calcite.util.mapping.Mappings) RexInputRef(org.apache.calcite.rex.RexInputRef) RexLocalRef(org.apache.calcite.rex.RexLocalRef) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

IgniteTable (org.apache.ignite.internal.sql.engine.schema.IgniteTable)9 Test (org.junit.jupiter.api.Test)6 InternalTable (org.apache.ignite.internal.table.InternalTable)5 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 RelNode (org.apache.calcite.rel.RelNode)2 RexInputRef (org.apache.calcite.rex.RexInputRef)2 RexLocalRef (org.apache.calcite.rex.RexLocalRef)2 RexNode (org.apache.calcite.rex.RexNode)2 RexShuttle (org.apache.calcite.rex.RexShuttle)2 Mappings (org.apache.calcite.util.mapping.Mappings)2 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)2 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 RelTraitSet (org.apache.calcite.plan.RelTraitSet)1 AbstractRelNode (org.apache.calcite.rel.AbstractRelNode)1 RelReferentialConstraint (org.apache.calcite.rel.RelReferentialConstraint)1 RelHint (org.apache.calcite.rel.hint.RelHint)1 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 Statistic (org.apache.calcite.schema.Statistic)1