-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[BugFix] Fix the bug that partition by range(str2date) does not check parameters #45838
Conversation
if (!PartitionFunctionChecker.checkStr2date(expr)) { | ||
throw new SemanticException("partition function check fail," + | ||
" only support str2date(VARCHAR str, VARCHAR format)"); | ||
} | ||
} | ||
} else { | ||
throw new AnalysisException("Unsupported expr:" + expr.toSql()); |
There was a problem hiding this comment.
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:
Missing null check for slotRef after calling AnalyzerUtils.getSlotRefFromFunctionCall(expr)
You can modify the code like this:
@@ -105,9 +108,20 @@ public void analyze(List<ColumnDef> columnDefs, Map<String, String> otherPropert
partitionType = ((CastExpr) expr).getTargetTypeDef().getType();
} else if (expr instanceof FunctionCallExpr) {
slotRef = AnalyzerUtils.getSlotRefFromFunctionCall(expr);
+
+ // Ensure slotRef is not null before proceeding
+ if (slotRef == null) {
+ throw new AnalysisException("Failed to obtain SlotRef from function call.");
+ }
+
Optional<ColumnDef> columnDef = columnDefs.stream()
.filter(c -> c.getName().equals(slotRef.getColumnName())).findFirst();
Preconditions.checkState(columnDef.isPresent());
slotRef.setType(columnDef.get().getType());
+
String functionName = ((FunctionCallExpr) expr).getFnName().getFunction().toLowerCase();
if (functionName.equals(FunctionSet.STR2DATE)) {
partitionType = Type.DATE;
+ if (!PartitionFunctionChecker.checkStr2date(expr)) {
+ throw new SemanticException("partition function check fail," +
+ " only support str2date(VARCHAR str, VARCHAR format)");
+ }
}
} else {
throw an AnalysisException("Unsupported expr:" + expr.toSql());
This change ensures that a null slotRef
(which could result from AnalyzerUtils.getSlotRefFromFunctionCall(expr)
returning null, for expressions that do not directly involve a column reference) will be caught and handled properly, preventing potential NullPointerExceptions later in the code when operations on slotRef
are attempted.
Signed-off-by: HangyuanLiu <460660596@qq.com>
b1807db
to
a83e28a
Compare
Quality Gate failedFailed conditions |
[FE Incremental Coverage Report]✅ pass : 67 / 80 (83.75%) file detail
|
[BE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
@Mergifyio backport branch-3.3 |
✅ Backports have been created
|
https://github.com/Mergifyio backport branch-3.2 |
✅ Backports have been created
|
Why I'm doing:
What I'm doing:
Fixes #issue
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: