Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Refactor create table analyzer process #45498

Merged
merged 1 commit into from May 14, 2024

Conversation

HangyuanLiu
Copy link
Contributor

@HangyuanLiu HangyuanLiu commented May 11, 2024

Why I'm doing:

What I'm doing:

No logic modification, just tidying up the code logic

Fixes #issue

fix #44543

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
    • 3.3
    • 3.2
    • 3.1
    • 3.0
    • 2.5

@HangyuanLiu HangyuanLiu requested review from a team as code owners May 11, 2024 09:54
* @param partitionColumnExpr : the materialized view's partition expr
* @param connectContext : connect context of the current session.
* @param queryStatement : the sub query statment that contains the partition column slot ref
* @return : return the resolved partition expr.
* @return : return the resolved partition expr.
*/
private Expr resolvePartitionExpr(Expr partitionColumnExpr,
ConnectContext connectContext,
Copy link

Choose a reason for hiding this comment

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

The most risky bug in this code is:
The removal and re-addition of IndexDef import without clear context on why it's been moved.

You can modify the code like this to ensure clarity on IndexDef usage or if the relocation was necessary, justify or comment on the reason behind such an action:

// Original location with a comment explaining why it might need to be relocated or kept here.
import com.starrocks.analysis.IndexDef;
// Further down if moved
// Moved to com.starrocks.sql.ast for reasons X, Y, Z.
import com.starrocks.sql.ast.IndexDef;

return pos;
}
}

Copy link

Choose a reason for hiding this comment

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

The most risky bug in this code is:
Improper construction of KeysDesc object with potentially mutable List reference.

You can modify the code like this:

public KeysDesc(KeysType type, List<String> keysColumnNames, NodePosition pos) {
    this.pos = pos;
    this.type = type;
    // Create a new ArrayList from the provided list to ensure immutability of internal state
    this.keysColumnNames = new ArrayList<>(keysColumnNames);
}

public boolean isHasGeneratedColumn() {
return hasGeneratedColumn;
}

public static CreateTableStmt read(DataInput in) throws IOException {
throw new RuntimeException("CreateTableStmt serialization is not supported anymore.");
}
Copy link

Choose a reason for hiding this comment

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

The most risky bug in this code is:
The columns and indexes fields in the CreateTableStmt class are not initialized, which can lead to a NullPointerException when their getter methods are called before they are explicitly set.

You can modify the code like this:

@@ -48,14 +45,19 @@ public class CreateTableStmt extends DdlStmt {
     private List<AlterClause> rollupAlterClauseList;
 
     // set in analyze
-    private List<Column> columns;
+    private List<Column> columns = Lists.newArrayList();
     private List<String> sortKeys = Lists.newArrayList();
 
-    private List<Index> indexes;
+    private List<Index> indexes = Lists.newArrayList();
 
     // for backup. set to -1 for normal use
     private int tableSignature;
 
     boolean hasHll = false;
     boolean hasBitmap = false;
     boolean hasReplace = false;
     boolean hasGeneratedColumn = false;

This ensures that both columns and indexes are immediately usable after an instance of CreateTableStmt is created, avoiding the risk of encountering a NullPointerException if getters are called before these fields are explicitly set using their respective setter methods.

nshangyiming
nshangyiming previously approved these changes May 13, 2024
@nshangyiming nshangyiming removed their assignment May 13, 2024
@HangyuanLiu HangyuanLiu force-pushed the 0511-refactor-create-table branch 2 times, most recently from 03f884b to 7fbdec2 Compare May 13, 2024 07:46
Copy link

sonarcloud bot commented May 13, 2024

Copy link

[FE Incremental Coverage Report]

pass : 389 / 448 (86.83%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/connector/elasticsearch/EsUtil.java 0 6 00.00% [66, 67, 70, 71, 78, 79]
🔵 com/starrocks/sql/common/MetaUtils.java 0 2 00.00% [57, 60]
🔵 com/starrocks/sql/ast/KeysDesc.java 10 16 62.50% [30, 31, 32, 33, 34, 60]
🔵 com/starrocks/sql/ast/CreateTableStmt.java 14 20 70.00% [308, 309, 312, 316, 317, 320]
🔵 com/starrocks/sql/analyzer/CreateTableAnalyzer.java 268 301 89.04% [92, 117, 128, 148, 149, 186, 192, 231, 240, 245, 267, 268, 291, 306, 319, 324, 328, 338, 344, 371, 372, 410, 416, 426, 435, 448, 478, 486, 487, 527, 533, 534, 551]
🔵 com/starrocks/sql/ast/IndexDef.java 90 96 93.75% [79, 125, 139, 169, 181, 211]
🔵 com/starrocks/sql/analyzer/InsertAnalyzer.java 2 2 100.00% []
🔵 com/starrocks/sql/analyzer/DropStmtAnalyzer.java 3 3 100.00% []
🔵 com/starrocks/sql/analyzer/AlterTableClauseVisitor.java 1 1 100.00% []
🔵 com/starrocks/sql/analyzer/CreateDbAnalyzer.java 1 1 100.00% []

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@imay imay merged commit 8d6c66b into StarRocks:main May 14, 2024
46 checks passed
node pushed a commit to vivo/starrocks that referenced this pull request May 17, 2024
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.

ctas pk table fail
4 participants