Search in sources :

Example 1 with IgniteTable

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);
}
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 2 with IgniteTable

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

Example 3 with IgniteTable

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);
}
Also used : SqlSchemaManager(org.apache.ignite.internal.sql.engine.schema.SqlSchemaManager) IgniteTable(org.apache.ignite.internal.sql.engine.schema.IgniteTable) Statistic(org.apache.calcite.schema.Statistic) RelNode(org.apache.calcite.rel.RelNode) RelDataType(org.apache.calcite.rel.type.RelDataType) UUID(java.util.UUID) IgniteTableScan(org.apache.ignite.internal.sql.engine.rel.IgniteTableScan) Test(org.junit.jupiter.api.Test)

Example 4 with IgniteTable

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);
}
Also used : RexShuttle(org.apache.calcite.rex.RexShuttle) IgniteTable(org.apache.ignite.internal.sql.engine.schema.IgniteTable) Mappings(org.apache.calcite.util.mapping.Mappings) ControlFlowException(org.apache.calcite.util.ControlFlowException) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) ArrayList(java.util.ArrayList) RexLocalRef(org.apache.calcite.rex.RexLocalRef) RexInputRef(org.apache.calcite.rex.RexInputRef) RelHint(org.apache.calcite.rel.hint.RelHint) RexNode(org.apache.calcite.rex.RexNode)

Example 5 with IgniteTable

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));
        }
    }
}
Also used : Splitter(org.apache.ignite.internal.sql.engine.prepare.Splitter) IgniteTable(org.apache.ignite.internal.sql.engine.schema.IgniteTable) InternalIgniteTable(org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable) ArrayList(java.util.ArrayList) Fragment(org.apache.ignite.internal.sql.engine.prepare.Fragment) RelReferentialConstraint(org.apache.calcite.rel.RelReferentialConstraint) AbstractRelNode(org.apache.calcite.rel.AbstractRelNode) RelNode(org.apache.calcite.rel.RelNode) RelJsonReader(org.apache.ignite.internal.sql.engine.externalize.RelJsonReader) UUID(java.util.UUID)

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