yabola commented on code in PR #7329:
URL: https://github.com/apache/kyuubi/pull/7329#discussion_r3227039106
##########
extensions/spark/kyuubi-spark-connector-hive/src/test/scala/org/apache/kyuubi/spark/connector/hive/command/DDLCommandTestUtils.scala:
##########
@@ -35,6 +35,8 @@ trait DDLCommandTestUtils extends KyuubiHiveTest {
// Name of the command as SQL statement, for instance "SHOW PARTITIONS"
protected def command: String
+ protected def catalogName: String = "hive"
Review Comment:
When running the tests, I had to change catalogName from a val to a def so
that the V1 and V2 suites can override it with different catalog names
(spark_catalog for V1 and hive for V2). Otherwise the overridden value never
takes effect and the catalog is always resolved to hive.
##########
extensions/spark/kyuubi-spark-connector-hive/src/test/scala/org/apache/kyuubi/spark/connector/hive/command/PartitionManagementSuite.scala:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.kyuubi.spark.connector.hive.command
+
+import java.io.File
+
+import org.apache.spark.sql.Row
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.analysis.{NoSuchPartitionsException,
PartitionsAlreadyExistException}
+import org.apache.spark.sql.connector.catalog.{Identifier,
SupportsPartitionManagement, TableCatalog}
+import org.apache.spark.unsafe.types.UTF8String
+
+import
org.apache.kyuubi.spark.connector.hive.command.DDLCommandTestUtils.{V1_COMMAND_VERSION,
V2_COMMAND_VERSION}
+
+trait PartitionManagementSuite extends DDLCommandTestUtils {
+ override protected def command: String = "PARTITION MANAGEMENT"
+
+ test("drop partition") {
+ withNamespaceAndTable("ns", "tbl") { t =>
+ sql(
+ s"""CREATE TABLE $t (id string, name string, year int, dt date)
+ |PARTITIONED BY (name, year, dt)""".stripMargin)
+ sql(s"ALTER TABLE $t ADD PARTITION (name='a', year=2023,
dt='2023-01-01')")
+ sql(s"ALTER TABLE $t DROP PARTITION (name='a', year=2023,
dt='2023-01-01')")
+ checkAnswer(
+ sql(s"SHOW PARTITIONS $t"),
+ Nil)
+ intercept[NoSuchPartitionsException] {
+ sql(s"ALTER TABLE $t DROP PARTITION (name='a', year=9999,
dt='9999-12-31')")
+ }
+ }
+ }
+
+ test("show partitions") {
+ withNamespaceAndTable("ns", "tbl") { t =>
+ sql(
+ s"""CREATE TABLE $t (id string, name string, year int, dt date)
+ |PARTITIONED BY (name, year, dt)""".stripMargin)
+ sql(s"ALTER TABLE $t ADD PARTITION (name='a', year=2023,
dt='2023-01-01')")
+ sql(s"ALTER TABLE $t ADD PARTITION (name='a', year=2023,
dt='2023-02-01')")
+ checkAnswer(
+ sql(s"SHOW PARTITIONS $t"),
+ Row("name=a/year=2023/dt=2023-01-01") ::
+ Row("name=a/year=2023/dt=2023-02-01") :: Nil)
+
+ checkAnswer(
+ sql(s"SHOW PARTITIONS $t PARTITION (name='a', year=2023,
dt='2023-01-01')"),
+ Row("name=a/year=2023/dt=2023-01-01") :: Nil)
+
+ checkAnswer(
+ sql(s"SHOW PARTITIONS $t PARTITION (name='a', year=2023)"),
+ Row("name=a/year=2023/dt=2023-01-01") ::
+ Row("name=a/year=2023/dt=2023-02-01") :: Nil)
+ }
+ }
+}
+
+class PartitionManagementV2Suite extends PartitionManagementSuite {
+ override protected def catalogVersion: String = "Hive V2"
+ override protected def commandVersion: String = V2_COMMAND_VERSION
+
+ test("create partition") {
+ withNamespaceAndTable("ns", "tbl") { t =>
+ sql(
+ s"""CREATE TABLE $t (id string, name string, year int, dt date)
+ |PARTITIONED BY (name, year, dt)""".stripMargin)
+ sql(s"ALTER TABLE $t ADD PARTITION (name='a', year=2023,
dt='2023-01-01')")
+ checkAnswer(
+ sql(s"SHOW PARTITIONS $t"),
+ Row("name=a/year=2023/dt=2023-01-01") :: Nil)
+ intercept[PartitionsAlreadyExistException] {
+ sql(s"ALTER TABLE $t ADD PARTITION (name='a', year=2023,
dt='2023-01-01')")
+ }
+ sql(s"INSERT INTO $t PARTITION (name=null, year=null, dt=null) VALUES
('1')")
+ checkAnswer(
+ sql(s"SHOW PARTITIONS $t"),
+ Row("name=a/year=2023/dt=2023-01-01") ::
+ Row("name=null/year=null/dt=null") :: Nil)
Review Comment:
I made a small behavior change here: for null partition values, we now
display null instead of __HIVE_DEFAULT_PARTITION__. This is consistent with
Iceberg's behavior, but differs from DataSource V1. Please take a look and let
me know if this is acceptable.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]