Skip to content

Conversation

@HangyuanLiu
Copy link
Contributor

@HangyuanLiu HangyuanLiu commented Dec 12, 2025

Why I'm doing:

What I'm doing:

This pull request refactors how table names are handled throughout the codebase, moving from direct usage of TableName objects to consistently constructing them from TableRef instances. This change standardizes table identification, making the code more robust and easier to maintain, especially when working with parsed SQL statements. Several visitor methods and job classes are updated to use the new utility method TableName.fromTableRef, and parser logic is adjusted to propagate TableRef instead of TableName where appropriate.

Core Table Name Handling Refactor:

  • Added a new utility method fromTableRef to the TableName class, allowing construction of a TableName from a TableRef object. This is now the preferred way to obtain a TableName from AST nodes.
  • Updated various visitor and executor classes (e.g., AlterJobExecutor, ConnectorAlterTableExecutor, ColumnPrivilege) to use TableName.fromTableRef instead of directly accessing or storing TableName from statements. [1] [2] [3] [4] [5] [6] [7]

Parser and Statement Construction Updates:

  • Modified the Trino parser (AstBuilder) to propagate TableRef instead of TableName in InsertStmt, CreateTableStmt, and DropTableStmt construction, aligning with the new table name handling approach. [1] [2] [3]

Job and Manager Class Adjustments:

  • Refactored job management classes (DeleteMgr, ExportJob, InsertOverwriteJobRunner, Pipe) to extract database and table names from TableRef rather than TableName, ensuring consistency and leveraging the new utility method. [1] [2] [3] [4] [5] [6]

Iceberg and Stream Load Integration:

  • Updated Iceberg connector and rewrite job logic to use TableRef and construct TableName via the new method, improving error reporting and logging. [1] [2]
  • Adjusted imports and cleaned up unused direct TableName references in stream load and related classes. [1] [2]

These changes collectively improve the maintainability and correctness of table name handling across the codebase by ensuring a single, reliable pathway from SQL AST to persistent table identification.

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 4.0
    • 3.5
    • 3.4
    • 3.3

Note

Unifies table identification across the stack by switching from direct TableName usage to TableRef in AST, analyzers, planners, and executors, with on-demand conversion via TableName.fromTableRef.

  • Adds TableName.fromTableRef and AnalyzerUtils.normalizedTableRef; updates DML/DDL analyzers, authorizer, planners, and executors to store/use TableRef and construct TableName only when needed
  • Trino parser (AstBuilder) now builds InsertStmt/CreateTableStmt/DropTableStmt with TableRef
  • Refactors jobs/managers (DeleteMgr, ExportJob, InsertOverwriteJobRunner, Pipe, Iceberg metadata/rewrite) to pull db/table from TableRef; improves error messages/logging
  • Reworks ShowExecutor helpers and multiple SHOW paths to accept/use TableRef; replaces calls in ShowExecutor/authorizer
  • Updates table create/like/alter/refresh paths to TableRef (e.g., CreateTableAnalyzer, CreateTableLikeAnalyzer, CancelAlterTableStmt, AlterJobExecutor, ConnectorAlterTableExecutor)
  • Adds null checks for missing TableRef and adjusts privilege checks accordingly

No functional changes intended; primarily API/refactor for consistency and maintainability.

Written by Cursor Bugbot for commit 34960e0. This will update automatically on new commits. Configure here.

@HangyuanLiu HangyuanLiu requested review from a team as code owners December 12, 2025 06:14
@mergify
Copy link
Contributor

mergify bot commented Dec 12, 2025

🧪 CI Insights

Here's what we observed from your CI run for 0b360ee.

🟢 All jobs passed!

But CI Insights is watching 👀

@alvin-celerdata
Copy link
Contributor

@cursor review

@alvin-celerdata
Copy link
Contributor

@cursor review

@HangyuanLiu HangyuanLiu force-pushed the 1211-table-name branch 3 times, most recently from 97527f7 to aa8f1fe Compare December 15, 2025 08:39
@alvin-celerdata
Copy link
Contributor

@cursor review

@alvin-celerdata
Copy link
Contributor

@cursor review

