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

don't silently ignore invalid timestamps supplied to mapreducer #469

Merged
merged 3 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ Changelog
* update jts dependency to version 1.18.2
* update ignite dependency to version 2.14.0 ([#459], [#467])
* add natural order to `OSHDBTag` ([#454])
* throw exception when invalid timestamp strings are supplied to the MapReducer ([#260])

[#260]: https://github.com/GIScience/oshdb/issues/260
[#419]: https://github.com/GIScience/oshdb/pull/419
[#433]: https://github.com/GIScience/oshdb/issues/433
[#438]: https://github.com/GIScience/oshdb/pull/438
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,17 +413,13 @@ public MapReducer<X> timestamps(String isoDateStart, String isoDateEnd) {
public MapReducer<X> timestamps(
String isoDateFirst, String isoDateSecond, String... isoDateMore) {
SortedSet<OSHDBTimestamp> timestamps = new TreeSet<>();
try {
timestamps.add(
new OSHDBTimestamp(IsoDateTimeParser.parseIsoDateTime(isoDateFirst).toEpochSecond()));
timestamps.add(
new OSHDBTimestamp(IsoDateTimeParser.parseIsoDateTime(isoDateFirst).toEpochSecond()));
timestamps.add(
new OSHDBTimestamp(IsoDateTimeParser.parseIsoDateTime(isoDateSecond).toEpochSecond()));
for (String isoDate : isoDateMore) {
timestamps.add(
new OSHDBTimestamp(IsoDateTimeParser.parseIsoDateTime(isoDateSecond).toEpochSecond()));
for (String isoDate : isoDateMore) {
timestamps.add(
new OSHDBTimestamp(IsoDateTimeParser.parseIsoDateTime(isoDate).toEpochSecond()));
}
} catch (Exception e) {
LOG.error("unable to parse ISO date string: " + e.getMessage());
new OSHDBTimestamp(IsoDateTimeParser.parseIsoDateTime(isoDate).toEpochSecond()));
}
return this.timestamps(() -> timestamps);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.time.format.DateTimeParseException;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -17,6 +18,7 @@
import org.heigit.ohsome.oshdb.util.function.SerializableFunction;
import org.heigit.ohsome.oshdb.util.mappable.OSMContribution;
import org.heigit.ohsome.oshdb.util.mappable.OSMEntitySnapshot;
import org.heigit.ohsome.oshdb.util.time.OSHDBTimestampIllegalArgumentException;
import org.heigit.ohsome.oshdb.util.time.OSHDBTimestamps;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -256,4 +258,33 @@ private static <T> SerializableFunction<T, T> delay(int ms) {
};
}

@Test
void testInvalidTimestamps() {
assertThrows(DateTimeParseException.class, this::invalidTimestamps1);
assertThrows(OSHDBTimestampIllegalArgumentException.class, this::invalidTimestamps2);
}

private void invalidTimestamps1() throws Exception {
// contribution view query
var ignored = createMapReducerOSMContribution()
.timestamps("invalid1", "invalid2")
.map(OSMContribution::getContributorUserId)
.uniq();
// snapshot view query
var ignored2 = createMapReducerOSMEntitySnapshot()
.timestamps("invalid")
.count();
}

@SuppressWarnings("UnusedAssignment")
private void invalidTimestamps2() throws Exception {
// invalid time zone
var ignored = createMapReducerOSMEntitySnapshot()
.timestamps("2020-01-01T00:00:00+00")
.count();
// invalid sign
ignored = createMapReducerOSMEntitySnapshot()
.timestamps("-2020-01-01T00:00:00Z")
.count();
}
}