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

Lineage events paging update #2577

Merged
merged 7 commits into from
Aug 10, 2023
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
13 changes: 9 additions & 4 deletions api/src/main/java/marquez/api/OpenLineageResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,25 @@ public Response getLineageEvents(
@QueryParam("before") @DefaultValue("2030-01-01T00:00:00+00:00") ZonedDateTimeParam before,
@QueryParam("after") @DefaultValue("1970-01-01T00:00:00+00:00") ZonedDateTimeParam after,
@QueryParam("sortDirection") @DefaultValue("desc") SortDirection sortDirection,
@QueryParam("limit") @DefaultValue("100") @Min(value = 0) int limit) {
@QueryParam("limit") @DefaultValue("100") @Min(value = 0) int limit,
@QueryParam("offset") @DefaultValue("0") @Min(value = 0) int offset) {
List<LineageEvent> events = Collections.emptyList();
switch (sortDirection) {
case DESC -> events =
openLineageDao.getAllLineageEventsDesc(before.get(), after.get(), limit);
case ASC -> events = openLineageDao.getAllLineageEventsAsc(before.get(), after.get(), limit);
openLineageDao.getAllLineageEventsDesc(before.get(), after.get(), limit, offset);
case ASC -> events =
openLineageDao.getAllLineageEventsAsc(before.get(), after.get(), limit, offset);
}
return Response.ok(new Events(events)).build();
int totalCount = openLineageDao.getAllLineageTotalCount(before.get(), after.get());
return Response.ok(new Events(events, totalCount)).build();
}

@Value
static class Events {
@NonNull
@JsonProperty("events")
List<LineageEvent> value;

int totalCount;
}
}
18 changes: 14 additions & 4 deletions api/src/main/java/marquez/db/OpenLineageDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ void createLineageEvent(
WHERE (le.event_time < :before
AND le.event_time >= :after)
ORDER BY le.event_time DESC
LIMIT :limit""")
List<LineageEvent> getAllLineageEventsDesc(ZonedDateTime before, ZonedDateTime after, int limit);
LIMIT :limit OFFSET :offset""")
List<LineageEvent> getAllLineageEventsDesc(
ZonedDateTime before, ZonedDateTime after, int limit, int offset);

@SqlQuery(
"""
Expand All @@ -113,8 +114,17 @@ void createLineageEvent(
WHERE (le.event_time < :before
AND le.event_time >= :after)
ORDER BY le.event_time ASC
LIMIT :limit""")
List<LineageEvent> getAllLineageEventsAsc(ZonedDateTime before, ZonedDateTime after, int limit);
LIMIT :limit OFFSET :offset""")
List<LineageEvent> getAllLineageEventsAsc(
ZonedDateTime before, ZonedDateTime after, int limit, int offset);

@SqlQuery(
"""
SELECT count(*)
FROM lineage_events le
WHERE (le.event_time < :before
AND le.event_time >= :after)""")
int getAllLineageTotalCount(ZonedDateTime before, ZonedDateTime after);

default UpdateLineageRow updateMarquezModel(LineageEvent event, ObjectMapper mapper) {
UpdateLineageRow updateLineageRow = updateBaseMarquezModel(event, mapper);
Expand Down
4 changes: 4 additions & 0 deletions spec/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ paths:
- $ref: '#/components/parameters/before'
- $ref: '#/components/parameters/after'
- $ref: '#/components/parameters/limit'
- $ref: '#/components/parameters/offset'
summary: List all received OpenLineage events.
description: Returns a list of OpenLineage events, sorted in direction of passed sort parameter. By default it is desc.
tags:
Expand Down Expand Up @@ -945,6 +946,9 @@ components:
type: array
items:
$ref: '#/components/schemas/LineageEvent'
totalCount:
type: number
description: The total number of events returned matching our conditions.

CreatedSource:
type: object
Expand Down
Loading