You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sedona.apache.org by ji...@apache.org on 2024/02/22 03:35:00 UTC

(sedona) branch master updated: [SEDONA-500] Fix failures and data consistency problems when reading multiple shapefiles in one directory (#1250)

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

jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git


The following commit(s) were added to refs/heads/master by this push:
     new 291fd965a [SEDONA-500] Fix failures and data consistency problems when reading multiple shapefiles in one directory (#1250)
291fd965a is described below

commit 291fd965a7c72829082ac7d938704072fe39f69a
Author: Kristin Cowalcijk <bo...@wherobots.com>
AuthorDate: Thu Feb 22 11:34:55 2024 +0800

    [SEDONA-500] Fix failures and data consistency problems when reading multiple shapefiles in one directory (#1250)
---
 .../shapefileParser/shapes/ShapeInputFormat.java           | 14 +++++++++-----
 .../shapefileParser/shapes/ShapefileReaderTest.java        |  3 ++-
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/spark/common/src/main/java/org/apache/sedona/core/formatMapper/shapefileParser/shapes/ShapeInputFormat.java b/spark/common/src/main/java/org/apache/sedona/core/formatMapper/shapefileParser/shapes/ShapeInputFormat.java
index d528b6db9..6c8d26e2d 100644
--- a/spark/common/src/main/java/org/apache/sedona/core/formatMapper/shapefileParser/shapes/ShapeInputFormat.java
+++ b/spark/common/src/main/java/org/apache/sedona/core/formatMapper/shapefileParser/shapes/ShapeInputFormat.java
@@ -101,16 +101,20 @@ public class ShapeInputFormat
                 String filename = FilenameUtils.removeExtension(filePath.getName()).toLowerCase();
                 String suffix = FilenameUtils.getExtension(filePath.getName()).toLowerCase();
 
-                fileSplitPathParts.add(filePath);
-                fileSplitSizeParts.add(filePathSizePair.get(filePath));
+                if (!(suffix.equals(SHX_SUFFIX) || suffix.equals(DBF_SUFFIX) || suffix.equals(SHP_SUFFIX))) {
+                    // Currently we only support .shp, .shx, and .dbf files
+                    continue;
+                }
 
-                if (prevfilename != "" && !prevfilename.equals(filename)
-                        && (suffix.equals(SHX_SUFFIX) || suffix.equals(DBF_SUFFIX) || suffix.equals(SHP_SUFFIX))) {
-                    // compare file name and if it is different then all same filename is into CombileFileSplit
+                if (!prevfilename.isEmpty() && !prevfilename.equals(filename)) {
+                    // compare file name and if it is different then all same filename is into CombineFileSplit
                     splits.add(new CombineFileSplit(fileSplitPathParts.toArray(new Path[0]), Longs.toArray(fileSplitSizeParts)));
                     fileSplitPathParts.clear();
                     fileSplitSizeParts.clear();
                 }
+
+                fileSplitPathParts.add(filePath);
+                fileSplitSizeParts.add(filePathSizePair.get(filePath));
                 prevfilename = filename;
             }
 
diff --git a/spark/common/src/test/java/org/apache/sedona/core/formatMapper/shapefileParser/shapes/ShapefileReaderTest.java b/spark/common/src/test/java/org/apache/sedona/core/formatMapper/shapefileParser/shapes/ShapefileReaderTest.java
index 5d4e61bab..65d145ed5 100644
--- a/spark/common/src/test/java/org/apache/sedona/core/formatMapper/shapefileParser/shapes/ShapefileReaderTest.java
+++ b/spark/common/src/test/java/org/apache/sedona/core/formatMapper/shapefileParser/shapes/ShapefileReaderTest.java
@@ -392,11 +392,12 @@ public class ShapefileReaderTest
     {
         // load shape with geotool.shapefile
         String inputLocation = getShapeFilePath("multipleshapefiles");
-        FeatureCollection<SimpleFeatureType, SimpleFeature> collection = loadFeatures(inputLocation);
         // load shapes with our tool
         SpatialRDD shapeRDD = ShapefileReader.readToGeometryRDD(sc, inputLocation);
         assert (shapeRDD.rawSpatialRDD.getNumPartitions() == 2);
         assertEquals("[STATEFP, COUNTYFP, COUNTYNS, AFFGEOID, GEOID, NAME, LSAD, ALAND, AWATER]", shapeRDD.fieldNames.toString());
+        long count = shapeRDD.rawSpatialRDD.count();
+        assertEquals(3220, count);
     }
 
     /**