Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SEDONA-500] Fix failures and data consistency problems when reading multiple shapefiles in one directory #1250

Merged
merged 1 commit into from
Feb 22, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,20 @@ public List<InputSplit> getSplits(JobContext job)
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,12 @@ public void testReadMultipleShapeFilesByMultiPartitions()
{
// 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);
}

/**
Expand Down
Loading