This is an automated email from the ASF dual-hosted git repository.

russellspitzer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/main by this push:
     new 4e62b58f04 AWS, Core, Dell, Spark: Use Strings to verify null and 
empty string (#9090)
4e62b58f04 is described below

commit 4e62b58f04aba4ccc2a2a846494b478d3b03f58f
Author: Andre Luis Anastacio <[email protected]>
AuthorDate: Mon Nov 27 21:41:32 2023 -0300

    AWS, Core, Dell, Spark: Use Strings to verify null and empty string (#9090)
    
    * AWS: Use !Strings.isNullOrEmpty to verify null and empty string
    
    * Core: Use !Strings.isNullOrEmpty to verify null and empty string
    
    * Dell: Use !Strings.isNullOrEmpty to verify null and empty string
    
    * Spark 3.2: Use !.isEmpty() instead of .length() > 0
    
    * Spark 3.3: Use !.isEmpty() instead of .length() > 0
---
 .../main/java/org/apache/iceberg/aws/dynamodb/DynamoDbCatalog.java  | 3 ++-
 aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java      | 6 +++---
 core/src/main/java/org/apache/iceberg/hadoop/HadoopCatalog.java     | 3 ++-
 core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java         | 3 ++-
 core/src/main/java/org/apache/iceberg/util/LocationUtil.java        | 4 ++--
 dell/src/main/java/org/apache/iceberg/dell/ecs/EcsCatalog.java      | 3 ++-
 .../iceberg/spark/extensions/SparkRowLevelOperationsTestBase.java   | 2 +-
 .../iceberg/spark/extensions/SparkRowLevelOperationsTestBase.java   | 2 +-
 8 files changed, 15 insertions(+), 11 deletions(-)

diff --git 
a/aws/src/main/java/org/apache/iceberg/aws/dynamodb/DynamoDbCatalog.java 
b/aws/src/main/java/org/apache/iceberg/aws/dynamodb/DynamoDbCatalog.java
index a957b3096a..fc1479c3a0 100644
--- a/aws/src/main/java/org/apache/iceberg/aws/dynamodb/DynamoDbCatalog.java
+++ b/aws/src/main/java/org/apache/iceberg/aws/dynamodb/DynamoDbCatalog.java
@@ -49,6 +49,7 @@ import org.apache.iceberg.io.FileIO;
 import 
org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
 import org.apache.iceberg.relocated.com.google.common.base.Joiner;
 import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.base.Strings;
 import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
 import org.apache.iceberg.relocated.com.google.common.collect.Lists;
 import org.apache.iceberg.relocated.com.google.common.collect.Maps;
@@ -130,7 +131,7 @@ public class DynamoDbCatalog extends BaseMetastoreCatalog
   void initialize(
       String name, String path, AwsProperties properties, DynamoDbClient 
client, FileIO io) {
     Preconditions.checkArgument(
-        path != null && path.length() > 0,
+        !Strings.isNullOrEmpty(path),
         "Cannot initialize DynamoDbCatalog because warehousePath must not be 
null or empty");
 
     this.catalogName = name;
diff --git a/aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java 
b/aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java
index 0a75821208..6e95379c1d 100644
--- a/aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java
+++ b/aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java
@@ -55,6 +55,7 @@ import org.apache.iceberg.io.CloseableGroup;
 import org.apache.iceberg.io.FileIO;
 import 
org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
 import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.base.Strings;
 import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
 import org.apache.iceberg.relocated.com.google.common.collect.Lists;
 import org.apache.iceberg.relocated.com.google.common.collect.Maps;
@@ -189,8 +190,7 @@ public class GlueCatalog extends BaseMetastoreCatalog
     this.catalogName = name;
     this.awsProperties = properties;
     this.s3FileIOProperties = s3Properties;
-    this.warehousePath =
-        (path != null && path.length() > 0) ? 
LocationUtil.stripTrailingSlash(path) : null;
+    this.warehousePath = Strings.isNullOrEmpty(path) ? null : 
LocationUtil.stripTrailingSlash(path);
     this.glue = client;
     this.lockManager = lock;
 
@@ -286,7 +286,7 @@ public class GlueCatalog extends BaseMetastoreCatalog
     }
 
     ValidationException.check(
-        warehousePath != null && warehousePath.length() > 0,
+        !Strings.isNullOrEmpty(warehousePath),
         "Cannot derive default warehouse location, warehouse path must not be 
null or empty");
 
     return String.format(
diff --git a/core/src/main/java/org/apache/iceberg/hadoop/HadoopCatalog.java 
b/core/src/main/java/org/apache/iceberg/hadoop/HadoopCatalog.java
index 25e6994d0b..166551fe55 100644
--- a/core/src/main/java/org/apache/iceberg/hadoop/HadoopCatalog.java
+++ b/core/src/main/java/org/apache/iceberg/hadoop/HadoopCatalog.java
@@ -54,6 +54,7 @@ import org.apache.iceberg.io.FileIO;
 import org.apache.iceberg.relocated.com.google.common.base.Joiner;
 import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
 import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.base.Strings;
 import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
 import org.apache.iceberg.relocated.com.google.common.collect.Lists;
 import org.apache.iceberg.relocated.com.google.common.collect.Sets;
@@ -104,7 +105,7 @@ public class HadoopCatalog extends BaseMetastoreCatalog
     this.catalogProperties = ImmutableMap.copyOf(properties);
     String inputWarehouseLocation = 
properties.get(CatalogProperties.WAREHOUSE_LOCATION);
     Preconditions.checkArgument(
-        inputWarehouseLocation != null && inputWarehouseLocation.length() > 0,
+        !Strings.isNullOrEmpty(inputWarehouseLocation),
         "Cannot initialize HadoopCatalog because warehousePath must not be 
null or empty");
 
     this.catalogName = name;
diff --git a/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java 
b/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java
index c45df884bd..314595dd02 100644
--- a/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java
+++ b/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java
@@ -53,6 +53,7 @@ import org.apache.iceberg.hadoop.Configurable;
 import org.apache.iceberg.io.FileIO;
 import org.apache.iceberg.relocated.com.google.common.base.Joiner;
 import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.base.Strings;
 import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
 import org.apache.iceberg.relocated.com.google.common.collect.Lists;
 import org.apache.iceberg.relocated.com.google.common.collect.Maps;
@@ -99,7 +100,7 @@ public class JdbcCatalog extends BaseMetastoreCatalog
 
     String inputWarehouseLocation = 
properties.get(CatalogProperties.WAREHOUSE_LOCATION);
     Preconditions.checkArgument(
-        inputWarehouseLocation != null && inputWarehouseLocation.length() > 0,
+        !Strings.isNullOrEmpty(inputWarehouseLocation),
         "Cannot initialize JDBCCatalog because warehousePath must not be null 
or empty");
 
     this.warehouseLocation = 
LocationUtil.stripTrailingSlash(inputWarehouseLocation);
diff --git a/core/src/main/java/org/apache/iceberg/util/LocationUtil.java 
b/core/src/main/java/org/apache/iceberg/util/LocationUtil.java
index 8eca0051cc..1927861557 100644
--- a/core/src/main/java/org/apache/iceberg/util/LocationUtil.java
+++ b/core/src/main/java/org/apache/iceberg/util/LocationUtil.java
@@ -19,13 +19,13 @@
 package org.apache.iceberg.util;
 
 import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.base.Strings;
 
 public class LocationUtil {
   private LocationUtil() {}
 
   public static String stripTrailingSlash(String path) {
-    Preconditions.checkArgument(
-        path != null && path.length() > 0, "path must not be null or empty");
+    Preconditions.checkArgument(!Strings.isNullOrEmpty(path), "path must not 
be null or empty");
 
     String result = path;
     while (result.endsWith("/")) {
diff --git a/dell/src/main/java/org/apache/iceberg/dell/ecs/EcsCatalog.java 
b/dell/src/main/java/org/apache/iceberg/dell/ecs/EcsCatalog.java
index bf16e1b07f..f951c8c937 100644
--- a/dell/src/main/java/org/apache/iceberg/dell/ecs/EcsCatalog.java
+++ b/dell/src/main/java/org/apache/iceberg/dell/ecs/EcsCatalog.java
@@ -55,6 +55,7 @@ import org.apache.iceberg.hadoop.Configurable;
 import org.apache.iceberg.io.CloseableGroup;
 import org.apache.iceberg.io.FileIO;
 import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.base.Strings;
 import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
 import org.apache.iceberg.relocated.com.google.common.collect.Lists;
 import org.apache.iceberg.relocated.com.google.common.io.ByteStreams;
@@ -99,7 +100,7 @@ public class EcsCatalog extends BaseMetastoreCatalog
     this.catalogProperties = ImmutableMap.copyOf(properties);
     String inputWarehouseLocation = 
properties.get(CatalogProperties.WAREHOUSE_LOCATION);
     Preconditions.checkArgument(
-        inputWarehouseLocation != null && inputWarehouseLocation.length() > 0,
+        !Strings.isNullOrEmpty(inputWarehouseLocation),
         "Cannot initialize EcsCatalog because warehousePath must not be null 
or empty");
 
     this.catalogName = name;
diff --git 
a/spark/v3.2/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/SparkRowLevelOperationsTestBase.java
 
b/spark/v3.2/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/SparkRowLevelOperationsTestBase.java
index 633b2ee431..e53c79f6c9 100644
--- 
a/spark/v3.2/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/SparkRowLevelOperationsTestBase.java
+++ 
b/spark/v3.2/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/SparkRowLevelOperationsTestBase.java
@@ -212,7 +212,7 @@ public abstract class SparkRowLevelOperationsTestBase 
extends SparkExtensionsTes
   private Dataset<Row> toDS(String schema, String jsonData) {
     List<String> jsonRows =
         Arrays.stream(jsonData.split("\n"))
-            .filter(str -> str.trim().length() > 0)
+            .filter(str -> !str.trim().isEmpty())
             .collect(Collectors.toList());
     Dataset<String> jsonDS = spark.createDataset(jsonRows, Encoders.STRING());
 
diff --git 
a/spark/v3.3/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/SparkRowLevelOperationsTestBase.java
 
b/spark/v3.3/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/SparkRowLevelOperationsTestBase.java
index ceb6b6aad8..9a1257ba39 100644
--- 
a/spark/v3.3/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/SparkRowLevelOperationsTestBase.java
+++ 
b/spark/v3.3/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/SparkRowLevelOperationsTestBase.java
@@ -225,7 +225,7 @@ public abstract class SparkRowLevelOperationsTestBase 
extends SparkExtensionsTes
   private Dataset<Row> toDS(String schema, String jsonData) {
     List<String> jsonRows =
         Arrays.stream(jsonData.split("\n"))
-            .filter(str -> str.trim().length() > 0)
+            .filter(str -> !str.trim().isEmpty())
             .collect(Collectors.toList());
     Dataset<String> jsonDS = spark.createDataset(jsonRows, Encoders.STRING());
 

Reply via email to