Skip to content

Commit

Permalink
[hotfix] Fix spark test typo and missing test (apache#2714)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zouxxyy authored Jan 17, 2024
1 parent fb5f886 commit 97d1314
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.paimon.spark.sql

import org.apache.paimon.spark.procedure.CompactProcedureTestBase
package org.apache.paimon.spark.procedure

class CompactProcedureTest extends CompactProcedureTestBase {}
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.paimon.spark.sql
package org.apache.paimon.spark.procedure

import org.apache.paimon.spark.PaimonSparkTestBase
import org.apache.paimon.spark.analysis.NoSuchProcedureException

import org.assertj.core.api.Assertions.assertThatThrownBy

class ProcedureTest extends PaimonSparkTestBase {

test(s"test call unknown procedure") {
spark.sql(s"""
|CREATE TABLE T (id INT, name STRING, dt STRING)
|""".stripMargin)

assertThatThrownBy(() => spark.sql("CALL unknown_procedure(table => 'test.T')"))
.isInstanceOf(classOf[NoSuchProcedureException])
}

}
class ProcedureTest extends ProcedureTestBase {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.paimon.spark.procedure

class ProcedureTest extends ProcedureTestBase {}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.apache.spark.sql.catalyst.dsl.expressions._
import org.apache.spark.sql.catalyst.expressions.{Attribute, GetStructField, NamedExpression, ScalarSubquery}
import org.apache.spark.sql.catalyst.plans.logical.CTERelationRef

class PaimonOptimzationTest extends PaimonOptimzationTestBase {
class PaimonOptimizationTest extends PaimonOptimizationTestBase {

override def extractorExpression(
cteIndex: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package org.apache.paimon.spark.sql
import org.apache.spark.sql.catalyst.expressions.{Attribute, GetStructField, NamedExpression, ScalarSubquery}
import org.apache.spark.sql.catalyst.plans.logical.CTERelationRef

class PaimonOptimzationTest extends PaimonOptimzationTestBase {
class PaimonOptimizationTest extends PaimonOptimizationTestBase {

import org.apache.spark.sql.catalyst.dsl.expressions._

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.paimon.spark.procedure

class CompactProcedureTest extends CompactProcedureTestBase {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.paimon.spark.procedure

class ProcedureTest extends ProcedureTestBase {}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.apache.spark.sql.catalyst.dsl.expressions._
import org.apache.spark.sql.catalyst.expressions.{Attribute, GetStructField, NamedExpression, ScalarSubquery}
import org.apache.spark.sql.catalyst.plans.logical.CTERelationRef

class PaimonOptimzationTest extends PaimonOptimzationTestBase {
class PaimonOptimizationTest extends PaimonOptimizationTestBase {

override def extractorExpression(
cteIndex: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PaimonHiveTestBase extends PaimonSparkTestBase {

protected lazy val testHiveMetastore: TestHiveMetastore = new TestHiveMetastore

protected val paimonHiveCatalog: String = "paimon_hive"
protected val paimonHiveCatalogName: String = "paimon_hive"

protected val hiveDbName: String = "test_hive"

Expand All @@ -43,17 +43,16 @@ class PaimonHiveTestBase extends PaimonSparkTestBase {
.set("spark.sql.warehouse.dir", tempHiveDBDir.getCanonicalPath)
.set("spark.sql.catalogImplementation", "hive")
.set("spark.sql.catalog.spark_catalog", classOf[SparkGenericCatalog[_]].getName)
.set(s"spark.sql.catalog.$paimonHiveCatalog", classOf[SparkCatalog].getName)
.set(s"spark.sql.catalog.$paimonHiveCatalog.metastore", "hive")
.set(s"spark.sql.catalog.$paimonHiveCatalog.warehouse", tempHiveDBDir.getCanonicalPath)
.set(s"spark.sql.catalog.$paimonHiveCatalogName", classOf[SparkCatalog].getName)
.set(s"spark.sql.catalog.$paimonHiveCatalogName.metastore", "hive")
.set(s"spark.sql.catalog.$paimonHiveCatalogName.warehouse", tempHiveDBDir.getCanonicalPath)
}

override protected def beforeAll(): Unit = {
testHiveMetastore.start()
super.beforeAll()
spark.sql(s"USE spark_catalog")
spark.sql(s"CREATE DATABASE IF NOT EXISTS $hiveDbName")
spark.sql(s"USE $hiveDbName")
}

override protected def afterAll(): Unit = {
Expand All @@ -70,5 +69,6 @@ class PaimonHiveTestBase extends PaimonSparkTestBase {
/** Default is spark_catalog */
override protected def beforeEach(): Unit = {
spark.sql(s"USE spark_catalog")
spark.sql(s"USE $hiveDbName")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ class PaimonSparkTestBase extends QueryTest with SharedSparkSession with WithTab
super.beforeAll()
spark.sql(s"USE paimon")
spark.sql(s"CREATE DATABASE IF NOT EXISTS paimon.$dbName0")
spark.sql(s"USE paimon.$dbName0")
}

override protected def afterAll(): Unit = {
try {
spark.sql(s"USE paimon")
spark.sql(s"DROP TABLE IF EXISTS $dbName0.$tableName0")
spark.sql("USE default")
spark.sql(s"DROP DATABASE paimon.$dbName0 CASCADE")
} finally {
Expand All @@ -75,6 +75,7 @@ class PaimonSparkTestBase extends QueryTest with SharedSparkSession with WithTab
override protected def beforeEach(): Unit = {
super.beforeAll()
spark.sql(s"USE paimon")
spark.sql(s"USE paimon.$dbName0")
spark.sql(s"DROP TABLE IF EXISTS $tableName0")
}

Expand All @@ -92,8 +93,8 @@ class PaimonSparkTestBase extends QueryTest with SharedSparkSession with WithTab
val currentCatalog = spark.sessionState.catalogManager.currentCatalog.name()
val options = Catalogs.catalogOptions(currentCatalog, spark.sessionState.conf)
val catalogContext =
CatalogContext.create(Options.fromMap(options), spark.sessionState.newHadoopConf());
CatalogFactory.createCatalog(catalogContext);
CatalogContext.create(Options.fromMap(options), spark.sessionState.newHadoopConf())
CatalogFactory.createCatalog(catalogContext)
}

def loadTable(tableName: String): AbstractFileStoreTable = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.assertj.core.api.Assertions

import java.util

/** Test sort compact procedure. See [[CompactProcedure]]. */
/** Test compact procedure. See [[CompactProcedure]]. */
abstract class CompactProcedureTestBase extends PaimonSparkTestBase with StreamTest {

import testImplicits._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.paimon.spark.sql
package org.apache.paimon.spark.procedure

import org.apache.paimon.spark.PaimonSparkTestBase
import org.apache.paimon.spark.analysis.NoSuchProcedureException

import org.assertj.core.api.Assertions.assertThatThrownBy

class ProcedureTest extends PaimonSparkTestBase {
abstract class ProcedureTestBase extends PaimonSparkTestBase {

test(s"test call unknown procedure") {
spark.sql(s"""
Expand All @@ -32,5 +32,4 @@ class ProcedureTest extends PaimonSparkTestBase {
assertThatThrownBy(() => spark.sql("CALL unknown_procedure(table => 'test.T')"))
.isInstanceOf(classOf[NoSuchProcedureException])
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.junit.jupiter.api.Assertions
class DDLWithHiveCatalogTest extends PaimonHiveTestBase {

test("Paimon DDL with hive catalog: create database with location and comment") {
Seq("spark_catalog", paimonHiveCatalog).foreach {
Seq("spark_catalog", paimonHiveCatalogName).foreach {
catalogName =>
spark.sql(s"USE $catalogName")
withTempDir {
Expand Down Expand Up @@ -52,7 +52,7 @@ class DDLWithHiveCatalogTest extends PaimonHiveTestBase {
}

test("Paimon DDL with hive catalog: create database with props") {
Seq("spark_catalog", paimonHiveCatalog).foreach {
Seq("spark_catalog", paimonHiveCatalogName).foreach {
catalogName =>
spark.sql(s"USE $catalogName")
withDatabase("paimon_db") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DeleteFromTableTest extends PaimonSparkTestBase {
spark.sql("INSERT INTO T VALUES (1, 'a', '11'), (2, 'b', '22')")

assertThatThrownBy(() => spark.sql("DELETE FROM T WHERE name = 'a'"))
.isInstanceOf(classOf[UnsupportedOperationException]);
.isInstanceOf(classOf[UnsupportedOperationException])
}

CoreOptions.MergeEngine.values().foreach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ import org.apache.spark.sql.catalyst.plans.logical.{CTERelationDef, LogicalPlan,
import org.apache.spark.sql.catalyst.rules.RuleExecutor
import org.apache.spark.sql.functions._

abstract class PaimonOptimzationTestBase extends PaimonSparkTestBase {
import scala.collection.immutable

abstract class PaimonOptimizationTestBase extends PaimonSparkTestBase {

import org.apache.spark.sql.catalyst.dsl.expressions._
import org.apache.spark.sql.catalyst.dsl.plans._
import testImplicits._

private object Optimize extends RuleExecutor[LogicalPlan] {
val batches = Batch("MergePaimonScalarSubqueries", Once, MergePaimonScalarSubqueriers) :: Nil
val batches: immutable.Seq[Batch] =
Batch("MergePaimonScalarSubqueries", Once, MergePaimonScalarSubqueriers) :: Nil
}

test("Paimon Optimization: merge scalar subqueries") {
Expand Down

0 comments on commit 97d1314

Please sign in to comment.