Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Kernel] [CC Refactor #2] TableDescriptor API + CC Table Properties #4050

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Create TableDescriptorSuite.scala
  • Loading branch information
scottsand-db committed Jan 14, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 4846b7a205c5db8a98ca11709c35fca1fe521e10
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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.coordinatedcommits

import org.scalatest.funsuite.AnyFunSuite
import io.delta.kernel.TableIdentifier
import java.util.Optional

import scala.collection.JavaConverters._

class TableDescriptorSuite extends AnyFunSuite {

test("TableDescriptor should throw NullPointerException for null constructor arguments") {
assertThrows[NullPointerException] {
new TableDescriptor(null, Optional.empty(), Map.empty[String, String].asJava)
}
assertThrows[NullPointerException] {
new TableDescriptor("/delta/logPath", null, Map.empty[String, String].asJava)
}
assertThrows[NullPointerException] {
new TableDescriptor("/delta/logPath", Optional.empty(), null)
}
}

test("TableDescriptor should return the correct logPath, tableId, and tableConf") {
val logPath = "/delta/logPath"
val tableId = Optional.of(new TableIdentifier(Array("catalog", "schema"), "table"))
val tableConf = Map("key1" -> "value1", "key2" -> "value2").asJava

val tableDescriptor = new TableDescriptor(logPath, tableId, tableConf)

assert(tableDescriptor.getLogPath == logPath)
assert(tableDescriptor.getTableId == tableId)
assert(tableDescriptor.getTableConf == tableConf)
}

test("TableDescriptors with the same values should be equal") {
val logPath = "/delta/logPath"
val tableId = Optional.of(new TableIdentifier(Array("catalog", "schema"), "table"))
val tableConf = Map("key1" -> "value1", "key2" -> "value2").asJava

val tableDescriptor1 = new TableDescriptor(logPath, tableId, tableConf)
val tableDescriptor2 = new TableDescriptor(logPath, tableId, tableConf)

assert(tableDescriptor1 == tableDescriptor2)
assert(tableDescriptor1.hashCode == tableDescriptor2.hashCode)
}

test("TableDescriptors with different values should not be equal") {
val logPath = "/delta/logPath"
val tableId = Optional.of(new TableIdentifier(Array("catalog", "schema"), "table"))
val tableConf1 = Map("key1" -> "value1").asJava
val tableConf2 = Map("key1" -> "value2").asJava

val tableDescriptor1 = new TableDescriptor(logPath, tableId, tableConf1)
val tableDescriptor2 = new TableDescriptor(logPath, tableId, tableConf2)

assert(tableDescriptor1 != tableDescriptor2)
}

test("TableDescriptor toString format") {
val logPath = "/delta/logPath"
val tableId = Optional.of(new TableIdentifier(Array("catalog", "schema"), "table"))
val tableConf = Map("key1" -> "value1").asJava

val tableDescriptor = new TableDescriptor(logPath, tableId, tableConf)
val expectedString = "TableDescriptor{logPath='/delta/logPath', " +
"tableId=Optional[TableIdentifier{catalog.schema.table}], " +
"tableConf={key1=value1}}"
assert(tableDescriptor.toString == expectedString)
}
}