Skip to content

HIVE-29668: Add -rebuildIndexes utility to reconstruct backend Metast… - #6636

Open
soumyakanti3578 wants to merge 2 commits into
apache:masterfrom
soumyakanti3578:HIVE-29668-index-gen
Open

HIVE-29668: Add -rebuildIndexes utility to reconstruct backend Metast…#6636
soumyakanti3578 wants to merge 2 commits into
apache:masterfrom
soumyakanti3578:HIVE-29668-index-gen

Conversation

@soumyakanti3578

@soumyakanti3578 soumyakanti3578 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

…ore indexes

What changes were proposed in this pull request?

  1. Add a rebuildIndexes option to schemaTool
  2. For postgres, mysql, oracle, and mssql, add a rebuild-indexes sql file that drops and recreates all HMS indexes.
  3. Tests

Why are the changes needed?

Gives users the ability to drop and recreate indexes easily through schematool.

Does this PR introduce any user-facing change?

Yes, adds a new option to schematool.

How was this patch tested?

mvn -pl standalone-metastore/metastore-server -Dtest=TestRebuildIndexesScriptConsistency  test
mvn -pl standalone-metastore/metastore-server -Dtest="TestSchemaToolForMetastore#testRebuildIndexes" -Dtest.groups="" -DfailIfNoTests=false test

@soumyakanti3578
soumyakanti3578 marked this pull request as ready for review July 24, 2026 19:46
@soumyakanti3578 soumyakanti3578 changed the title [WIP]HIVE-29668: Add -rebuildIndexes utility to reconstruct backend Metast… HIVE-29668: Add -rebuildIndexes utility to reconstruct backend Metast… Jul 27, 2026
@sonarqubecloud

Copy link
Copy Markdown

@nrg4878 nrg4878 left a comment

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.

I wasnt expecting that we will be checking in rebuild-indexes scripts as well. But I do not have a problem per se as long as these get updated when new indices are added.


@Category(MetastoreUnitTest.class)
@RunWith(Parameterized.class)
public class TestRebuildIndexesScriptConsistency {

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.

can we add a test that fails if we add a new index to the schema file that is not found in the rebuild-indexes file ? So that way developers will remember to update these files as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, that is exactly what's being tested in rebuildScriptMatchesInitScript()

    Pattern pattern = PATTERNS.get(dbType);
    Set<String> initIndexes = extractIndexNames(schemaScript, pattern);
    Set<String> rebuildIndexes = extractIndexNames(rebuildScript, pattern);

    Set<String> missing = new HashSet<>(initIndexes);
    missing.removeAll(rebuildIndexes);

    Set<String> extra = new HashSet<>(rebuildIndexes);
    extra.removeAll(initIndexes);

    assertTrue("Indexes in init script missing from rebuild script: " + missing, missing.isEmpty());
    assertTrue("Indexes in rebuild script not found in init script: " + extra, extra.isEmpty());

and it tests extra indexes in the rebuild scripts too, so devs can remember to remove them if we ever remove an index from the schema file.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants