This is an automated email from the ASF dual-hosted git repository.
huajianlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 40c6c61dbbe [fix](sql cache) fix prepare statement with sql cache
throw NullPointerException (#45640)
40c6c61dbbe is described below
commit 40c6c61dbbe67b3c11095427b3c5e471dfee0042
Author: 924060929 <[email protected]>
AuthorDate: Thu Dec 19 17:39:25 2024 +0800
[fix](sql cache) fix prepare statement with sql cache throw
NullPointerException (#45640)
fix prepare statement with sql cache throw NullPointerException:
```shell
java.lang.NullPointerException: Cannot read field "originStmt" because the
return value of "org.apache.doris.analysis.StatementBase.getOrigStmt()" is null
```
---
.../java/org/apache/doris/qe/StmtExecutor.java | 3 +-
.../cache/prepare_stmt_with_sql_cache.groovy | 57 ++++++++++++++++++++++
2 files changed, 59 insertions(+), 1 deletion(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
index 05df53ed679..5c2566225fe 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
@@ -1894,7 +1894,8 @@ public class StmtExecutor {
// TODO support arrow flight sql
// NOTE: If you want to add another condition about SessionVariable,
please consider whether
// add to CacheAnalyzer.commonCacheCondition
- if (channel != null && !isOutfileQuery &&
CacheAnalyzer.canUseCache(context.getSessionVariable())) {
+ if (channel != null && !isOutfileQuery &&
CacheAnalyzer.canUseCache(context.getSessionVariable())
+ && parsedStmt.getOrigStmt() != null &&
parsedStmt.getOrigStmt().originStmt != null) {
if (queryStmt instanceof QueryStmt || queryStmt instanceof
LogicalPlanAdapter) {
handleCacheStmt(cacheAnalyzer, channel);
LOG.info("Query {} finished",
DebugUtil.printId(context.queryId));
diff --git
a/regression-test/suites/nereids_p0/cache/prepare_stmt_with_sql_cache.groovy
b/regression-test/suites/nereids_p0/cache/prepare_stmt_with_sql_cache.groovy
new file mode 100644
index 00000000000..7819a6ca09d
--- /dev/null
+++ b/regression-test/suites/nereids_p0/cache/prepare_stmt_with_sql_cache.groovy
@@ -0,0 +1,57 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+import com.mysql.cj.ServerPreparedQuery
+import com.mysql.cj.jdbc.ConnectionImpl
+import com.mysql.cj.jdbc.JdbcStatement
+import com.mysql.cj.jdbc.ServerPreparedStatement
+import com.mysql.cj.jdbc.StatementImpl
+import org.apache.doris.regression.util.JdbcUtils
+
+import java.lang.reflect.Field
+import java.sql.PreparedStatement
+import java.sql.ResultSet
+import java.util.concurrent.CopyOnWriteArrayList
+
+suite("prepare_stmt_with_sql_cache") {
+
+ multi_sql """
+ drop table if exists test_prepare_stmt_with_sql_cache;
+ create table test_prepare_stmt_with_sql_cache(id int)
+ distributed by hash(id)
+ properties('replication_num'='1');
+
+ insert into test_prepare_stmt_with_sql_cache select * from
numbers('number'='100');
+ """
+
+ def db = (sql "select database()")[0][0].toString()
+
+ def url = getServerPrepareJdbcUrl(context.config.jdbcUrl, db)
+
+ connect(context.config.jdbcUser, context.config.jdbcPassword, url) {
+ sql "set enable_sql_cache=true"
+ for (def i in 0..<10) {
+ try (PreparedStatement pstmt = prepareStatement("select * from
test_prepare_stmt_with_sql_cache where id=?")) {
+ pstmt.setInt(1, i)
+ try (ResultSet rs = pstmt.executeQuery()) {
+ def result = JdbcUtils.toList(rs).v1
+ logger.info("result: {}", result)
+ }
+ }
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]