-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Kernel] Add
Snapshot::getPartitionColumnNames
public API (#3916)
#### Which Delta project/connector is this regarding? - [ ] Spark - [ ] Standalone - [ ] Flink - [X] Kernel - [ ] Other (fill in here) ## Description Add new `Snapshot::getPartitionColumnNames` public API ## How was this patch tested? Simple UTs. ## Does this PR introduce _any_ user-facing changes? Yes.
- Loading branch information
1 parent
8ef5efc
commit 6345a88
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
kernel/kernel-defaults/src/test/scala/io/delta/kernel/defaults/SnapshotSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (2024) The Delta Lake Project Authors. | ||
* | ||
* Licensed 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 io.delta.kernel.defaults | ||
|
||
import io.delta.kernel.{Operation, Table} | ||
import io.delta.kernel.defaults.utils.TestUtils | ||
import io.delta.kernel.types.{IntegerType, StructField, StructType} | ||
import io.delta.kernel.utils.CloseableIterable | ||
import org.scalatest.funsuite.AnyFunSuite | ||
|
||
import scala.collection.JavaConverters._ | ||
|
||
class SnapshotSuite extends AnyFunSuite with TestUtils { | ||
|
||
Seq( | ||
Seq("part1"), // simple case | ||
Seq("part1", "part2", "part3"), // multiple partition columns | ||
Seq(), // non-partitioned | ||
Seq("PART1", "part2") // case-sensitive | ||
).foreach { partCols => | ||
test(s"Snapshot getPartitionColumnNames - partCols=$partCols") { | ||
withTempDir { dir => | ||
// Step 1: Create a table with the given partition columns | ||
val table = Table.forPath(defaultEngine, dir.getCanonicalPath) | ||
|
||
val columns = (partCols ++ Seq("col1", "col2")).map { colName => | ||
new StructField(colName, IntegerType.INTEGER, true /* nullable */) | ||
} | ||
|
||
val schema = new StructType(columns.asJava) | ||
|
||
var txnBuilder = table | ||
.createTransactionBuilder(defaultEngine, "engineInfo", Operation.CREATE_TABLE) | ||
.withSchema(defaultEngine, schema) | ||
|
||
if (partCols.nonEmpty) { | ||
txnBuilder = txnBuilder.withPartitionColumns(defaultEngine, partCols.asJava) | ||
} | ||
|
||
txnBuilder.build(defaultEngine).commit(defaultEngine, CloseableIterable.emptyIterable()) | ||
|
||
// Step 2: Check the partition columns | ||
val tablePartCols = | ||
table.getLatestSnapshot(defaultEngine).getPartitionColumnNames(defaultEngine) | ||
|
||
assert(partCols.asJava === tablePartCols) | ||
} | ||
} | ||
} | ||
|
||
} |