-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Maciej Obuchowski <[email protected]>
- Loading branch information
1 parent
53460fa
commit f1868f8
Showing
20 changed files
with
398 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package marquez.api; | ||
|
||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON; | ||
|
||
import com.codahale.metrics.annotation.ExceptionMetered; | ||
import com.codahale.metrics.annotation.ResponseMetered; | ||
import com.codahale.metrics.annotation.Timed; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import java.util.List; | ||
import javax.validation.constraints.Min; | ||
import javax.ws.rs.DefaultValue; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.Response; | ||
import lombok.NonNull; | ||
import lombok.Value; | ||
import marquez.service.ServiceFactory; | ||
|
||
@Path("/api/v1") | ||
public class EventResource extends BaseResource { | ||
public EventResource(@NonNull final ServiceFactory serviceFactory) { | ||
super(serviceFactory); | ||
} | ||
|
||
@Timed | ||
@ResponseMetered | ||
@ExceptionMetered | ||
@GET | ||
@Path("/events") | ||
@Produces(APPLICATION_JSON) | ||
public Response get( | ||
@QueryParam("limit") @DefaultValue("100") @Min(value = 0) int limit, | ||
@QueryParam("offset") @DefaultValue("0") @Min(value = 0) int offset) { | ||
final List<JsonNode> events = eventService.getAll(limit, offset); | ||
return Response.ok(new Events(events)).build(); | ||
} | ||
|
||
@Timed | ||
@ResponseMetered | ||
@ExceptionMetered | ||
@GET | ||
@Path("/events/{namespace}") | ||
@Produces(APPLICATION_JSON) | ||
public Response getByNamespace( | ||
@PathParam("namespace") String namespace, | ||
@QueryParam("limit") @DefaultValue("100") @Min(value = 0) int limit, | ||
@QueryParam("offset") @DefaultValue("0") @Min(value = 0) int offset) { | ||
final List<JsonNode> event = eventService.getByNamespace(namespace, limit, offset); | ||
return Response.ok(new Events(event)).build(); | ||
} | ||
|
||
@Value | ||
static class Events { | ||
@NonNull | ||
@JsonProperty("events") | ||
List<JsonNode> value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package marquez.db; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import java.util.List; | ||
import marquez.db.mappers.RawLineageEventMapper; | ||
import org.jdbi.v3.sqlobject.config.RegisterRowMapper; | ||
import org.jdbi.v3.sqlobject.customizer.Bind; | ||
import org.jdbi.v3.sqlobject.statement.SqlQuery; | ||
|
||
@RegisterRowMapper(RawLineageEventMapper.class) | ||
public interface EventDao extends BaseDao { | ||
|
||
@SqlQuery( | ||
""" | ||
SELECT event | ||
FROM lineage_events | ||
ORDER BY event_time DESC | ||
LIMIT :limit | ||
OFFSET :offset""") | ||
List<JsonNode> getAll(int limit, int offset); | ||
|
||
/** | ||
* This is a "hack" to get inputs/outputs namespace from jsonb column: <a | ||
* href="https://github.com/jdbi/jdbi/issues/1510#issuecomment-485423083">explanation</a> | ||
*/ | ||
@SqlQuery( | ||
""" | ||
SELECT le.event | ||
FROM lineage_events le, jsonb_array_elements(coalesce(le.event -> 'inputs', '[]'::jsonb) || coalesce(le.event -> 'outputs', '[]'::jsonb)) AS ds | ||
WHERE le.job_namespace = :namespace | ||
OR ds ->> 'namespace' = :namespace | ||
ORDER BY event_time DESC | ||
LIMIT :limit | ||
OFFSET :offset""") | ||
List<JsonNode> getByNamespace( | ||
@Bind("namespace") String namespace, @Bind("limit") int limit, @Bind("offset") int offset); | ||
} |
30 changes: 30 additions & 0 deletions
30
api/src/main/java/marquez/db/mappers/RawLineageEventMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package marquez.db.mappers; | ||
|
||
import static marquez.db.Columns.stringOrThrow; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import marquez.common.Utils; | ||
import marquez.db.Columns; | ||
import org.jdbi.v3.core.mapper.RowMapper; | ||
import org.jdbi.v3.core.statement.StatementContext; | ||
|
||
@Slf4j | ||
public class RawLineageEventMapper implements RowMapper<JsonNode> { | ||
@Override | ||
public JsonNode map(ResultSet rs, StatementContext ctx) throws SQLException { | ||
String rawEvent = stringOrThrow(rs, Columns.EVENT); | ||
|
||
try { | ||
ObjectMapper mapper = Utils.getMapper(); | ||
return mapper.readTree(rawEvent); | ||
} catch (JsonProcessingException e) { | ||
log.error("Failed to process json", e); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package marquez.service; | ||
|
||
import lombok.NonNull; | ||
import marquez.db.BaseDao; | ||
|
||
public class EventService extends DelegatingDaos.DelegatingEventDao { | ||
public EventService(@NonNull BaseDao baseDao) { | ||
super(baseDao.createEventDao()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
api/src/main/resources/marquez/db/migration/V46__add_lineage_event_indexes.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE INDEX lineage_events_event_time | ||
on lineage_events(event_time DESC); | ||
|
||
CREATE INDEX lineage_events_namespace_event_time | ||
on lineage_events(job_namespace, event_time DESC); |
Oops, something went wrong.