Skip to content

Commit

Permalink
[core] Fix the caching catalog to properly handle case sensitivity fo…
Browse files Browse the repository at this point in the history
…r system table
  • Loading branch information
Zouxxyy committed Dec 10, 2024
1 parent 55e4e74 commit 1b4b1df
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class Identifier implements Serializable {

private transient String table;
private transient String branch;
// SystemTable name is case-insensitive and will consistently be returned in lowercase.
private transient String systemTable;

public Identifier(String database, String object) {
Expand Down Expand Up @@ -116,7 +117,7 @@ public String getBranchNameOrDefault() {

public @Nullable String getSystemTableName() {
splitObjectName();
return systemTable;
return systemTable == null ? null : systemTable.toLowerCase();
}

private void splitObjectName() {
Expand Down Expand Up @@ -187,12 +188,15 @@ public boolean equals(Object o) {
return false;
}
Identifier that = (Identifier) o;
return Objects.equals(database, that.database) && Objects.equals(object, that.object);
return Objects.equals(database, that.database)
&& Objects.equals(getTableName(), that.getTableName())
&& Objects.equals(getBranchName(), that.getBranchName())
&& Objects.equals(getSystemTableName(), that.getSystemTableName());
}

@Override
public int hashCode() {
return Objects.hash(database, object);
return Objects.hash(database, getTableName(), getBranchName(), getSystemTableName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,14 @@ public void testInvalidateSysTablesIfBaseTableIsDropped() throws Exception {
catalog.createTable(new Identifier("db", "tbl"), DEFAULT_TABLE_SCHEMA, false);
Identifier sysIdent = new Identifier("db", "tbl$files");
catalog.getTable(sysIdent);
Identifier sysIdent1 = new Identifier("db", "tbl$SNAPSHOTS");
catalog.getTable(sysIdent1);

catalog.dropTable(tableIdent, false);
assertThatThrownBy(() -> catalog.getTable(sysIdent))
.hasMessage("Table db.tbl does not exist.");
assertThatThrownBy(() -> catalog.getTable(sysIdent1))
.hasMessage("Table db.tbl does not exist.");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.catalog;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/** Test for {@link Identifier}. */
public class IdentifierTest {

@Test
public void testIdentifierEquals() {
assertThat(new Identifier("db", "tbl")).isNotEqualTo(new Identifier("DB", "tbl"));
assertThat(new Identifier("db", "tbl")).isNotEqualTo(new Identifier("db", "TBL"));
assertThat(new Identifier("db", "tbl$branch_test"))
.isNotEqualTo(new Identifier("db", "tbl$branch_TEST"));
assertThat(new Identifier("db", "tbl$files")).isEqualTo(new Identifier("db", "tbl$FILES"));
assertThat(new Identifier("db", "tbl$branch_test$files"))
.isEqualTo(new Identifier("db", "tbl$branch_test$FILES"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class PaimonSparkTestBase
super.sparkConf
.set("spark.sql.catalog.paimon", classOf[SparkCatalog].getName)
.set("spark.sql.catalog.paimon.warehouse", tempDBDir.getCanonicalPath)
.set("spark.sql.catalog.paimon.cache-enabled", "false")
.set("spark.sql.extensions", classOf[PaimonSparkSessionExtensions].getName)
.set("spark.serializer", serializer)
}
Expand Down

0 comments on commit 1b4b1df

Please sign in to comment.