This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-2.0-alpha
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 08f4cf03e8fd948e6d1bf8097e4c6417ba6645b6
Author: lihangyu <[email protected]>
AuthorDate: Sun Apr 16 18:13:45 2023 +0800

    [regression-test](prepared statement) Fix connection error when test 
framework used lower jdbc version (#18665)
---
 .../java/org/apache/doris/qe/ConnectProcessor.java |  6 ++++
 .../test_compaction_uniq_keys_row_store.groovy     | 25 ++++++++++----
 .../suites/point_query_p0/test_point_query.groovy  | 40 +++++++++++++++++-----
 3 files changed, 55 insertions(+), 16 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java
index 2d8d4da210..12b4b289da 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java
@@ -212,6 +212,12 @@ public class ConnectProcessor {
         packetBuf.getInt();
         LOG.debug("execute prepared statement {}", stmtId);
         PrepareStmtContext prepareCtx = 
ctx.getPreparedStmt(String.valueOf(stmtId));
+        if (prepareCtx == null) {
+            LOG.debug("No such statement in context, stmtId:{}", stmtId);
+            ctx.getState().setError(ErrorCode.ERR_UNKNOWN_COM_ERROR,
+                    "msg: Not supported such prepared statement");
+            return;
+        }
         int paramCount = prepareCtx.stmt.getParmCount();
         // null bitmap
         byte[] nullbitmapData = new byte[(paramCount + 7) / 8];
diff --git 
a/regression-test/suites/compaction/test_compaction_uniq_keys_row_store.groovy 
b/regression-test/suites/compaction/test_compaction_uniq_keys_row_store.groovy
index ff79af35f4..06499b7986 100644
--- 
a/regression-test/suites/compaction/test_compaction_uniq_keys_row_store.groovy
+++ 
b/regression-test/suites/compaction/test_compaction_uniq_keys_row_store.groovy
@@ -19,7 +19,10 @@ import org.codehaus.groovy.runtime.IOGroovyMethods
 
 
 suite("test_compaction_uniq_keys_row_store") {
-    def tableName = "compaction_uniq_keys_row_store_regression_test"
+    def realDb = "regression_test_serving_p0"
+    def tableName = realDb + ".compaction_uniq_keys_row_store_regression_test"
+    sql "CREATE DATABASE IF NOT EXISTS ${realDb}"
+
     def setPrepareStmtArgs = {stmt, user_id, date, datev2, datetimev2_1, 
datetimev2_2, city, age, sex ->
         java.text.SimpleDateFormat formater = new 
java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS");
         stmt.setInt(1, user_id)
@@ -73,7 +76,20 @@ suite("test_compaction_uniq_keys_row_store") {
         def checkValue = { ->
             def user = context.config.jdbcUser
             def password = context.config.jdbcPassword
-            def url = context.config.jdbcUrl + "&useServerPrepStmts=true"
+            // Parse url
+            String jdbcUrl = context.config.jdbcUrl
+            String urlWithoutSchema = jdbcUrl.substring(jdbcUrl.indexOf("://") 
+ 3)
+            def sql_ip = urlWithoutSchema.substring(0, 
urlWithoutSchema.indexOf(":"))
+            def sql_port
+            if (urlWithoutSchema.indexOf("/") >= 0) {
+                // e.g: jdbc:mysql://locahost:8080/?a=b
+                sql_port = 
urlWithoutSchema.substring(urlWithoutSchema.indexOf(":") + 1, 
urlWithoutSchema.indexOf("/"))
+            } else {
+                // e.g: jdbc:mysql://locahost:8080
+                sql_port = 
urlWithoutSchema.substring(urlWithoutSchema.indexOf(":") + 1)
+            }
+            // set server side prepared statment url
+            def url="jdbc:mysql://" + sql_ip + ":" + sql_port + "/" + realDb + 
"?&useServerPrepStmts=true"
             def result1 = connect(user=user, password=password, url=url) {
                 def stmt = prepareStatement """ SELECT * FROM ${tableName} t 
where user_id = ? and date = ? and datev2 = ? and datetimev2_1 = ? and 
datetimev2_2 = ? and city = ? and age = ? and sex = ?; """
                 setPrepareStmtArgs stmt, 1, '2017-10-01', '2017-10-01', 
'2017-10-01 11:11:11.21', '2017-10-01 11:11:11.11', 'Beijing', 10, 1
@@ -97,10 +113,7 @@ suite("test_compaction_uniq_keys_row_store") {
 
         def user = context.config.jdbcUser
         def password = context.config.jdbcPassword
-        def url = context.config.jdbcUrl + "&useServerPrepStmts=true"
         def tablets = null
-        def result1 = connect(user=user, password=password, url=url) {
-
         sql """ DROP TABLE IF EXISTS ${tableName} """
         sql """
             CREATE TABLE IF NOT EXISTS ${tableName} (
@@ -157,11 +170,9 @@ suite("test_compaction_uniq_keys_row_store") {
             """
         
//TabletId,ReplicaIdBackendId,SchemaHash,Version,LstSuccessVersion,LstFailedVersion,LstFailedTime,LocalDataSize,RemoteDataSize,RowCount,State,LstConsistencyCheckTime,CheckVersion,VersionCount,PathHash,MetaUrl,CompactionStatus
         tablets = sql """ show tablets from ${tableName}; """
-        }
 
         checkValue()
 
-
         // trigger compactions for all tablets in ${tableName}
         for (String[] tablet in tablets) {
             String tablet_id = tablet[0]
diff --git a/regression-test/suites/point_query_p0/test_point_query.groovy 
b/regression-test/suites/point_query_p0/test_point_query.groovy
index d69527dff1..96db424a34 100644
--- a/regression-test/suites/point_query_p0/test_point_query.groovy
+++ b/regression-test/suites/point_query_p0/test_point_query.groovy
@@ -18,10 +18,26 @@
 import java.math.BigDecimal;
 
 suite("test_point_query") {
-    def tableName = "tbl_point_query"
     def user = context.config.jdbcUser
     def password = context.config.jdbcPassword
-    def url = context.config.jdbcUrl + "&useServerPrepStmts=true"
+    def realDb = "regression_test_serving_p0"
+    def tableName = realDb + ".tbl_point_query"
+    sql "CREATE DATABASE IF NOT EXISTS ${realDb}"
+
+    // Parse url
+    String jdbcUrl = context.config.jdbcUrl
+    String urlWithoutSchema = jdbcUrl.substring(jdbcUrl.indexOf("://") + 3)
+    def sql_ip = urlWithoutSchema.substring(0, urlWithoutSchema.indexOf(":"))
+    def sql_port
+    if (urlWithoutSchema.indexOf("/") >= 0) {
+        // e.g: jdbc:mysql://locahost:8080/?a=b
+        sql_port = urlWithoutSchema.substring(urlWithoutSchema.indexOf(":") + 
1, urlWithoutSchema.indexOf("/"))
+    } else {
+        // e.g: jdbc:mysql://locahost:8080
+        sql_port = urlWithoutSchema.substring(urlWithoutSchema.indexOf(":") + 
1)
+    }
+    // set server side prepared statment url
+    def url="jdbc:mysql://" + sql_ip + ":" + sql_port + "/" + realDb + 
"?&useServerPrepStmts=true"
 
     def generateString = {len ->
         def str = ""
@@ -31,8 +47,6 @@ suite("test_point_query") {
         return str
     }
 
-    // def url = context.config.jdbcUrl
-    def result1 = connect(user=user, password=password, url=url) {
     sql """DROP TABLE IF EXISTS ${tableName}"""
     test {
         // abnormal case
@@ -82,6 +96,14 @@ suite("test_point_query") {
       sql """ INSERT INTO ${tableName} VALUES(252, 120939.11130, 
"${generateString(252)}", "laooq", "2030-01-02", "2020-01-01 12:36:38", 252, 
"7022-01-01 11:30:38") """
       sql """ INSERT INTO ${tableName} VALUES(298, 120939.11130, 
"${generateString(298)}", "laooq", "2030-01-02", "2020-01-01 12:36:38", 298, 
"7022-01-01 11:30:38") """
 
+    def nprep_sql = {sql_str->
+        def url_without_prep ="jdbc:mysql://" + sql_ip + ":" + sql_port + "/" 
+ realDb
+        connect(user=user, password=password, url=url_without_prep) {
+            sql sql_str
+        }
+    }
+    // def url = context.config.jdbcUrl
+    def result1 = connect(user=user, password=password, url=url) {
       def stmt = prepareStatement "select * from ${tableName} where k1 = ? and 
k2 = ? and k3 = ?"
       assertEquals(stmt.class, com.mysql.cj.jdbc.ServerPreparedStatement);
       stmt.setInt(1, 1231)
@@ -125,26 +147,26 @@ suite("test_point_query") {
       qe_point_select stmt_fn
       qe_point_select stmt_fn
 
-      sql """
+      nprep_sql """
           ALTER table ${tableName} ADD COLUMN new_column0 INT default "0";
           """
       sleep(1);
-      sql """ INSERT INTO ${tableName} VALUES(1235, 120939.11130, "a    ddd", 
"laooq", "2030-01-02", "2020-01-01 12:36:38", 22.822, "7022-01-01 11:30:38", 
123) """
+      nprep_sql """ INSERT INTO ${tableName} VALUES(1235, 120939.11130, "a    
ddd", "laooq", "2030-01-02", "2020-01-01 12:36:38", 22.822, "7022-01-01 
11:30:38", 123) """
       stmt.setBigDecimal(1, new BigDecimal("120939.11130"))
       stmt.setString(2, "a    ddd")
       qe_point_select stmt
       qe_point_select stmt
       // invalidate cache
-      sql """ INSERT INTO ${tableName} VALUES(1235, 120939.11130, "a    ddd", 
"xxxxxx", "2030-01-02", "2020-01-01 12:36:38", 22.822, "7022-01-01 11:30:38", 
123) """
+      nprep_sql """ INSERT INTO ${tableName} VALUES(1235, 120939.11130, "a    
ddd", "xxxxxx", "2030-01-02", "2020-01-01 12:36:38", 22.822, "7022-01-01 
11:30:38", 123) """
       qe_point_select stmt
       qe_point_select stmt
       qe_point_select stmt
-      sql """
+      nprep_sql """
           ALTER table ${tableName} ADD COLUMN new_column1 INT default "0";
           """
       qe_point_select stmt
       qe_point_select stmt
-      sql """
+      nprep_sql """
           ALTER table ${tableName} DROP COLUMN new_column1;
           """
       qe_point_select stmt


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to