You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "chinmay-bhat (via GitHub)" <gi...@apache.org> on 2024/01/03 09:38:14 UTC
[PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
chinmay-bhat opened a new pull request, #9401:
URL: https://github.com/apache/iceberg/pull/9401
This PR migrates the tests in spark/sql directory to JUnit5.
Issue: #9086
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "chinmay-bhat (via GitHub)" <gi...@apache.org>.
chinmay-bhat commented on code in PR #9401:
URL: https://github.com/apache/iceberg/pull/9401#discussion_r1442989187
##########
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/sql/PartitionedWritesTestBase.java:
##########
@@ -18,53 +18,49 @@
*/
package org.apache.iceberg.spark.sql;
+import static org.assertj.core.api.Assertions.assertThat;
+
import java.util.Arrays;
import java.util.List;
-import java.util.Map;
import org.apache.iceberg.Table;
import org.apache.iceberg.expressions.Expressions;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
-import org.apache.iceberg.spark.SparkCatalogTestBase;
+import org.apache.iceberg.spark.CatalogTestBase;
import org.apache.iceberg.spark.source.SimpleRecord;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.catalyst.analysis.NoSuchTableException;
import org.apache.spark.sql.functions;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public abstract class PartitionedWritesTestBase extends SparkCatalogTestBase {
- public PartitionedWritesTestBase(
- String catalogName, String implementation, Map<String, String> config) {
- super(catalogName, implementation, config);
- }
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestTemplate;
+
+public abstract class /**/ PartitionedWritesTestBase extends CatalogTestBase {
Review Comment:
my bad, fixed!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9401:
URL: https://github.com/apache/iceberg/pull/9401#discussion_r1443812461
##########
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/sql/TestNamespaceSQL.java:
##########
@@ -18,90 +18,131 @@
*/
package org.apache.iceberg.spark.sql;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assumptions.assumeThat;
+
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
+import org.apache.iceberg.Parameter;
+import org.apache.iceberg.Parameters;
import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet;
import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
-import org.apache.iceberg.spark.SparkCatalogTestBase;
+import org.apache.iceberg.spark.CatalogTestBase;
+import org.apache.iceberg.spark.SparkCatalogConfig;
import org.assertj.core.api.Assertions;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.TestTemplate;
-public class TestNamespaceSQL extends SparkCatalogTestBase {
+public class TestNamespaceSQL extends CatalogTestBase {
private static final Namespace NS = Namespace.of("db");
- private final String fullNamespace;
- private final boolean isHadoopCatalog;
-
- public TestNamespaceSQL(String catalogName, String implementation, Map<String, String> config) {
- super(catalogName, implementation, config);
- this.fullNamespace = ("spark_catalog".equals(catalogName) ? "" : catalogName + ".") + NS;
- this.isHadoopCatalog = "testhadoop".equals(catalogName);
+ @Parameter(index = 3)
+ private String fullNamespace;
+
+ @Parameter(index = 4)
+ private boolean isHadoopCatalog;
+
+ @Parameters(
+ name =
+ "catalogName = {0}, implementation = {1}, config = {2}, fullNameSpace = {3}, isHadoopCatalog = {4}")
+ protected static Object[][] parameters() {
+ return new Object[][] {
+ {
+ SparkCatalogConfig.HIVE.catalogName(),
+ SparkCatalogConfig.HIVE.implementation(),
+ SparkCatalogConfig.HIVE.properties(),
+ "testhive." + NS.toString(),
Review Comment:
we should probably use `SparkCatalogConfig.HIVE.catalogName()` to construct this. If anyone ever updates the underlying name then this test will start to fail
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9401:
URL: https://github.com/apache/iceberg/pull/9401#discussion_r1445274223
##########
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/sql/TestNamespaceSQL.java:
##########
@@ -110,134 +151,156 @@ public void testDropNonEmptyNamespace() {
sql("DROP TABLE %s.table", fullNamespace);
}
- @Test
+ @TestTemplate
public void testListTables() {
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
sql("CREATE NAMESPACE %s", fullNamespace);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
List<Object[]> rows = sql("SHOW TABLES IN %s", fullNamespace);
- Assert.assertEquals("Should not list any tables", 0, rows.size());
+ assertThat(rows).as("Should not list any tables").hasSize(0);
sql("CREATE TABLE %s.table (id bigint) USING iceberg", fullNamespace);
Object[] row = Iterables.getOnlyElement(sql("SHOW TABLES IN %s", fullNamespace));
- Assert.assertEquals("Namespace should match", "db", row[0]);
- Assert.assertEquals("Table name should match", "table", row[1]);
+ assertThat(row[0]).as("Namespace should match").isEqualTo("db");
+ assertThat(row[1]).as("Table name should match").isEqualTo("table");
}
- @Test
+ @TestTemplate
public void testListNamespace() {
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
sql("CREATE NAMESPACE %s", fullNamespace);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
List<Object[]> namespaces = sql("SHOW NAMESPACES IN %s", catalogName);
if (isHadoopCatalog) {
- Assert.assertEquals("Should have 1 namespace", 1, namespaces.size());
+ assertThat(namespaces).as("Should have 1 namespace").hasSize(1);
Set<String> namespaceNames =
namespaces.stream().map(arr -> arr[0].toString()).collect(Collectors.toSet());
- Assert.assertEquals("Should have only db namespace", ImmutableSet.of("db"), namespaceNames);
+ assertThat(namespaceNames)
+ .as("Should have only db namespace")
+ .isEqualTo(ImmutableSet.of("db"));
} else {
- Assert.assertEquals("Should have 2 namespaces", 2, namespaces.size());
+ assertThat(namespaces).as("Should have 2 namespaces").hasSize(2);
Set<String> namespaceNames =
namespaces.stream().map(arr -> arr[0].toString()).collect(Collectors.toSet());
- Assert.assertEquals(
- "Should have default and db namespaces",
- ImmutableSet.of("default", "db"),
- namespaceNames);
+ assertThat(namespaceNames)
+ .as("Should have default and db namespaces")
+ .isEqualTo(ImmutableSet.of("default", "db"));
}
List<Object[]> nestedNamespaces = sql("SHOW NAMESPACES IN %s", fullNamespace);
Set<String> nestedNames =
nestedNamespaces.stream().map(arr -> arr[0].toString()).collect(Collectors.toSet());
- Assert.assertEquals("Should not have nested namespaces", ImmutableSet.of(), nestedNames);
+ assertThat(nestedNames).as("Should not have nested namespaces").isEmpty();
}
- @Test
+ @TestTemplate
public void testCreateNamespaceWithMetadata() {
- Assume.assumeFalse("HadoopCatalog does not support namespace metadata", isHadoopCatalog);
+ assumeThat(isHadoopCatalog).as("HadoopCatalog does not support namespace metadata").isFalse();
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
sql("CREATE NAMESPACE %s WITH PROPERTIES ('prop'='value')", fullNamespace);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
Map<String, String> nsMetadata = validationNamespaceCatalog.loadNamespaceMetadata(NS);
- Assert.assertEquals(
- "Namespace should have expected prop value", "value", nsMetadata.get("prop"));
+ assertThat(nsMetadata.get("prop"))
+ .as("Namespace should have expected prop value")
+ .isEqualTo("value");
}
- @Test
+ @TestTemplate
public void testCreateNamespaceWithComment() {
- Assume.assumeFalse("HadoopCatalog does not support namespace metadata", isHadoopCatalog);
+ assumeThat(isHadoopCatalog).as("HadoopCatalog does not support namespace metadata").isFalse();
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
sql("CREATE NAMESPACE %s COMMENT 'namespace doc'", fullNamespace);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
Map<String, String> nsMetadata = validationNamespaceCatalog.loadNamespaceMetadata(NS);
- Assert.assertEquals(
- "Namespace should have expected comment", "namespace doc", nsMetadata.get("comment"));
+ assertThat(nsMetadata.get("comment"))
Review Comment:
same as above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "chinmay-bhat (via GitHub)" <gi...@apache.org>.
chinmay-bhat commented on code in PR #9401:
URL: https://github.com/apache/iceberg/pull/9401#discussion_r1443954928
##########
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/sql/TestPartitionedWritesAsSelect.java:
##########
@@ -18,34 +18,35 @@
*/
package org.apache.iceberg.spark.sql;
+import static org.assertj.core.api.Assertions.assertThat;
+
import java.util.List;
import java.util.stream.IntStream;
import org.apache.iceberg.spark.IcebergSpark;
-import org.apache.iceberg.spark.SparkTestBaseWithCatalog;
+import org.apache.iceberg.spark.TestBaseWithCatalog;
import org.apache.spark.sql.types.DataTypes;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestTemplate;
-public class TestPartitionedWritesAsSelect extends SparkTestBaseWithCatalog {
+public class TestPartitionedWritesAsSelect extends TestBaseWithCatalog {
- private final String targetTable = tableName("target_table");
+ private final String targetTable = "testhadoop.default.target_table";
Review Comment:
aah this was unnecessary, thanks for catching this. Will revert.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9401:
URL: https://github.com/apache/iceberg/pull/9401#discussion_r1445263754
##########
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/sql/TestCreateTable.java:
##########
@@ -289,22 +312,25 @@ public void testCreateTableProperties() {
tableName);
Table table = validationCatalog.loadTable(tableIdent);
- Assert.assertNotNull("Should load the new table", table);
+ assertThat(table).as("Should load the new table").isNotNull();
StructType expectedSchema =
StructType.of(
NestedField.required(1, "id", Types.LongType.get()),
NestedField.optional(2, "data", Types.StringType.get()));
- Assert.assertEquals(
- "Should have the expected schema", expectedSchema, table.schema().asStruct());
- Assert.assertEquals("Should not be partitioned", 0, table.spec().fields().size());
- Assert.assertEquals("Should have property p1", "2", table.properties().get("p1"));
- Assert.assertEquals("Should have property p2", "x", table.properties().get("p2"));
+ assertThat(table.schema().asStruct())
+ .as("Should have the expected schema")
+ .isEqualTo(expectedSchema);
+ assertThat(table.spec().fields()).as("Should not be partitioned").hasSize(0);
+ assertThat(table.properties().get("p1")).as("Should have property p1").isEqualTo("2");
Review Comment:
please use `.containsEntry(..).containsEntry(..)` here. I don't think we need the `as(..)` as it's self-explanatory here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9401:
URL: https://github.com/apache/iceberg/pull/9401#discussion_r1445283708
##########
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/sql/TestSelect.java:
##########
@@ -18,70 +18,95 @@
*/
package org.apache.iceberg.spark.sql;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assumptions.assumeThat;
+
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
-import java.util.Map;
import java.util.concurrent.TimeUnit;
+import org.apache.iceberg.Parameter;
+import org.apache.iceberg.Parameters;
import org.apache.iceberg.Table;
import org.apache.iceberg.events.Listeners;
import org.apache.iceberg.events.ScanEvent;
import org.apache.iceberg.exceptions.ValidationException;
import org.apache.iceberg.expressions.Expressions;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.spark.CatalogTestBase;
import org.apache.iceberg.spark.Spark3Util;
-import org.apache.iceberg.spark.SparkCatalogTestBase;
+import org.apache.iceberg.spark.SparkCatalogConfig;
import org.apache.iceberg.spark.SparkReadOptions;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
-import org.assertj.core.api.Assertions;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.Test;
-
-public class TestSelect extends SparkCatalogTestBase {
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestTemplate;
+
+public class TestSelect extends CatalogTestBase {
private int scanEventCount = 0;
private ScanEvent lastScanEvent = null;
- private String binaryTableName = tableName("binary_table");
- public TestSelect(String catalogName, String implementation, Map<String, String> config) {
- super(catalogName, implementation, config);
+ @Parameter(index = 3)
+ private String binaryTableName;
+
+ @Parameters(name = "catalogName = {0}, implementation = {1}, config = {2}, binaryTableName = {3}")
+ protected static Object[][] parameters() {
+ return new Object[][] {
+ {
+ SparkCatalogConfig.HIVE.catalogName(),
+ SparkCatalogConfig.HIVE.implementation(),
+ SparkCatalogConfig.HIVE.properties(),
+ "testhive.default.binary_table"
Review Comment:
we should probably use `SparkCatalogConfig.HIVE.catalogName()` to construct this here and further below
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9401:
URL: https://github.com/apache/iceberg/pull/9401#discussion_r1445284087
##########
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/sql/TestCreateTableAsSelect.java:
##########
@@ -21,40 +21,64 @@
import static org.apache.spark.sql.functions.col;
import static org.apache.spark.sql.functions.lit;
import static org.apache.spark.sql.functions.when;
+import static org.assertj.core.api.Assertions.assertThat;
-import java.util.Map;
+import org.apache.iceberg.Parameter;
+import org.apache.iceberg.Parameters;
import org.apache.iceberg.PartitionSpec;
import org.apache.iceberg.Schema;
import org.apache.iceberg.Table;
-import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
-import org.apache.iceberg.spark.SparkCatalogTestBase;
+import org.apache.iceberg.spark.CatalogTestBase;
+import org.apache.iceberg.spark.SparkCatalogConfig;
import org.apache.iceberg.types.Types;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class TestCreateTableAsSelect extends SparkCatalogTestBase {
-
- private final String sourceName;
-
- public TestCreateTableAsSelect(
- String catalogName, String implementation, Map<String, String> config) {
- super(catalogName, implementation, config);
- this.sourceName = tableName("source");
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestTemplate;
+
+public class TestCreateTableAsSelect extends CatalogTestBase {
+
+ @Parameter(index = 3)
+ private String sourceName;
+
+ @Parameters(name = "catalogName = {0}, implementation = {1}, config = {2}, sourceName = {3}")
+ protected static Object[][] parameters() {
+ return new Object[][] {
+ {
+ SparkCatalogConfig.HIVE.catalogName(),
+ SparkCatalogConfig.HIVE.implementation(),
+ SparkCatalogConfig.HIVE.properties(),
+ "testhive.default.source"
Review Comment:
we should probably use `SparkCatalogConfig.HIVE.catalogName()` to construct this here and further below
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "chinmay-bhat (via GitHub)" <gi...@apache.org>.
chinmay-bhat commented on code in PR #9401:
URL: https://github.com/apache/iceberg/pull/9401#discussion_r1444346662
##########
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/sql/TestTimestampWithoutZone.java:
##########
@@ -145,33 +137,31 @@ public void testAppendTimestampWithZone() {
toTimestamp("2021-02-01T00:00:00.0")))));
}
- @Test
+ @TestTemplate
public void testCreateAsSelectWithTimestampWithoutZone() {
sql("INSERT INTO %s VALUES %s", tableName, rowToSqlValues(values));
sql("CREATE TABLE %s USING iceberg AS SELECT * FROM %s", newTableName, tableName);
- Assert.assertEquals(
- "Should have " + values.size() + " row",
- (long) values.size(),
- scalarSql("SELECT count(*) FROM %s", newTableName));
+ assertThat(scalarSql("SELECT count(*) FROM %s", newTableName))
+ .as("Should have " + values.size() + " row")
+ .isEqualTo((long) values.size());
Review Comment:
looking at the failed tests, we apparently do need the casts.
Line 48 shows in the schema, the `id` is a `long`.
```
private static final Schema schema =
new Schema(
Types.NestedField.required(1, "id", Types.LongType.get()),
Types.NestedField.required(2, "ts", Types.TimestampType.withoutZone()),
Types.NestedField.required(3, "tsz", Types.TimestampType.withZone()));
```
`scalarSql()` returns the `id` of the row. As its a `long`, we should continue using the casts.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra merged PR #9401:
URL: https://github.com/apache/iceberg/pull/9401
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9401:
URL: https://github.com/apache/iceberg/pull/9401#discussion_r1445274451
##########
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/sql/TestNamespaceSQL.java:
##########
@@ -110,134 +151,156 @@ public void testDropNonEmptyNamespace() {
sql("DROP TABLE %s.table", fullNamespace);
}
- @Test
+ @TestTemplate
public void testListTables() {
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
sql("CREATE NAMESPACE %s", fullNamespace);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
List<Object[]> rows = sql("SHOW TABLES IN %s", fullNamespace);
- Assert.assertEquals("Should not list any tables", 0, rows.size());
+ assertThat(rows).as("Should not list any tables").hasSize(0);
sql("CREATE TABLE %s.table (id bigint) USING iceberg", fullNamespace);
Object[] row = Iterables.getOnlyElement(sql("SHOW TABLES IN %s", fullNamespace));
- Assert.assertEquals("Namespace should match", "db", row[0]);
- Assert.assertEquals("Table name should match", "table", row[1]);
+ assertThat(row[0]).as("Namespace should match").isEqualTo("db");
+ assertThat(row[1]).as("Table name should match").isEqualTo("table");
}
- @Test
+ @TestTemplate
public void testListNamespace() {
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
sql("CREATE NAMESPACE %s", fullNamespace);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
List<Object[]> namespaces = sql("SHOW NAMESPACES IN %s", catalogName);
if (isHadoopCatalog) {
- Assert.assertEquals("Should have 1 namespace", 1, namespaces.size());
+ assertThat(namespaces).as("Should have 1 namespace").hasSize(1);
Set<String> namespaceNames =
namespaces.stream().map(arr -> arr[0].toString()).collect(Collectors.toSet());
- Assert.assertEquals("Should have only db namespace", ImmutableSet.of("db"), namespaceNames);
+ assertThat(namespaceNames)
+ .as("Should have only db namespace")
+ .isEqualTo(ImmutableSet.of("db"));
} else {
- Assert.assertEquals("Should have 2 namespaces", 2, namespaces.size());
+ assertThat(namespaces).as("Should have 2 namespaces").hasSize(2);
Set<String> namespaceNames =
namespaces.stream().map(arr -> arr[0].toString()).collect(Collectors.toSet());
- Assert.assertEquals(
- "Should have default and db namespaces",
- ImmutableSet.of("default", "db"),
- namespaceNames);
+ assertThat(namespaceNames)
+ .as("Should have default and db namespaces")
+ .isEqualTo(ImmutableSet.of("default", "db"));
}
List<Object[]> nestedNamespaces = sql("SHOW NAMESPACES IN %s", fullNamespace);
Set<String> nestedNames =
nestedNamespaces.stream().map(arr -> arr[0].toString()).collect(Collectors.toSet());
- Assert.assertEquals("Should not have nested namespaces", ImmutableSet.of(), nestedNames);
+ assertThat(nestedNames).as("Should not have nested namespaces").isEmpty();
}
- @Test
+ @TestTemplate
public void testCreateNamespaceWithMetadata() {
- Assume.assumeFalse("HadoopCatalog does not support namespace metadata", isHadoopCatalog);
+ assumeThat(isHadoopCatalog).as("HadoopCatalog does not support namespace metadata").isFalse();
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
sql("CREATE NAMESPACE %s WITH PROPERTIES ('prop'='value')", fullNamespace);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
Map<String, String> nsMetadata = validationNamespaceCatalog.loadNamespaceMetadata(NS);
- Assert.assertEquals(
- "Namespace should have expected prop value", "value", nsMetadata.get("prop"));
+ assertThat(nsMetadata.get("prop"))
+ .as("Namespace should have expected prop value")
+ .isEqualTo("value");
}
- @Test
+ @TestTemplate
public void testCreateNamespaceWithComment() {
- Assume.assumeFalse("HadoopCatalog does not support namespace metadata", isHadoopCatalog);
+ assumeThat(isHadoopCatalog).as("HadoopCatalog does not support namespace metadata").isFalse();
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
sql("CREATE NAMESPACE %s COMMENT 'namespace doc'", fullNamespace);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
Map<String, String> nsMetadata = validationNamespaceCatalog.loadNamespaceMetadata(NS);
- Assert.assertEquals(
- "Namespace should have expected comment", "namespace doc", nsMetadata.get("comment"));
+ assertThat(nsMetadata.get("comment"))
+ .as("Namespace should have expected comment")
+ .isEqualTo("namespace doc");
}
- @Test
+ @TestTemplate
public void testCreateNamespaceWithLocation() throws Exception {
- Assume.assumeFalse("HadoopCatalog does not support namespace locations", isHadoopCatalog);
+ assumeThat(isHadoopCatalog).as("HadoopCatalog does not support namespace metadata").isFalse();
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
- File location = temp.newFile();
- Assert.assertTrue(location.delete());
+ File location = File.createTempFile("junit", null, temp.toFile());
+ assertThat(location.delete()).isTrue();
sql("CREATE NAMESPACE %s LOCATION '%s'", fullNamespace, location);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
Map<String, String> nsMetadata = validationNamespaceCatalog.loadNamespaceMetadata(NS);
- Assert.assertEquals(
- "Namespace should have expected location",
- "file:" + location.getPath(),
- nsMetadata.get("location"));
+ assertThat(nsMetadata.get("location"))
Review Comment:
same as above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9401:
URL: https://github.com/apache/iceberg/pull/9401#discussion_r1445272797
##########
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/sql/TestNamespaceSQL.java:
##########
@@ -18,90 +18,131 @@
*/
package org.apache.iceberg.spark.sql;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assumptions.assumeThat;
+
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
+import org.apache.iceberg.Parameter;
+import org.apache.iceberg.Parameters;
import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet;
import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
-import org.apache.iceberg.spark.SparkCatalogTestBase;
+import org.apache.iceberg.spark.CatalogTestBase;
+import org.apache.iceberg.spark.SparkCatalogConfig;
import org.assertj.core.api.Assertions;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.TestTemplate;
-public class TestNamespaceSQL extends SparkCatalogTestBase {
+public class TestNamespaceSQL extends CatalogTestBase {
private static final Namespace NS = Namespace.of("db");
- private final String fullNamespace;
- private final boolean isHadoopCatalog;
-
- public TestNamespaceSQL(String catalogName, String implementation, Map<String, String> config) {
- super(catalogName, implementation, config);
- this.fullNamespace = ("spark_catalog".equals(catalogName) ? "" : catalogName + ".") + NS;
- this.isHadoopCatalog = "testhadoop".equals(catalogName);
+ @Parameter(index = 3)
+ private String fullNamespace;
+
+ @Parameter(index = 4)
+ private boolean isHadoopCatalog;
+
+ @Parameters(
+ name =
+ "catalogName = {0}, implementation = {1}, config = {2}, fullNameSpace = {3}, isHadoopCatalog = {4}")
+ protected static Object[][] parameters() {
+ return new Object[][] {
+ {
+ SparkCatalogConfig.HIVE.catalogName(),
+ SparkCatalogConfig.HIVE.implementation(),
+ SparkCatalogConfig.HIVE.properties(),
+ SparkCatalogConfig.HIVE.catalogName() + "." + NS.toString(),
+ false
+ },
+ {
+ SparkCatalogConfig.HADOOP.catalogName(),
+ SparkCatalogConfig.HADOOP.implementation(),
+ SparkCatalogConfig.HADOOP.properties(),
+ SparkCatalogConfig.HADOOP.catalogName() + "." + NS.toString(),
+ true
+ },
+ {
+ SparkCatalogConfig.SPARK.catalogName(),
+ SparkCatalogConfig.SPARK.implementation(),
+ SparkCatalogConfig.SPARK.properties(),
+ NS.toString(),
+ false
+ }
+ };
}
- @After
+ @AfterEach
public void cleanNamespaces() {
sql("DROP TABLE IF EXISTS %s.table", fullNamespace);
sql("DROP NAMESPACE IF EXISTS %s", fullNamespace);
}
- @Test
+ @TestTemplate
public void testCreateNamespace() {
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
sql("CREATE NAMESPACE %s", fullNamespace);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
}
- @Test
+ @TestTemplate
public void testDefaultNamespace() {
- Assume.assumeFalse("Hadoop has no default namespace configured", isHadoopCatalog);
+ assumeThat(isHadoopCatalog).as("Hadoop has no default namespace configured").isFalse();
sql("USE %s", catalogName);
Object[] current = Iterables.getOnlyElement(sql("SHOW CURRENT NAMESPACE"));
- Assert.assertEquals("Should use the current catalog", current[0], catalogName);
- Assert.assertEquals("Should use the configured default namespace", current[1], "default");
+ assertThat(catalogName).as("Should use the current catalog").isEqualTo(current[0]);
Review Comment:
```suggestion
assertThat(current[0]).as("Should use the current catalog").isEqualTo(catalogName);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "chinmay-bhat (via GitHub)" <gi...@apache.org>.
chinmay-bhat commented on code in PR #9401:
URL: https://github.com/apache/iceberg/pull/9401#discussion_r1444665891
##########
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/sql/TestPartitionedWritesAsSelect.java:
##########
@@ -18,34 +18,35 @@
*/
package org.apache.iceberg.spark.sql;
+import static org.assertj.core.api.Assertions.assertThat;
+
import java.util.List;
import java.util.stream.IntStream;
import org.apache.iceberg.spark.IcebergSpark;
-import org.apache.iceberg.spark.SparkTestBaseWithCatalog;
+import org.apache.iceberg.spark.TestBaseWithCatalog;
import org.apache.spark.sql.types.DataTypes;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestTemplate;
-public class TestPartitionedWritesAsSelect extends SparkTestBaseWithCatalog {
+public class TestPartitionedWritesAsSelect extends TestBaseWithCatalog {
- private final String targetTable = tableName("target_table");
+ private final String targetTable = "testhadoop.default.target_table";
Review Comment:
hmm reverting this change seems to cause more errors. Earlier, as we had constructors to initialize catalogName, we could simply use `tableName()`, but with parameters only, catalogName is not set, but passed as a `Parameter`. So we need to treat `targetTable` as a `Parameter` too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9401:
URL: https://github.com/apache/iceberg/pull/9401#discussion_r1442885901
##########
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/sql/PartitionedWritesTestBase.java:
##########
@@ -18,53 +18,49 @@
*/
package org.apache.iceberg.spark.sql;
+import static org.assertj.core.api.Assertions.assertThat;
+
import java.util.Arrays;
import java.util.List;
-import java.util.Map;
import org.apache.iceberg.Table;
import org.apache.iceberg.expressions.Expressions;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
-import org.apache.iceberg.spark.SparkCatalogTestBase;
+import org.apache.iceberg.spark.CatalogTestBase;
import org.apache.iceberg.spark.source.SimpleRecord;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.catalyst.analysis.NoSuchTableException;
import org.apache.spark.sql.functions;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public abstract class PartitionedWritesTestBase extends SparkCatalogTestBase {
- public PartitionedWritesTestBase(
- String catalogName, String implementation, Map<String, String> config) {
- super(catalogName, implementation, config);
- }
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestTemplate;
+
+public abstract class /**/ PartitionedWritesTestBase extends CatalogTestBase {
Review Comment:
```suggestion
public abstract class PartitionedWritesTestBase extends CatalogTestBase {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9401:
URL: https://github.com/apache/iceberg/pull/9401#discussion_r1443812981
##########
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/sql/TestTimestampWithoutZone.java:
##########
@@ -145,33 +137,31 @@ public void testAppendTimestampWithZone() {
toTimestamp("2021-02-01T00:00:00.0")))));
}
- @Test
+ @TestTemplate
public void testCreateAsSelectWithTimestampWithoutZone() {
sql("INSERT INTO %s VALUES %s", tableName, rowToSqlValues(values));
sql("CREATE TABLE %s USING iceberg AS SELECT * FROM %s", newTableName, tableName);
- Assert.assertEquals(
- "Should have " + values.size() + " row",
- (long) values.size(),
- scalarSql("SELECT count(*) FROM %s", newTableName));
+ assertThat(scalarSql("SELECT count(*) FROM %s", newTableName))
+ .as("Should have " + values.size() + " row")
+ .isEqualTo((long) values.size());
Review Comment:
do we need these casts?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "chinmay-bhat (via GitHub)" <gi...@apache.org>.
chinmay-bhat commented on PR #9401:
URL: https://github.com/apache/iceberg/pull/9401#issuecomment-1883591290
Thanks for the review, @nastra! I've made the suggested changes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9401:
URL: https://github.com/apache/iceberg/pull/9401#discussion_r1443812495
##########
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/sql/TestPartitionedWritesAsSelect.java:
##########
@@ -18,34 +18,35 @@
*/
package org.apache.iceberg.spark.sql;
+import static org.assertj.core.api.Assertions.assertThat;
+
import java.util.List;
import java.util.stream.IntStream;
import org.apache.iceberg.spark.IcebergSpark;
-import org.apache.iceberg.spark.SparkTestBaseWithCatalog;
+import org.apache.iceberg.spark.TestBaseWithCatalog;
import org.apache.spark.sql.types.DataTypes;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestTemplate;
-public class TestPartitionedWritesAsSelect extends SparkTestBaseWithCatalog {
+public class TestPartitionedWritesAsSelect extends TestBaseWithCatalog {
- private final String targetTable = tableName("target_table");
+ private final String targetTable = "testhadoop.default.target_table";
Review Comment:
why this change?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "chinmay-bhat (via GitHub)" <gi...@apache.org>.
chinmay-bhat commented on code in PR #9401:
URL: https://github.com/apache/iceberg/pull/9401#discussion_r1443955073
##########
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/sql/TestTimestampWithoutZone.java:
##########
@@ -145,33 +137,31 @@ public void testAppendTimestampWithZone() {
toTimestamp("2021-02-01T00:00:00.0")))));
}
- @Test
+ @TestTemplate
public void testCreateAsSelectWithTimestampWithoutZone() {
sql("INSERT INTO %s VALUES %s", tableName, rowToSqlValues(values));
sql("CREATE TABLE %s USING iceberg AS SELECT * FROM %s", newTableName, tableName);
- Assert.assertEquals(
- "Should have " + values.size() + " row",
- (long) values.size(),
- scalarSql("SELECT count(*) FROM %s", newTableName));
+ assertThat(scalarSql("SELECT count(*) FROM %s", newTableName))
+ .as("Should have " + values.size() + " row")
+ .isEqualTo((long) values.size());
Review Comment:
no, not needed. Will update this too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9401:
URL: https://github.com/apache/iceberg/pull/9401#discussion_r1445274742
##########
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/sql/TestNamespaceSQL.java:
##########
@@ -110,134 +151,156 @@ public void testDropNonEmptyNamespace() {
sql("DROP TABLE %s.table", fullNamespace);
}
- @Test
+ @TestTemplate
public void testListTables() {
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
sql("CREATE NAMESPACE %s", fullNamespace);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
List<Object[]> rows = sql("SHOW TABLES IN %s", fullNamespace);
- Assert.assertEquals("Should not list any tables", 0, rows.size());
+ assertThat(rows).as("Should not list any tables").hasSize(0);
sql("CREATE TABLE %s.table (id bigint) USING iceberg", fullNamespace);
Object[] row = Iterables.getOnlyElement(sql("SHOW TABLES IN %s", fullNamespace));
- Assert.assertEquals("Namespace should match", "db", row[0]);
- Assert.assertEquals("Table name should match", "table", row[1]);
+ assertThat(row[0]).as("Namespace should match").isEqualTo("db");
+ assertThat(row[1]).as("Table name should match").isEqualTo("table");
}
- @Test
+ @TestTemplate
public void testListNamespace() {
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
sql("CREATE NAMESPACE %s", fullNamespace);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
List<Object[]> namespaces = sql("SHOW NAMESPACES IN %s", catalogName);
if (isHadoopCatalog) {
- Assert.assertEquals("Should have 1 namespace", 1, namespaces.size());
+ assertThat(namespaces).as("Should have 1 namespace").hasSize(1);
Set<String> namespaceNames =
namespaces.stream().map(arr -> arr[0].toString()).collect(Collectors.toSet());
- Assert.assertEquals("Should have only db namespace", ImmutableSet.of("db"), namespaceNames);
+ assertThat(namespaceNames)
+ .as("Should have only db namespace")
+ .isEqualTo(ImmutableSet.of("db"));
} else {
- Assert.assertEquals("Should have 2 namespaces", 2, namespaces.size());
+ assertThat(namespaces).as("Should have 2 namespaces").hasSize(2);
Set<String> namespaceNames =
namespaces.stream().map(arr -> arr[0].toString()).collect(Collectors.toSet());
- Assert.assertEquals(
- "Should have default and db namespaces",
- ImmutableSet.of("default", "db"),
- namespaceNames);
+ assertThat(namespaceNames)
+ .as("Should have default and db namespaces")
+ .isEqualTo(ImmutableSet.of("default", "db"));
}
List<Object[]> nestedNamespaces = sql("SHOW NAMESPACES IN %s", fullNamespace);
Set<String> nestedNames =
nestedNamespaces.stream().map(arr -> arr[0].toString()).collect(Collectors.toSet());
- Assert.assertEquals("Should not have nested namespaces", ImmutableSet.of(), nestedNames);
+ assertThat(nestedNames).as("Should not have nested namespaces").isEmpty();
}
- @Test
+ @TestTemplate
public void testCreateNamespaceWithMetadata() {
- Assume.assumeFalse("HadoopCatalog does not support namespace metadata", isHadoopCatalog);
+ assumeThat(isHadoopCatalog).as("HadoopCatalog does not support namespace metadata").isFalse();
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
sql("CREATE NAMESPACE %s WITH PROPERTIES ('prop'='value')", fullNamespace);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
Map<String, String> nsMetadata = validationNamespaceCatalog.loadNamespaceMetadata(NS);
- Assert.assertEquals(
- "Namespace should have expected prop value", "value", nsMetadata.get("prop"));
+ assertThat(nsMetadata.get("prop"))
+ .as("Namespace should have expected prop value")
+ .isEqualTo("value");
}
- @Test
+ @TestTemplate
public void testCreateNamespaceWithComment() {
- Assume.assumeFalse("HadoopCatalog does not support namespace metadata", isHadoopCatalog);
+ assumeThat(isHadoopCatalog).as("HadoopCatalog does not support namespace metadata").isFalse();
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
sql("CREATE NAMESPACE %s COMMENT 'namespace doc'", fullNamespace);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
Map<String, String> nsMetadata = validationNamespaceCatalog.loadNamespaceMetadata(NS);
- Assert.assertEquals(
- "Namespace should have expected comment", "namespace doc", nsMetadata.get("comment"));
+ assertThat(nsMetadata.get("comment"))
+ .as("Namespace should have expected comment")
+ .isEqualTo("namespace doc");
}
- @Test
+ @TestTemplate
public void testCreateNamespaceWithLocation() throws Exception {
- Assume.assumeFalse("HadoopCatalog does not support namespace locations", isHadoopCatalog);
+ assumeThat(isHadoopCatalog).as("HadoopCatalog does not support namespace metadata").isFalse();
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
- File location = temp.newFile();
- Assert.assertTrue(location.delete());
+ File location = File.createTempFile("junit", null, temp.toFile());
+ assertThat(location.delete()).isTrue();
sql("CREATE NAMESPACE %s LOCATION '%s'", fullNamespace, location);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
Map<String, String> nsMetadata = validationNamespaceCatalog.loadNamespaceMetadata(NS);
- Assert.assertEquals(
- "Namespace should have expected location",
- "file:" + location.getPath(),
- nsMetadata.get("location"));
+ assertThat(nsMetadata.get("location"))
+ .as("Namespace should have expected location")
+ .isEqualTo("file:" + location.getPath());
}
- @Test
+ @TestTemplate
public void testSetProperties() {
- Assume.assumeFalse("HadoopCatalog does not support namespace metadata", isHadoopCatalog);
+ assumeThat(isHadoopCatalog).as("HadoopCatalog does not support namespace metadata").isFalse();
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
sql("CREATE NAMESPACE %s", fullNamespace);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
Map<String, String> defaultMetadata = validationNamespaceCatalog.loadNamespaceMetadata(NS);
- Assert.assertFalse(
- "Default metadata should not have custom property", defaultMetadata.containsKey("prop"));
+ assertThat(defaultMetadata)
+ .as("Default metadata should not have custom property")
+ .doesNotContainKey("prop");
sql("ALTER NAMESPACE %s SET PROPERTIES ('prop'='value')", fullNamespace);
Map<String, String> nsMetadata = validationNamespaceCatalog.loadNamespaceMetadata(NS);
- Assert.assertEquals(
- "Namespace should have expected prop value", "value", nsMetadata.get("prop"));
+ assertThat(nsMetadata.get("prop"))
Review Comment:
same as above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark 3.5: Migrate tests in SQL directory to JUnit5 [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #9401:
URL: https://github.com/apache/iceberg/pull/9401#discussion_r1445273981
##########
spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/sql/TestNamespaceSQL.java:
##########
@@ -110,134 +151,156 @@ public void testDropNonEmptyNamespace() {
sql("DROP TABLE %s.table", fullNamespace);
}
- @Test
+ @TestTemplate
public void testListTables() {
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
sql("CREATE NAMESPACE %s", fullNamespace);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
List<Object[]> rows = sql("SHOW TABLES IN %s", fullNamespace);
- Assert.assertEquals("Should not list any tables", 0, rows.size());
+ assertThat(rows).as("Should not list any tables").hasSize(0);
sql("CREATE TABLE %s.table (id bigint) USING iceberg", fullNamespace);
Object[] row = Iterables.getOnlyElement(sql("SHOW TABLES IN %s", fullNamespace));
- Assert.assertEquals("Namespace should match", "db", row[0]);
- Assert.assertEquals("Table name should match", "table", row[1]);
+ assertThat(row[0]).as("Namespace should match").isEqualTo("db");
+ assertThat(row[1]).as("Table name should match").isEqualTo("table");
}
- @Test
+ @TestTemplate
public void testListNamespace() {
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
sql("CREATE NAMESPACE %s", fullNamespace);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
List<Object[]> namespaces = sql("SHOW NAMESPACES IN %s", catalogName);
if (isHadoopCatalog) {
- Assert.assertEquals("Should have 1 namespace", 1, namespaces.size());
+ assertThat(namespaces).as("Should have 1 namespace").hasSize(1);
Set<String> namespaceNames =
namespaces.stream().map(arr -> arr[0].toString()).collect(Collectors.toSet());
- Assert.assertEquals("Should have only db namespace", ImmutableSet.of("db"), namespaceNames);
+ assertThat(namespaceNames)
+ .as("Should have only db namespace")
+ .isEqualTo(ImmutableSet.of("db"));
} else {
- Assert.assertEquals("Should have 2 namespaces", 2, namespaces.size());
+ assertThat(namespaces).as("Should have 2 namespaces").hasSize(2);
Set<String> namespaceNames =
namespaces.stream().map(arr -> arr[0].toString()).collect(Collectors.toSet());
- Assert.assertEquals(
- "Should have default and db namespaces",
- ImmutableSet.of("default", "db"),
- namespaceNames);
+ assertThat(namespaceNames)
+ .as("Should have default and db namespaces")
+ .isEqualTo(ImmutableSet.of("default", "db"));
}
List<Object[]> nestedNamespaces = sql("SHOW NAMESPACES IN %s", fullNamespace);
Set<String> nestedNames =
nestedNamespaces.stream().map(arr -> arr[0].toString()).collect(Collectors.toSet());
- Assert.assertEquals("Should not have nested namespaces", ImmutableSet.of(), nestedNames);
+ assertThat(nestedNames).as("Should not have nested namespaces").isEmpty();
}
- @Test
+ @TestTemplate
public void testCreateNamespaceWithMetadata() {
- Assume.assumeFalse("HadoopCatalog does not support namespace metadata", isHadoopCatalog);
+ assumeThat(isHadoopCatalog).as("HadoopCatalog does not support namespace metadata").isFalse();
- Assert.assertFalse(
- "Namespace should not already exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should not already exist")
+ .isFalse();
sql("CREATE NAMESPACE %s WITH PROPERTIES ('prop'='value')", fullNamespace);
- Assert.assertTrue("Namespace should exist", validationNamespaceCatalog.namespaceExists(NS));
+ assertThat(validationNamespaceCatalog.namespaceExists(NS))
+ .as("Namespace should exist")
+ .isTrue();
Map<String, String> nsMetadata = validationNamespaceCatalog.loadNamespaceMetadata(NS);
- Assert.assertEquals(
- "Namespace should have expected prop value", "value", nsMetadata.get("prop"));
+ assertThat(nsMetadata.get("prop"))
Review Comment:
better to use `.containsEntry()` here (without the `as()`)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org