# Conflicts:
#	fe/fe-core/src/main/java/com/starrocks/sql/DeletePlanner.java
#	fe/fe-core/src/main/java/com/starrocks/sql/analyzer/DeleteAnalyzer.java
…utor, IcebergMetadata, LocalMetastore, and related classes
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
13.5% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@github-actions
Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions
Copy link

[FE Incremental Coverage Report]

pass : 1006 / 1205 (83.49%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/authorization/ColumnPrivilege.java 0 9 00.00% [262, 263, 264, 271, 272, 273, 280, 281, 282]
🔵 com/starrocks/connector/iceberg/IcebergRewriteDataJob.java 0 3 00.00% [143, 144, 145]
🔵 com/starrocks/server/MetadataMgr.java 0 5 00.00% [421, 422, 423, 424, 425]
🔵 com/starrocks/connector/iceberg/IcebergMetadata.java 0 6 00.00% [366, 367, 368, 369, 371, 373]
🔵 com/starrocks/statistic/FullStatisticsCollectJob.java 0 2 00.00% [297, 299]
🔵 com/starrocks/scheduler/mv/IMTCreator.java 1 6 16.67% [232, 235, 236, 237, 243]
🔵 com/starrocks/sql/ast/StreamLoadStmt.java 1 3 33.33% [29, 33]
🔵 com/starrocks/sql/ast/pipe/CreatePipeStmt.java 3 6 50.00% [88, 92, 96]
🔵 com/starrocks/sql/ast/CreateTableStmt.java 8 16 50.00% [84, 100, 261, 262, 264, 265, 266, 267]
🔵 com/starrocks/sql/ast/ShowColumnStmt.java 4 8 50.00% [33, 46, 50, 54]
🔵 com/starrocks/service/FrontendServiceImpl.java 3 6 50.00% [2254, 2255, 2256]
🔵 com/starrocks/sql/ast/CreateMaterializedViewStmt.java 7 13 53.85% [184, 188, 189, 196, 200, 227]
🔵 com/starrocks/alter/AlterJobExecutor.java 3 5 60.00% [266, 269]
🔵 com/starrocks/sql/analyzer/InsertAnalyzer.java 11 18 61.11% [590, 591, 592, 593, 594, 595, 596]
🔵 com/starrocks/sql/ast/DropStatsStmt.java 5 8 62.50% [26, 44, 48]
🔵 com/starrocks/sql/ast/RecoverTableStmt.java 5 8 62.50% [41, 45, 49]
🔵 com/starrocks/server/LocalMetastore.java 12 19 63.16% [3320, 3323, 3435, 3436, 4994, 5001, 5004]
🔵 com/starrocks/qe/StmtExecutor.java 22 34 64.71% [1181, 1735, 1894, 1895, 1896, 1898, 1899, 1934, 2591, 2592, 2593, 2719]
🔵 com/starrocks/sql/ast/DmlStmt.java 4 6 66.67% [47, 48]
🔵 com/starrocks/sql/ast/DropHistogramStmt.java 6 8 75.00% [31, 49]
🔵 com/starrocks/load/ExportJob.java 6 8 75.00% [278, 283]
🔵 com/starrocks/catalog/TableName.java 3 4 75.00% [121]
🔵 com/starrocks/sql/ast/AdminSetPartitionVersionStmt.java 3 4 75.00% [34]
🔵 com/starrocks/sql/ast/CreateTableAsSelectStmt.java 3 4 75.00% [49]
🔵 com/starrocks/sql/analyzer/DropStmtAnalyzer.java 11 14 78.57% [99, 115, 119]
🔵 com/starrocks/sql/ast/DeleteStmt.java 4 5 80.00% [68]
🔵 com/starrocks/sql/ast/ShowIndexStmt.java 4 5 80.00% [41]
🔵 com/starrocks/server/GlobalStateMgr.java 4 5 80.00% [2526]
🔵 com/starrocks/load/pipe/Pipe.java 4 5 80.00% [137]
🔵 com/starrocks/sql/ast/ShowTabletStmt.java 9 11 81.82% [55, 85]
🔵 com/starrocks/sql/analyzer/AlterTableStatementAnalyzer.java 5 6 83.33% [46]
🔵 com/starrocks/sql/analyzer/CTASAnalyzer.java 5 6 83.33% [92]
🔵 com/starrocks/sql/analyzer/MaterializedViewAnalyzer.java 45 54 83.33% [920, 1699, 1707, 1710, 1711, 1726, 1750, 1764, 1768]
🔵 com/starrocks/sql/analyzer/AnalyzeStmtAnalyzer.java 81 97 83.51% [126, 221, 255, 257, 261, 268, 272, 273, 286, 287, 292, 293, 305, 322, 389, 390]
🔵 com/starrocks/sql/ast/AnalyzeStmt.java 6 7 85.71% [91]
🔵 com/starrocks/sql/analyzer/AuthorizerStmtVisitor.java 143 165 86.67% [316, 337, 356, 1037, 1056, 1068, 1780, 1782, 1824, 1865, 1875, 1918, 1919, 1920, 1951, 1970, 2001, 2003, 2028, 2047, 2059, 2347]
🔵 com/starrocks/sql/StatementPlanner.java 20 23 86.96% [536, 641, 642]
🔵 com/starrocks/sql/ast/RefreshTableStmt.java 7 8 87.50% [54]
🔵 com/starrocks/sql/ast/RecoverPartitionStmt.java 7 8 87.50% [43]
🔵 com/starrocks/sql/ast/ShowPartitionsStmt.java 7 8 87.50% [90]
🔵 com/starrocks/sql/analyzer/CreateTableAnalyzer.java 14 16 87.50% [96, 110]
🔵 com/starrocks/sql/ast/DropMaterializedViewStmt.java 7 8 87.50% [35]
🔵 com/starrocks/sql/analyzer/ShowTabletStmtAnalyzer.java 7 8 87.50% [101]
🔵 com/starrocks/load/DeleteMgr.java 7 8 87.50% [170]
🔵 com/starrocks/qe/ShowExecutor.java 148 169 87.57% [749, 869, 1124, 1137, 1874, 2403, 2416, 3213, 3258, 3265, 3266, 3291, 3296, 3323, 3328, 3332, 3333, 3353, 3358, 3362, 3363]
🔵 com/starrocks/sql/ast/ExportStmt.java 15 17 88.24% [186, 190]
🔵 com/starrocks/sql/analyzer/ViewAnalyzer.java 15 17 88.24% [52, 91]
🔵 com/starrocks/sql/analyzer/ShowStmtAnalyzer.java 20 22 90.91% [338, 616]
🔵 com/starrocks/sql/ast/CreateTableLikeStmt.java 13 14 92.86% [81]
🔵 com/starrocks/sql/analyzer/CreateTableLikeAnalyzer.java 16 17 94.12% [53]
🔵 com/starrocks/sql/analyzer/AnalyzerUtils.java 24 25 96.00% [2021]
🔵 com/starrocks/sql/analyzer/ShowStmtToSelectStmtConverter.java 3 3 100.00% []
🔵 com/starrocks/statistic/HyperStatisticsCollectJob.java 2 2 100.00% []
🔵 com/starrocks/sql/ast/DropTemporaryTableStmt.java 1 1 100.00% []
🔵 com/starrocks/sql/ast/DropTableStmt.java 8 8 100.00% []
🔵 com/starrocks/sql/DeletePlanner.java 2 2 100.00% []
🔵 com/starrocks/statistic/ExternalFullStatisticsCollectJob.java 2 2 100.00% []
🔵 com/starrocks/sql/analyzer/RecoverTableAnalyzer.java 2 2 100.00% []
🔵 com/starrocks/sql/ast/CreateMaterializedViewStatement.java 7 7 100.00% []
🔵 com/starrocks/sql/ast/CreateAnalyzeJobStmt.java 21 21 100.00% []
🔵 com/starrocks/sql/analyzer/DMLStmtAnalyzer.java 7 7 100.00% []
🔵 com/starrocks/sql/ast/DescribeStmt.java 9 9 100.00% []
🔵 com/starrocks/sql/ast/AlterViewStmt.java 8 8 100.00% []
🔵 com/starrocks/sql/ast/AlterTableStmt.java 7 7 100.00% []
🔵 com/starrocks/sql/analyzer/RefreshTableStatementAnalyzer.java 5 5 100.00% []
🔵 com/starrocks/sql/UpdatePlanner.java 2 2 100.00% []
🔵 com/starrocks/sql/ast/AlterMaterializedViewStmt.java 7 7 100.00% []
🔵 com/starrocks/statistic/StatisticsMetaManager.java 23 23 100.00% []
🔵 com/starrocks/sql/ast/CreateTemporaryTableStmt.java 2 2 100.00% []
🔵 com/starrocks/sql/analyzer/DeleteAnalyzer.java 2 2 100.00% []
🔵 com/starrocks/sql/analyzer/RecoverPartitionAnalyzer.java 2 2 100.00% []
🔵 com/starrocks/statistic/MultiColumnHyperStatisticsCollectJob.java 2 2 100.00% []
🔵 com/starrocks/sql/analyzer/PlannerMetaLocker.java 15 15 100.00% []
🔵 com/starrocks/sql/analyzer/UpdateAnalyzer.java 3 3 100.00% []
🔵 com/starrocks/sql/analyzer/PipeAnalyzer.java 4 4 100.00% []
🔵 com/starrocks/sql/ast/CreateViewStmt.java 8 8 100.00% []
🔵 com/starrocks/sql/InsertPlanner.java 6 6 100.00% []
🔵 com/starrocks/connector/parser/trino/AstBuilder.java 8 8 100.00% []
🔵 com/starrocks/sql/formatter/AST2StringVisitor.java 12 12 100.00% []
🔵 com/starrocks/sql/ast/UpdateStmt.java 4 4 100.00% []
🔵 com/starrocks/sql/ast/pipe/ShowPipeStmt.java 3 3 100.00% []
🔵 com/starrocks/connector/ConnectorAlterTableExecutor.java 1 1 100.00% []
🔵 com/starrocks/transaction/TransactionStmtExecutor.java 2 2 100.00% []
🔵 com/starrocks/sql/plan/PlanFragmentBuilder.java 1 1 100.00% []
🔵 com/starrocks/sql/analyzer/AdminStmtAnalyzer.java 1 1 100.00% []
🔵 com/starrocks/sql/ast/ShowCreateTableStmt.java 8 8 100.00% []
🔵 com/starrocks/sql/ast/CancelRefreshMaterializedViewStmt.java 8 8 100.00% []
🔵 com/starrocks/sql/ast/InsertStmt.java 6 6 100.00% []
🔵 com/starrocks/sql/analyzer/CancelAlterTableStatementAnalyzer.java 2 2 100.00% []
🔵 com/starrocks/sql/ast/CreateTemporaryTableLikeStmt.java 1 1 100.00% []
🔵 com/starrocks/sql/ast/IcebergRewriteStmt.java 1 1 100.00% []
🔵 com/starrocks/load/InsertOverwriteJobRunner.java 1 1 100.00% []
🔵 com/starrocks/sql/analyzer/ExportStmtAnalyzer.java 9 9 100.00% []
🔵 com/starrocks/sql/ast/RefreshMaterializedViewStatement.java 7 7 100.00% []
🔵 com/starrocks/sql/ast/CancelAlterTableStmt.java 8 8 100.00% []
🔵 com/starrocks/load/streamload/StreamLoadTask.java 2 2 100.00% []
🔵 com/starrocks/qe/DDLStmtExecutor.java 3 3 100.00% []

@github-actions
Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@alvin-celerdata
Copy link
Contributor

@cursor review

String tableName = stmt.getTableName().toSql();
TableRef tableRef = stmt.getTableRef();
TableName tableNameObj = TableName.fromTableRef(tableRef);
String tableName = tableNameObj.toSql();
Copy link

Choose a reason for hiding this comment

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

Missing null check causes NPE in partition pruning

The partitionPruneForDelete method calls TableName.fromTableRef(tableRef) without checking if tableRef is null first. Since fromTableRef returns null when given null input, the subsequent call to tableNameObj.toSql() will throw a NullPointerException. While the process method has a null check for tableRef, the public method extractPartitionNamesByCondition directly calls partitionPruneForDelete without this protection, allowing callers to trigger the NPE.

Fix in Cursor Fix in Web

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.

2 participants