Skip to content

Conversation

@nk1506
Copy link
Contributor

@nk1506 nk1506 commented Mar 17, 2024

Hive should not allow creating an iceberg table, if there is already another content available with same name.

@pvary / @szehon-ho Please share your feedback for these tests.

@github-actions github-actions bot added the hive label Mar 17, 2024
@nk1506 nk1506 changed the title Hive: Test to do validation hive content and iceberg table with the same name Hive: Tests to do validation hive content and iceberg table with the same name Mar 20, 2024

catalog.setListAllTables(true);
List<TableIdentifier> tableIdents2 = catalog.listTables(TABLE_IDENTIFIER.namespace());
assertThat(tableIdents2).as("should be 2 tables in namespace .").hasSize(2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should also use .containsExactly(..) to check what exactly comes back

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertThat(catalog.listTables(TABLE_IDENTIFIER.namespace())).hasSize(2).containsExactly(...) (no need to define List<TableIdentifier> tableIdents2)

throws IOException {
@Test
public void testHiveTableAndIcebergTableWithSameName() throws TException, IOException {
List<TableIdentifier> tableIdents = catalog.listTables(TABLE_IDENTIFIER.namespace());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to store this in a variable

@Test
public void testHiveTableAndIcebergTableWithSameName() throws TException, IOException {
List<TableIdentifier> tableIdents = catalog.listTables(TABLE_IDENTIFIER.namespace());
assertThat(tableIdents).as("should be 1 table in namespace .").hasSize(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assertThat(tableIdents).as("should be 1 table in namespace .").hasSize(1);
assertThat(catalog.listTables(TABLE_IDENTIFIER.namespace())).hasSize(1).containsExactly(...);

catalog.createTable(
identifierWithHiveTableName, schema, PartitionSpec.unpartitioned()))
.isInstanceOf(NoSuchIcebergTableException.class)
.hasMessageStartingWith("Not an iceberg table: hive.hivedb.test_hive_table");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.hasMessageStartingWith("Not an iceberg table: hive.hivedb.test_hive_table");
.hasMessageStartingWith(String.format("Not an iceberg table: %s", identifier));

List<TableIdentifier> tableIdents2 = catalog.listTables(TABLE_IDENTIFIER.namespace());
assertThat(tableIdents2).as("should be 2 tables in namespace .").hasSize(2);

TableIdentifier identifierWithHiveTableName = TableIdentifier.of(DB_NAME, hiveTableName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TableIdentifier identifierWithHiveTableName = TableIdentifier.of(DB_NAME, hiveTableName);
TableIdentifier identifier = TableIdentifier.of(DB_NAME, hiveTableName);

}

@Test
public void testHiveViewAndIcebergTableWithSameName() throws TException, IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also reflect the comments from above in this test method


private org.apache.hadoop.hive.metastore.api.Table createHiveTable(String hiveTableName)
throws IOException {
@Test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could change this to a @ParameterizedTest, since the only difference between the two tests is the TableType. So the test would have a TableType parameter, where you pass TableType.EXTERNAL_TABLE and TableType.VIRTUAL_VIEW via @EnumSource (there are examples in the codebase on how to use parameterized tests with enums)

import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;

@ExtendWith(ParameterizedTestExtension.class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't have to make the full class a parameterized test.

@ParameterizedTest
@EnumSource(
value = TableSchemaType.class,
names = {"ONE_BUCKET", "IDENTITY_AND_BUCKET"})
public void testSendRecordsToAllBucketsEvenly(TableSchemaType tableSchemaType) throws Exception {
is all you need and that's what I meant in #9980 (comment)

@nastra nastra merged commit 2eabd52 into apache:main Mar 26, 2024
sasankpagolu pushed a commit to sasankpagolu/iceberg that referenced this pull request Oct 27, 2024
zachdisc pushed a commit to zachdisc/iceberg that referenced this pull request Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants