You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/11/14 22:29:51 UTC

[GitHub] [spark] janekdb commented on a change in pull request #30377: [SPARK-33453][SQL][TESTS] Unify v1 and v2 SHOW PARTITIONS tests

janekdb commented on a change in pull request #30377:
URL: https://github.com/apache/spark/pull/30377#discussion_r523471140



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/command/v1/ShowPartitionsSuite.scala
##########
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.command.v1
+
+import org.apache.spark.sql.{AnalysisException, Row, SaveMode}
+import org.apache.spark.sql.catalyst.analysis.NoSuchTableException
+import org.apache.spark.sql.connector.catalog.CatalogManager
+import org.apache.spark.sql.execution.command
+import org.apache.spark.sql.test.SharedSparkSession
+
+trait ShowPartitionsSuiteBase extends command.ShowPartitionsSuiteBase {
+  override def version: String = "V1"
+  override def catalog: String = CatalogManager.SESSION_CATALOG_NAME
+  override def defaultNamespace: Seq[String] = Seq("default")
+  override def defaultUsing: String = "USING parquet"
+
+  protected def createDateTable(table: String): Unit = {
+    sql(s"""
+      |CREATE TABLE $table (price int, qty int, year int, month int)
+      |$defaultUsing
+      |partitioned by (year, month)""".stripMargin)
+  }
+
+  protected def fillDateTable(table: String): Unit = {
+    sql(s"INSERT INTO $table PARTITION(year = 2015, month = 1) SELECT 1, 1")
+    sql(s"INSERT INTO $table PARTITION(year = 2015, month = 2) SELECT 2, 2")
+    sql(s"INSERT INTO $table PARTITION(year = 2016, month = 2) SELECT 3, 3")
+    sql(s"INSERT INTO $table PARTITION(year = 2016, month = 3) SELECT 3, 3")
+  }
+
+  protected def createWideTable(table: String): Unit = {
+    sql(s"""
+      |CREATE TABLE $table (
+      |  price int, qty int,
+      |  year int, month int, hour int, minute int, sec int, extra int)
+      |$defaultUsing
+      |PARTITIONED BY (year, month, hour, minute, sec, extra)""".stripMargin)
+  }
+
+  protected def fillWideTable(table: String): Unit = {
+    sql(s"""
+      |INSERT INTO $table
+      |PARTITION(year = 2016, month = 3, hour = 10, minute = 10, sec = 10, extra = 1) SELECT 3, 3
+      """.stripMargin)
+    sql(s"""
+      |INSERT INTO $table
+      |PARTITION(year = 2016, month = 4, hour = 10, minute = 10, sec = 10, extra = 1) SELECT 3, 3
+      """.stripMargin)
+  }
+
+  test("show everything") {
+    val table = "dateTable"
+    withTable(table) {
+      createDateTable(table)
+      fillDateTable(table)
+      checkAnswer(
+        sql(s"show partitions $table"),
+        Row("year=2015/month=1") ::
+          Row("year=2015/month=2") ::
+          Row("year=2016/month=2") ::
+          Row("year=2016/month=3") :: Nil)
+
+      checkAnswer(
+        sql(s"show partitions default.$table"),
+        Row("year=2015/month=1") ::
+          Row("year=2015/month=2") ::
+          Row("year=2016/month=2") ::
+          Row("year=2016/month=3") :: Nil)
+    }
+  }
+
+  test("filter by partitions") {
+    val table = "dateTable"
+    withTable(table) {
+      createDateTable(table)
+      fillDateTable(table)
+      checkAnswer(
+        sql(s"show partitions default.$table PARTITION(year=2015)"),
+        Row("year=2015/month=1") ::
+          Row("year=2015/month=2") :: Nil)
+      checkAnswer(
+        sql(s"show partitions default.$table PARTITION(year=2015, month=1)"),
+        Row("year=2015/month=1") :: Nil)
+      checkAnswer(
+        sql(s"show partitions default.$table PARTITION(month=2)"),
+        Row("year=2015/month=2") ::
+          Row("year=2016/month=2") :: Nil)
+    }
+  }
+
+  test("show everything more than 5 part keys") {
+    val table = "wideTable"
+    withTable(table) {
+      createWideTable(table)
+      fillWideTable(table)
+      checkAnswer(
+        sql(s"show partitions $table"),
+        Row("year=2016/month=3/hour=10/minute=10/sec=10/extra=1") ::
+          Row("year=2016/month=4/hour=10/minute=10/sec=10/extra=1") :: Nil)
+    }
+  }
+
+  test("non-partitioning columns") {
+    val table = "dateTable"
+    withTable(table) {
+      createDateTable(table)
+      fillDateTable(table)
+      val errMsg = intercept[AnalysisException] {
+        sql(s"SHOW PARTITIONS $table PARTITION(abcd=2015, xyz=1)")
+      }.getMessage
+      assert(errMsg.contains("Non-partitioning column(s) [abcd, xyz] are specified"))
+    }
+  }
+
+  test("show partitions of not partitioned table") {

Review comment:
       "non-partitioned" sounds a bit more natural.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org