Skip to content

Commit

Permalink
refactor getDerivedEvents with overload
Browse files Browse the repository at this point in the history
  • Loading branch information
pranav-super committed Oct 21, 2024
1 parent bcea9a0 commit 312c4bf
Showing 1 changed file with 41 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,39 @@ protected void associateDerivationGroupWithPlan(int planId, String derivationGro
/**
* Get all derived events.
*/
protected List<DerivedEvent> getDerivedEvents(String end) throws SQLException {
protected List<DerivedEvent> getDerivedEvents() throws SQLException {
List<DerivedEvent> results = new ArrayList<>();
try(final var statement = connection.createStatement()) {
var res = statement.executeQuery(
// language=sql
"""
SELECT * FROM merlin.derived_events %s
""".formatted(end)
SELECT * FROM merlin.derived_events;
"""
);
while (res.next()) {
results.add(new DerivedEvent(
res.getString("event_key"),
res.getString("event_type_name"),
res.getString("source_key"),
res.getString("derivation_group_name"),
res.getString("start_time"),
res.getString("DURATION"),
res.getString("source_range"),
res.getString("valid_at")
));
}
}
return results;
}

protected List<DerivedEvent> getDerivedEvents(String dg_name) throws SQLException {
List<DerivedEvent> results = new ArrayList<>();
try(final var statement = connection.createStatement()) {
var res = statement.executeQuery(
// language=sql
"""
SELECT * FROM merlin.derived_events %s;
""".formatted(dg_name)
);
while (res.next()) {
results.add(new DerivedEvent(
Expand Down Expand Up @@ -393,7 +418,7 @@ void testSparseCoverage() throws SQLException {
insertExternalEvent(aE);
insertExternalEvent(bE);

var results = getDerivedEvents("ORDER BY source_key");
var results = getDerivedEvents();

// both ranges should only have a single element and be fully present
final List<DerivedEvent> expectedResults = List.of(
Expand Down Expand Up @@ -472,7 +497,7 @@ void testForwardOverlap() throws SQLException {
insertExternalEvent(aE);
insertExternalEvent(bE);

var results = getDerivedEvents("ORDER BY source_key");
var results = getDerivedEvents();

// both ranges should only have a single element and be fully present
final List<DerivedEvent> expectedResults = List.of(
Expand Down Expand Up @@ -551,7 +576,7 @@ void testBackwardOverlap() throws SQLException {
insertExternalEvent(aE);
insertExternalEvent(bE);

var results = getDerivedEvents("ORDER BY source_key");
var results = getDerivedEvents();

// both ranges should only have a single element and be fully present
final List<DerivedEvent> expectedResults = List.of(
Expand Down Expand Up @@ -644,7 +669,7 @@ void testBackground() throws SQLException {
insertExternalEvent(bE);
insertExternalEvent(cE);

var results = getDerivedEvents("ORDER BY source_key");
var results = getDerivedEvents();

// both ranges should only have a single element and be fully present
final List<DerivedEvent> expectedResults = List.of(
Expand Down Expand Up @@ -807,7 +832,7 @@ void testAmalgamation() throws SQLException {
insertExternalEvent(fE);
insertExternalEvent(gE);

var results = getDerivedEvents("ORDER BY source_key");
var results = getDerivedEvents();

// both ranges should only have a single element and be fully present
final List<DerivedEvent> expectedResults = List.of(
Expand Down Expand Up @@ -934,7 +959,7 @@ void rule1_solitary() throws SQLException {
insertExternalEvent(e);

// ensure the result has the right size and keys
final var results = getDerivedEvents("");
final var results = getDerivedEvents();

// both ranges should only have a single element and be fully present
final List<DerivedEvent> expectedResults = List.of(
Expand Down Expand Up @@ -1008,7 +1033,7 @@ void rule1_bookended() throws SQLException {
insertExternalEvent(after);

// verify the expected keys are included
final var results = getDerivedEvents("ORDER BY source_key");
final var results = getDerivedEvents();

// both ranges should only have a single element and be fully present
final List<DerivedEvent> expectedResults = List.of(
Expand Down Expand Up @@ -1093,7 +1118,7 @@ void rule2() throws SQLException {
insertExternalEvent(b2);

// verify the expected keys
final var results = getDerivedEvents("ORDER BY source_key");
final var results = getDerivedEvents();

// both ranges should only have a single element and be fully present
final List<DerivedEvent> expectedResults = List.of(
Expand Down Expand Up @@ -1190,7 +1215,7 @@ void rule3_basic() throws SQLException {
insertExternalEvent(b2);

// verify the expected keys
final var results = getDerivedEvents("ORDER BY source_key");
final var results = getDerivedEvents();

// both ranges should only have a single element and be fully present
final List<DerivedEvent> expectedResults = List.of(
Expand Down Expand Up @@ -1274,7 +1299,7 @@ void rule3_empty() throws SQLException {
insertExternalSource(B);

// verify expected keys (none)
final var results = getDerivedEvents("ORDER BY source_key");
final var results = getDerivedEvents();

assertEquals(0, results.size());
}
Expand Down Expand Up @@ -1351,7 +1376,7 @@ void rule4() throws SQLException {
insertExternalEvent(e3);

// verify expected keys
final var results = getDerivedEvents("ORDER BY source_key");
final var results = getDerivedEvents();

// both ranges should only have a single element and be fully present
final List<DerivedEvent> expectedResults = List.of(
Expand Down Expand Up @@ -1458,7 +1483,7 @@ void nEventsAtSameTime() throws SQLException {
insertExternalEvent(e3);

// all 3 keys should be present!
var results = getDerivedEvents("ORDER BY start_time, event_key ASC");
var results = getDerivedEvents();

// both ranges should only have a single element and be fully present
final List<DerivedEvent> expectedResults = List.of(
Expand Down Expand Up @@ -1929,7 +1954,7 @@ void superDerivedEvents() throws SQLException {

// check that derived events in our prewritten case has the correct keys
// verify everything is present
var results = getDerivedEvents("ORDER BY source_key");
var results = getDerivedEvents();

// both ranges should only have a single element and be fully present
List<DerivedEvent> expectedResults = List.of(
Expand Down

0 comments on commit 312c4bf

Please sign in to comment.