Skip to content

fix: use schemaName as fallback for databaseName in Hive DDL/columns/view queries#1818

Open
octo-patch wants to merge 1 commit intoCodePhiliaX:mainfrom
octo-patch:fix/issue-1745-hive-ddl-null-schema
Open

fix: use schemaName as fallback for databaseName in Hive DDL/columns/view queries#1818
octo-patch wants to merge 1 commit intoCodePhiliaX:mainfrom
octo-patch:fix/issue-1745-hive-ddl-null-schema

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #1745

Problem

When viewing a Hive table's DDL structure, the query fails with:

Table not found null.ods_cancel_order RuntimeException

Root cause: In Hive, schema and database represent the same concept. The HiveMetaData.schemas() method already reflects this by returning Schema(name=databaseName). However, when a client calls the DDL export endpoint passing only schemaName (without databaseName), the tableDDL(), columns(), and view() methods all used databaseName directly in their SQL queries — producing null.table_name when databaseName was absent.

Solution

Apply a schemaName fallback in the three affected methods so the effective database name is resolved correctly:

String effectiveDb = StringUtils.isNotBlank(databaseName) ? databaseName : schemaName;

This is applied to:

  • tableDDL()SHOW CREATE TABLE
  • columns()DESCRIBE FORMATTED
  • view()SHOW CREATE TABLE for views

Testing

The fix resolves the Table not found null.table_name error reported in the issue. No existing behavior is changed when databaseName is already populated.

…view queries (fixes CodePhiliaX#1745)

In Hive, schema and database represent the same concept. When a client passes
schemaName without databaseName (e.g. from the DDL export endpoint), the SQL
was generated as `SHOW CREATE TABLE null.table_name`, causing a SemanticException.

Apply the same schemaName fallback in tableDDL(), columns(), and view() so all
three operations work correctly regardless of which field the caller populates.
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.

Bug: 连接Hive时无法查看表的DDL结构

1 participant