You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ya...@apache.org on 2021/08/20 16:18:57 UTC

[incubator-kyuubi] branch branch-1.3 updated: [KYUUBI #956] Fail to get table list if there is _ in schema's name

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

yao pushed a commit to branch branch-1.3
in repository https://gitbox.apache.org/repos/asf/incubator-kyuubi.git


The following commit(s) were added to refs/heads/branch-1.3 by this push:
     new d58f970  [KYUUBI #956] Fail to get table list if there is _ in schema's name
d58f970 is described below

commit d58f970aec227a7d4f572b76ac2fe72e0e9dd1ea
Author: Baoqi Wu <wu...@gmail.com>
AuthorDate: Sat Aug 21 00:17:54 2021 +0800

    [KYUUBI #956] Fail to get table list if there is _ in schema's name
    
    Just write some basic tests out in other projects.
    
    Since this toJavaRegex is not a static function, which is hard to write unit test if don't move it out as  as static function in object.  (But in that case, the change may be too large for this).
    
    ### _How was this patch tested?_
    - [x] Add some test cases that check the changes thoroughly including negative and positive cases if possible
    
    - [ ] Add screenshots for manual tests if appropriate
    
    - [x] [Run test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request
    
    Closes #964 from Baoqi/bwu_fix_956.
    
    Closes #956
    
    985a73b5 [Baoqi Wu] [KYUUBI #956] add a unit test for this
    cb111893 [Baoqi Wu] [KYUUBI #956] Fail to get table list if there is _ in schema's name
    
    Authored-by: Baoqi Wu <wu...@gmail.com>
    Signed-off-by: Kent Yao <ya...@apache.org>
    (cherry picked from commit 484bb3c6bda1eee6f0a10208de8df9b5989b32ea)
    Signed-off-by: Kent Yao <ya...@apache.org>
---
 .../engine/spark/operation/SparkOperation.scala      | 20 ++++++--------------
 .../org/apache/kyuubi/operation/BasicJDBCTests.scala |  2 ++
 2 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/SparkOperation.scala b/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/SparkOperation.scala
index 646afe6..67d1ecd 100644
--- a/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/SparkOperation.scala
+++ b/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/SparkOperation.scala
@@ -18,7 +18,6 @@
 package org.apache.kyuubi.engine.spark.operation
 
 import java.time.ZoneId
-import java.util.regex.Pattern
 
 import org.apache.commons.lang3.StringUtils
 import org.apache.hive.service.rpc.thrift.{TRowSet, TTableSchema}
@@ -62,6 +61,8 @@ abstract class SparkOperation(spark: SparkSession, opType: OperationType, sessio
    *
    * Underscores (_) are converted to '.' and percent signs (%) are converted to '.*'.
    *
+   * (referred to Spark's implementation: convertPattern function in file MetadataOperation.java)
+   *
    * @param input the SQL pattern to convert
    * @return the equivalent Java regular expression of the pattern
    */
@@ -71,19 +72,10 @@ abstract class SparkOperation(spark: SparkSession, opType: OperationType, sessio
     } else {
       input
     }
-    val in = res.toIterator
-    val out = new StringBuilder()
-
-    while (in.hasNext) {
-      in.next match {
-        case c if c == '\\' && in.hasNext => Pattern.quote(Character.toString(in.next()))
-        case c if c == '\\' && !in.hasNext => Pattern.quote(Character.toString(c))
-        case '_' => out ++= "."
-        case '%' => out ++= ".*"
-        case c => out ++= Character.toString(c)
-      }
-    }
-    out.result()
+    val wStr = ".*"
+    res
+      .replaceAll("([^\\\\])%", "$1" + wStr).replaceAll("\\\\%", "%").replaceAll("^%", wStr)
+      .replaceAll("([^\\\\])_", "$1.").replaceAll("\\\\_", "_").replaceAll("^_", ".")
   }
 
   protected def onError(cancel: Boolean = false): PartialFunction[Throwable, Unit] = {
diff --git a/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/BasicJDBCTests.scala b/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/BasicJDBCTests.scala
index 07ff751..c05078f 100644
--- a/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/BasicJDBCTests.scala
+++ b/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/BasicJDBCTests.scala
@@ -53,6 +53,8 @@ trait BasicJDBCTests extends JDBCTestUtils {
 
       checkGetSchemas(metaData.getSchemas(catalog, "db1"), Seq("db1"), catalog)
       checkGetSchemas(metaData.getSchemas(catalog, "db_not_exist"), Seq.empty, catalog)
+
+      checkGetSchemas(metaData.getSchemas(catalog, "global\\_temp"), Seq("global_temp"), catalog)
     }
   }