Skip to content

HIVE-29244: Add catalog field into ShowLocksRequest#6314

Open
Neer393 wants to merge 1 commit intoapache:masterfrom
Neer393:HIVE-29244
Open

HIVE-29244: Add catalog field into ShowLocksRequest#6314
Neer393 wants to merge 1 commit intoapache:masterfrom
Neer393:HIVE-29244

Conversation

@Neer393
Copy link
Contributor

@Neer393 Neer393 commented Feb 11, 2026

What changes were proposed in this pull request?

Modified SHowLocksRequest and ShowLocksResponse to include the catalog name and modified the grammar to accept catalog name for getting locks. Added a catalog field to the HMS HIVE_LOCKS table for 4.3.0 and added an alter statement for upgrading from 4.2.0 to 4.3.0

Why are the changes needed?

The changes are needed so that now user can view locks on tables and databases across catalogs.

Does this PR introduce any user-facing change?

No user facing change

How was this patch tested?

Checked the HIVE_LOCKS table and it had the Catalog column and also tried SHOW LOCKS DATABASE dbname; which displayed the catalog column as well. Also tried out SHOW LOCKS DATABASE catname.dbname;

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 84 out of 84 changed files in this pull request and generated 13 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@init { pushMsg("specifying table types", state); }
@after { popMsg(state); }
: identifier (DOT^ identifier)?
: identifier (DOT^ identifier (DOT^ identifier)?)?
Copy link
Member

Choose a reason for hiding this comment

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

why do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because SHOW LOCKS in HiveParser.g uses partTypeExpr which itself uses tabTypeExpr.
So to accomodate specifying catalog name, this change is needed. Removing this would not accept catalog name i.e. currently we use SHOW LOCKS sales_db.orders; but we want to support SHOW LOCKS companycatalaog.sales_db.orders; this as well which requires this change

| KW_SHOW KW_LOCKS
(
(KW_DATABASE|KW_SCHEMA) => (KW_DATABASE|KW_SCHEMA) (dbName=identifier) (isExtended=KW_EXTENDED)? -> ^(TOK_SHOWDBLOCKS $dbName $isExtended?)
(KW_DATABASE|KW_SCHEMA) => (KW_DATABASE|KW_SCHEMA) (name=databaseName) (isExtended=KW_EXTENDED)? -> ^(TOK_SHOWDBLOCKS $name $isExtended?)
Copy link
Member

Choose a reason for hiding this comment

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

what is the purpose of rename?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dbName=identifier just accepted the database name and not catname.dbname
But FromClauseParser.g already has an implementation for parsing both dbname and catname.dbname
So modified the grammar to name=databaseName
If you want, I can change this to (dbName=databaseName)

ctx.setResFile(ctx.getLocalTmpPath());

String tableName = null;
String fullyQualifiedTableName = null;
Copy link
Member

Choose a reason for hiding this comment

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

why rename?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's because now this analyze internal may receive tbname, dbname.tbname and catname.dbname.tbname from which we would need to extract the table name separately.
That is why if you see the logic, I have renamed this to fullyQualifiedTableName and then at the bottom, I am extracting catname, dbname and tbname from it separately.

This made more sense to me as now it's not just the table name we receive but if you still want I can keep the original name. Just let me know

String tableName = null;

if (fullyQualifiedTableName != null) {
String defaultDatabase = SessionState.get() != null
Copy link
Member

@deniskuzZ deniskuzZ Feb 26, 2026

Choose a reason for hiding this comment

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

there are plenty of places that use

TableName table = TableName.fromString(tableName, MetaStoreUtils.getDefaultCatalog(conf),
        Warehouse.DEFAULT_DATABASE_NAME)

should we change there as well and use HiveUtils.getCurrentCatalogOrDefault(conf)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I am pretty sure we would need to change them as according to the current implementation of MetastoreUtils.getDefaultCatalog(conf), I see in any case, it returns hive catalog and does not respect the current session catalog.

public static String getDefaultCatalog(Configuration conf) {
    if (conf == null) {
      LOG.warn("Configuration is null, so going with default catalog.");
      return Warehouse.DEFAULT_CATALOG_NAME;
    }
    String catName = MetastoreConf.getVar(conf, MetastoreConf.ConfVars.CATALOG_DEFAULT);
    if (catName == null || "".equals(catName)) {
      catName = Warehouse.DEFAULT_CATALOG_NAME;
    }
    return catName;
  }

Table t = null;
switch (input.getType()) {
case DATABASE:
compBuilder.setCatName(Optional.ofNullable(input.getDatabase().getCatalogName()).orElse(currentCatalog));
Copy link
Member

Choose a reason for hiding this comment

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

why not move this in getCatalogName?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

input.getDatabase() returns an object of class Database which is a thrift generated class from hive_metastore.thrift for which I see only the fields definition in the hive_metastore.thrift file. So to be honest I don't know how we would move that logic to getCatalogName as it is a generated method.

If you do know, do let me know. Thanks


components.add(createLockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb", "mytable", null, DataOperationType.UPDATE));
components.add(createLockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb", "yourtable", "mypartition=myvalue", DataOperationType.UPDATE));
components.add(createLockComponent(LockType.SHARED_WRITE, LockLevel.DB, "hive", "mydb",
Copy link
Member

Choose a reason for hiding this comment

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

what is the point doing doing changes here. can't you just use hive hardcode in createLockComponent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I did think of it but say in future new tests added to this file wants to create a lock component on some table that is not in hive catalog some new catalog. In that case this method won't be usable. Just for extensibility sake I have modified the usages.

If you want, I can hardcode hive in createLockComponent method itself.

@@ -1,3 +1,5 @@
SELECT 'Upgrading MetaStore schema from 4.2.0 to 4.3.0';

ALTER TABLE `HIVE_LOCKS` ADD COLUMNS (`HL_CATALOG` string);
Copy link
Member

Choose a reason for hiding this comment

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

i don't think it's a good idea to use full catalog name here instead of FK reference

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I did think of same but then I saw the current implementation like we could have done the same i.e create FK reference for db and table as well but I see the current implementation stores the names and not reference as string so I decided to stick with it.

@sonarqubecloud
Copy link

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.

7 participants