Skip to content

Commit

Permalink
[KYUUBI #956] Fail to get table list if there is _ in schema's name
Browse files Browse the repository at this point in the history
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

985a73b [Baoqi Wu] [KYUUBI #956] add a unit test for this
cb11189 [Baoqi Wu] [KYUUBI #956] Fail to get table list if there is _ in schema's name

Authored-by: Baoqi Wu <wubaoqi@gmail.com>
Signed-off-by: Kent Yao <yao@apache.org>
(cherry picked from commit 484bb3c)
Signed-off-by: Kent Yao <yao@apache.org>
  • Loading branch information
Baoqi authored and yaooqinn committed Aug 20, 2021
1 parent 896cb84 commit d58f970
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
*/
Expand All @@ -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] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit d58f970

Please sign in to comment.