Skip to content

Commit

Permalink
[spark] Support DeleteFromPaimonTableCommand for Spark 3.2 (apache#2947)
Browse files Browse the repository at this point in the history
  • Loading branch information
choucmei authored Mar 13, 2024
1 parent f7a4c81 commit d463b1d
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.commands

import org.apache.paimon.spark.SparkTable

import org.apache.spark.sql.catalyst.expressions.Expression
import org.apache.spark.sql.catalyst.plans.logical.DeleteFromTable

case class DeleteFromPaimonTableCommand(v2Table: SparkTable, delete: DeleteFromTable)
extends DeleteFromPaimonTableCommandBase {
override def condition(): Expression = delete.condition.orNull
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.commands

import org.apache.paimon.spark.SparkTable

import org.apache.spark.sql.catalyst.expressions.Expression
import org.apache.spark.sql.catalyst.plans.logical.DeleteFromTable

case class DeleteFromPaimonTableCommand(v2Table: SparkTable, delete: DeleteFromTable)
extends DeleteFromPaimonTableCommandBase {
override def condition(): Expression = delete.condition.orNull
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.sql

class DeleteFromTableTest extends DeleteFromTableTestBase {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.sql

class DeleteFromTableTest extends DeleteFromTableTestBase {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.sql

class DeleteFromTableTest extends DeleteFromTableTestBase {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.sql

class DeleteFromTableTest extends DeleteFromTableTestBase {}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.apache.paimon.types.RowKind

import org.apache.spark.sql.{Row, SparkSession}
import org.apache.spark.sql.Utils.createDataset
import org.apache.spark.sql.catalyst.expressions.Expression
import org.apache.spark.sql.catalyst.expressions.Literal.TrueLiteral
import org.apache.spark.sql.catalyst.plans.logical.{DeleteFromTable, Filter}
import org.apache.spark.sql.functions.lit
Expand All @@ -37,14 +38,13 @@ import java.util.{Collections, UUID}

import scala.util.control.NonFatal

case class DeleteFromPaimonTableCommand(v2Table: SparkTable, delete: DeleteFromTable)
extends PaimonLeafRunnableCommand
with PaimonCommand {

trait DeleteFromPaimonTableCommandBase extends PaimonLeafRunnableCommand with PaimonCommand {
self: DeleteFromPaimonTableCommand =>
override def table: FileStoreTable = v2Table.getTable.asInstanceOf[FileStoreTable]

private val relation = delete.table
private val condition = delete.condition

def condition(): Expression

private lazy val (deletePredicate, forceDeleteByRows) =
if (condition == null || condition == TrueLiteral) {
Expand Down Expand Up @@ -87,3 +87,8 @@ case class DeleteFromPaimonTableCommand(v2Table: SparkTable, delete: DeleteFromT
WriteIntoPaimonTable(table, InsertInto, df, new Options()).run(sparkSession)
}
}

case class DeleteFromPaimonTableCommand(v2Table: SparkTable, delete: DeleteFromTable)
extends DeleteFromPaimonTableCommandBase {
override def condition(): Expression = delete.condition
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.apache.paimon.spark.catalyst.analysis.Delete

import org.assertj.core.api.Assertions.{assertThat, assertThatThrownBy}

class DeleteFromTableTest extends PaimonSparkTestBase {
abstract class DeleteFromTableTestBase extends PaimonSparkTestBase {

test(s"test delete from append only table") {
spark.sql(s"""
Expand Down Expand Up @@ -184,3 +184,5 @@ class DeleteFromTableTest extends PaimonSparkTestBase {
assertThat(rows4.toString).isEqualTo("[]")
}
}

class DeleteFromTableTest extends DeleteFromTableTestBase {}

0 comments on commit d463b1d

Please sign in to comment.