Search in sources :

Example 1 with RelJsonReader

use of org.apache.ignite.internal.sql.engine.externalize.RelJsonReader 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

ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 AbstractRelNode (org.apache.calcite.rel.AbstractRelNode)1 RelNode (org.apache.calcite.rel.RelNode)1 RelReferentialConstraint (org.apache.calcite.rel.RelReferentialConstraint)1 RelJsonReader (org.apache.ignite.internal.sql.engine.externalize.RelJsonReader)1 Fragment (org.apache.ignite.internal.sql.engine.prepare.Fragment)1 Splitter (org.apache.ignite.internal.sql.engine.prepare.Splitter)1 IgniteTable (org.apache.ignite.internal.sql.engine.schema.IgniteTable)1 InternalIgniteTable (org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable)1