|
15 | 15 | * limitations under the License.
|
16 | 16 | */
|
17 | 17 |
|
18 |
| -package org.apache.spark.sql.execution.command |
| 18 | +package org.apache.spark.sql.execution |
19 | 19 |
|
20 | 20 | import org.apache.spark.sql.catalyst.analysis.{AnalysisTest, UnresolvedNamespace}
|
21 |
| -import org.apache.spark.sql.catalyst.parser.CatalystSqlParser.parsePlan |
22 |
| -import org.apache.spark.sql.catalyst.plans.logical.ShowNamespaces |
| 21 | +import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan |
| 22 | +import org.apache.spark.sql.execution.command.ShowNamespacesCommand |
23 | 23 | import org.apache.spark.sql.test.SharedSparkSession
|
24 | 24 |
|
25 | 25 | class ShowNamespacesParserSuite extends AnalysisTest with SharedSparkSession {
|
| 26 | + |
| 27 | + private lazy val parser = new SparkSqlParser() |
| 28 | + |
26 | 29 | private val keywords = Seq("NAMESPACES", "DATABASES", "SCHEMAS")
|
27 | 30 |
|
| 31 | + private def assertEqual(sqlCommand: String, plan: LogicalPlan): Unit = { |
| 32 | + comparePlans(parser.parsePlan(sqlCommand), plan) |
| 33 | + } |
| 34 | + |
28 | 35 | test("show namespaces in the current catalog") {
|
29 | 36 | keywords.foreach { keyword =>
|
30 |
| - comparePlans( |
31 |
| - parsePlan(s"SHOW $keyword"), |
32 |
| - ShowNamespaces(UnresolvedNamespace(Seq.empty[String]), None)) |
| 37 | + assertEqual( |
| 38 | + s"SHOW $keyword", |
| 39 | + ShowNamespacesCommand(UnresolvedNamespace(Seq.empty[String]), None)) |
33 | 40 | }
|
34 | 41 | }
|
35 | 42 |
|
36 | 43 | test("show namespaces with a pattern") {
|
37 | 44 | keywords.foreach { keyword =>
|
38 |
| - comparePlans( |
39 |
| - parsePlan(s"SHOW $keyword LIKE 'defau*'"), |
40 |
| - ShowNamespaces(UnresolvedNamespace(Seq.empty[String]), Some("defau*"))) |
| 45 | + assertEqual( |
| 46 | + s"SHOW $keyword LIKE 'defau*'", |
| 47 | + ShowNamespacesCommand(UnresolvedNamespace(Seq.empty[String]), Some("defau*"))) |
41 | 48 | // LIKE can be omitted.
|
42 |
| - comparePlans( |
43 |
| - parsePlan(s"SHOW $keyword 'defau*'"), |
44 |
| - ShowNamespaces(UnresolvedNamespace(Seq.empty[String]), Some("defau*"))) |
| 49 | + assertEqual( |
| 50 | + s"SHOW $keyword 'defau*'", |
| 51 | + ShowNamespacesCommand(UnresolvedNamespace(Seq.empty[String]), Some("defau*"))) |
45 | 52 | }
|
46 | 53 | }
|
47 | 54 |
|
48 | 55 | test("show namespaces in/from a namespace") {
|
49 | 56 | keywords.foreach { keyword =>
|
50 |
| - comparePlans( |
51 |
| - parsePlan(s"SHOW $keyword FROM testcat.ns1.ns2"), |
52 |
| - ShowNamespaces(UnresolvedNamespace(Seq("testcat", "ns1", "ns2")), None)) |
53 |
| - comparePlans( |
54 |
| - parsePlan(s"SHOW $keyword IN testcat.ns1.ns2"), |
55 |
| - ShowNamespaces(UnresolvedNamespace(Seq("testcat", "ns1", "ns2")), None)) |
| 57 | + assertEqual( |
| 58 | + s"SHOW $keyword FROM testcat.ns1.ns2", |
| 59 | + ShowNamespacesCommand(UnresolvedNamespace(Seq("testcat", "ns1", "ns2")), None)) |
| 60 | + assertEqual( |
| 61 | + s"SHOW $keyword IN testcat.ns1.ns2", |
| 62 | + ShowNamespacesCommand(UnresolvedNamespace(Seq("testcat", "ns1", "ns2")), None)) |
56 | 63 | }
|
57 | 64 | }
|
58 | 65 |
|
59 | 66 | test("namespaces by a pattern from another namespace") {
|
60 | 67 | keywords.foreach { keyword =>
|
61 |
| - comparePlans( |
62 |
| - parsePlan(s"SHOW $keyword IN testcat.ns1 LIKE '*pattern*'"), |
63 |
| - ShowNamespaces(UnresolvedNamespace(Seq("testcat", "ns1")), Some("*pattern*"))) |
| 68 | + assertEqual( |
| 69 | + s"SHOW $keyword IN testcat.ns1 LIKE '*pattern*'", |
| 70 | + ShowNamespacesCommand(UnresolvedNamespace(Seq("testcat", "ns1")), Some("*pattern*"))) |
64 | 71 | }
|
65 | 72 | }
|
66 | 73 | }
|
0 commit comments