Skip to content

IGNITE-28596 Add test to check TPCH plans#13068

Open
nizhikov wants to merge 40 commits into
apache:masterfrom
nizhikov:IGNITE-28596
Open

IGNITE-28596 Add test to check TPCH plans#13068
nizhikov wants to merge 40 commits into
apache:masterfrom
nizhikov:IGNITE-28596

Conversation

@nizhikov
Copy link
Copy Markdown
Contributor

Thank you for submitting the pull request to the Apache Ignite.

In order to streamline the review of the contribution
we ask you to ensure the following steps have been taken:

The Contribution Checklist

  • There is a single JIRA ticket related to the pull request.
  • The web-link to the pull request is attached to the JIRA ticket.
  • The JIRA ticket has the Patch Available state.
  • The pull request body describes changes that have been made.
    The description explains WHAT and WHY was made instead of HOW.
  • The pull request title is treated as the final commit message.
    The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
  • A reviewer has been mentioned through the JIRA comments
    (see the Maintainers list)
  • The pull request has been checked by the Teamcity Bot and
    the green visa attached to the JIRA ticket (see tab PR Check at TC.Bot - Instance 1 or TC.Bot - Instance 2)

Notes

If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com #ignite channel.

@sonarqubecloud
Copy link
Copy Markdown

TpchHelper.createTables(srv);

/*
TpchHelper.fillTables(srv, 0.01);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems it need to be fixed somehow ?

* @return {@code True} if any expanded plan equals to the parameter.
*/
public boolean match(String actualPlan) {
return expandOneof(template).stream()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return expandOneof(template).stream()
return expandOneof(template).stream()

@zstan
Copy link
Copy Markdown
Contributor

zstan commented May 18, 2026

Overall looks good instead i still believe that non-empty tables size need to be involved, probably places like :
{ONEOF}
...
{ONEOF}
can be reduced or fully removed too.
table row size are requested from : IgniteStatisticsImpl#getRowCount if it hard to implement right now - probably we need follow up issue for such a case.

/**
* Abstract test class to ensure a planner generates expected plan for TPC queries.
*/
public class AbstractTpcQueryPlannerTest extends AbstractPlannerTest {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a planner test, it's an integration test, you almost not use AbstractPlannerTest except plannerCtx, but you don't need it, the same result can be obtained by just:

sql("EXPLAIN PLAN FOR " + loadFromResource(sqlTestName(getClass()) + "/" + queryId + ".sql"))

So, it's more correct to inherit from AbstractBasicIntegrationTest


/** Query id. Set by {@link PlanChecker}. */
@Parameterized.Parameter
public String queryId;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abbreviation should be used

Comment on lines +69 to +104
/** Run once, before all queries check. */
@BeforePlansTest
public static void startAll(Class<?> testClass) throws Exception {
AbstractTpcQueryPlannerTest mock = new AbstractTpcQueryPlannerTest();

mock.beforeFirstTest();

IgniteConfiguration cfg = mock.getConfiguration("server");

cfg.getSqlConfiguration()
.setQueryEnginesConfiguration(new CalciteQueryEngineConfiguration().setDefault(true));

srv = (IgniteEx)IgnitionEx.start(cfg);

srv.getOrCreateCache(new CacheConfiguration<>("mock")
.setSqlFunctionClasses(AbstractTpcQueryPlannerTest.TpchUDF.class)
.setSqlSchema("PUBLIC"));

TpchHelper.createTables(srv);

/*
TpchHelper.fillTables(srv, 0.01);

TpchHelper.collectSqlStatistics(srv);
*/
}

/** Run once, after all queries check. */
@AfterPlansTest
public static void stopAll(Class<?> testClass) {
if (srv != null) {
srv.close();

srv = null;
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overcomplicated, it's hard to read and understand. All PlanChecker related code (together with PlanChecker itself) can be replaced with standard parameterized test, all you need is one method:

    @Parameterized.Parameters(name = "queryId={0}")
    public static Collection<String> params() throws IOException {
        return Files.list(Path.of(RSRC_DIR, "tpch"))
            .filter(p -> p.toString().endsWith(".sql") && !p.toString().endsWith("ddl.sql"))
            .sorted()
            .map(p -> p.getFileName().toString().replace(".sql", ""))
            .collect(Collectors.toList());
    }

Or extend AbstractTpchTest and redefine set of tests.

* @param sql SQL query.
* @param params Query parameters.
*/
public static List<List<?>> sql(Ignite ignite, String sql, Object... params) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed if test will be inherited from AbstractBasicIntegrationTest

}

/** */
public static class TpchUDF {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UDF not used at all

*/
public class PlanTemplate {
/** */
private static final Pattern ID_PATTERN = Pattern.compile(", id = \\d+");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to remove "id" from plan. It's not needed for user at all (only required for developer, for planner dumps).

private static final Pattern ID_PATTERN = Pattern.compile(", id = \\d+");

/** */
private static final Pattern HASH_PATTERN = Pattern.compile(", hash=-?\\d+]");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to beautify AffinityIdentity.toString() (add annotation @GridToStringExclude to hash field)?

while (sc.hasNextLine()) {
String line = sc.nextLine();

for (StringBuffer expanded : res) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant braces

}

/** Expands plans. Replace {ONEOF} tag with the possible cases. */
private static List<String> expandOneof(String plan) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oneof -> OneOf
Inconsistent API with expandIndexCase (one returns Stream, another returns List)

TpchHelper.createTables(srv);

/*
TpchHelper.fillTables(srv, 0.01);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It takes about 5 seconds to fill with 0.01 scale, but in this case plans are more predictable. Plans without data are irrelevant, I this we should fill the tables.

}

/** Expands plans. Replace {INDEX_CASE} tag with the possible indexes. */
private static Stream<String> expandIndexCase(String plan) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these cases with {INDEX_CASE} are related to proxy indexes. Maybe just replace index=[{index_name}_proxy] with index=[{index_name}] and don't use {INDEX_CASE} at all?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants