Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ This product includes code from Apache Parquet.

* DynMethods.java
* DynConstructors.java
* AssertHelpers.java
* IOUtil.java readFully and tests
* ByteBufferInputStream implementations and tests

Expand Down
213 changes: 0 additions & 213 deletions api/src/test/java/org/apache/iceberg/AssertHelpers.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.apache.avro.generic.GenericDatumWriter;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.io.DatumWriter;
import org.apache.iceberg.AssertHelpers;
import org.apache.iceberg.DataFile;
import org.apache.iceberg.TableProperties;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
Expand All @@ -48,6 +47,7 @@
import org.apache.spark.sql.types.Metadata;
import org.apache.spark.sql.types.StructField;
import org.apache.spark.sql.types.StructType;
import org.assertj.core.api.Assertions;
import org.joda.time.DateTime;
import org.junit.After;
import org.junit.Assert;
Expand Down Expand Up @@ -688,23 +688,23 @@ public void invalidDataImport() {

createIcebergTable("id Integer, name String, dept String, subdept String");

AssertHelpers.assertThrows(
"Should forbid adding of partitioned data to unpartitioned table",
IllegalArgumentException.class,
"Cannot use partition filter with an unpartitioned table",
() ->
scalarSql(
"CALL %s.system.add_files('%s', '`parquet`.`%s`', map('id', 1))",
catalogName, tableName, fileTableDir.getAbsolutePath()));

AssertHelpers.assertThrows(
"Should forbid adding of partitioned data to unpartitioned table",
IllegalArgumentException.class,
"Cannot add partitioned files to an unpartitioned table",
() ->
scalarSql(
"CALL %s.system.add_files('%s', '`parquet`.`%s`')",
catalogName, tableName, fileTableDir.getAbsolutePath()));
Assertions.assertThatThrownBy(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it should be fine to statically import the method here, similar to how assertThat is already statically imported in this class.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The code was changed mechanically, so thanks for catching that.
I know that static imports are generally discouraged in the project, so is this comment about this source file in particular, or more broadly about Assertions.*?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the comment is only about statically importing methods from Assertions, but I guess it would be too much work now to statically import assertThatThrownBy, so let's leave it as-is

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If we have consensu that Assertions should be used with static imports, do you think it could be helpful to support this with static code analysis?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we could eventually support this via static code analysis but atm we have a mix of static vs non-static usage wrt Assertions

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

so if we cleaned up the non-static imports, we would want to have static code analysis?
let's give it a try -- #10517

() ->
scalarSql(
"CALL %s.system.add_files('%s', '`parquet`.`%s`', map('id', 1))",
catalogName, tableName, fileTableDir.getAbsolutePath()))
.as("Should forbid adding of partitioned data to unpartitioned table")
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Cannot use partition filter with an unpartitioned table");

Assertions.assertThatThrownBy(
() ->
scalarSql(
"CALL %s.system.add_files('%s', '`parquet`.`%s`')",
catalogName, tableName, fileTableDir.getAbsolutePath()))
.as("Should forbid adding of partitioned data to unpartitioned table")
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Cannot add partitioned files to an unpartitioned table");
}

@Test
Expand All @@ -714,23 +714,24 @@ public void invalidDataImportPartitioned() {
createIcebergTable(
"id Integer, name String, dept String, subdept String", "PARTITIONED BY (id)");

AssertHelpers.assertThrows(
"Should forbid adding with a mismatching partition spec",
IllegalArgumentException.class,
"is greater than the number of partitioned columns",
() ->
scalarSql(
"CALL %s.system.add_files('%s', '`parquet`.`%s`', map('x', '1', 'y', '2'))",
catalogName, tableName, fileTableDir.getAbsolutePath()));

AssertHelpers.assertThrows(
"Should forbid adding with partition spec with incorrect columns",
IllegalArgumentException.class,
"specified partition filter refers to columns that are not partitioned",
() ->
scalarSql(
"CALL %s.system.add_files('%s', '`parquet`.`%s`', map('dept', '2'))",
catalogName, tableName, fileTableDir.getAbsolutePath()));
Assertions.assertThatThrownBy(
() ->
scalarSql(
"CALL %s.system.add_files('%s', '`parquet`.`%s`', map('x', '1', 'y', '2'))",
catalogName, tableName, fileTableDir.getAbsolutePath()))
.as("Should forbid adding with a mismatching partition spec")
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("is greater than the number of partitioned columns");

Assertions.assertThatThrownBy(
() ->
scalarSql(
"CALL %s.system.add_files('%s', '`parquet`.`%s`', map('dept', '2'))",
catalogName, tableName, fileTableDir.getAbsolutePath()))
.as("Should forbid adding with partition spec with incorrect columns")
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining(
"specified partition filter refers to columns that are not partitioned");
}

@Test
Expand Down Expand Up @@ -782,18 +783,19 @@ public void duplicateDataPartitioned() {
+ "partition_filter => map('id', 1))",
catalogName, tableName, sourceTableName);

AssertHelpers.assertThrows(
"Should not allow adding duplicate files",
IllegalStateException.class,
"Cannot complete import because data files to be imported already"
+ " exist within the target table",
() ->
scalarSql(
"CALL %s.system.add_files("
+ "table => '%s', "
+ "source_table => '%s', "
+ "partition_filter => map('id', 1))",
catalogName, tableName, sourceTableName));
Assertions.assertThatThrownBy(
() ->
scalarSql(
"CALL %s.system.add_files("
+ "table => '%s', "
+ "source_table => '%s', "
+ "partition_filter => map('id', 1))",
catalogName, tableName, sourceTableName))
.as("Should not allow adding duplicate files")
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining(
"Cannot complete import because data files to be imported already"
+ " exist within the target table");
}

@Test
Expand Down Expand Up @@ -841,14 +843,16 @@ public void duplicateDataUnpartitioned() {

sql("CALL %s.system.add_files('%s', '%s')", catalogName, tableName, sourceTableName);

AssertHelpers.assertThrows(
"Should not allow adding duplicate files",
IllegalStateException.class,
"Cannot complete import because data files to be imported already"
+ " exist within the target table",
() ->
scalarSql(
"CALL %s.system.add_files('%s', '%s')", catalogName, tableName, sourceTableName));
Assertions.assertThatThrownBy(
() ->
scalarSql(
"CALL %s.system.add_files('%s', '%s')",
catalogName, tableName, sourceTableName))
.as("Should not allow adding duplicate files")
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining(
"Cannot complete import because data files to be imported already"
+ " exist within the target table");
}

@Test
Expand Down
Loading