[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 <wubaoqi@gmail.com>
Signed-off-by: Kent Yao <yao@apache.org>
(cherry picked from commit 484bb3c6bd)
Signed-off-by: Kent Yao <yao@apache.org>
This commit is contained in:
parent
896cb8430c
commit
d58f970aec
@ -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] = {
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user