use of io.cdap.cdap.proto.metadata.lineage.FieldLineageSummary in project cdap by caskdata.
the class LineageHTTPHandler method datasetFieldLineageSummary.
/**
* Get the field level lineage about the specified field in one dataset.
*
* @param field the field name to compute field level lineage
* @param directionStr the direction to compute the field level lineage, can be INCOMING, OUTGOING or BOTH
* @param startStr the start time string, it can be a specific timestamp in milliseconds or a relative time,
* using now and times added to it.
* @param endStr the end time string, it can be a specific timestamp in milliseconds or a relative time,
* using now and times added to it.
*/
@GET
@Path("/namespaces/{namespace-id}/datasets/{dataset-id}/lineage/fields/{field-name}")
public void datasetFieldLineageSummary(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("dataset-id") String datasetId, @PathParam("field-name") String field, @QueryParam("direction") String directionStr, @QueryParam("start") String startStr, @QueryParam("end") String endStr) throws Exception {
accessEnforcer.enforce(new DatasetId(namespaceId, datasetId), authenticationContext.getPrincipal(), StandardPermission.GET);
TimeRange range = parseRange(startStr, endStr);
Constants.FieldLineage.Direction direction = parseDirection(directionStr);
EndPointField endPointField = new EndPointField(EndPoint.of(namespaceId, datasetId), field);
FieldLineageSummary summary = fieldLineageAdmin.getFieldLineage(direction, endPointField, range.getStart(), range.getEnd());
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(summary));
}
use of io.cdap.cdap.proto.metadata.lineage.FieldLineageSummary in project cdap by caskdata.
the class FieldLineageAdminTest method testSummary.
@Test
public void testSummary() {
FieldLineageAdmin fieldLineageAdmin = new FieldLineageAdmin(new FakeFieldLineageReader(Collections.emptySet(), summary(), Collections.emptySet()), metadataAdmin);
EndPoint endPoint = EndPoint.of("ns", "file");
DatasetField datasetField = new DatasetField(new DatasetId("ns", "file"), new HashSet<>(Arrays.asList("a", "b", "c")));
DatasetField anotherDatasetField = new DatasetField(new DatasetId("ns", "anotherfile"), new HashSet<>(Arrays.asList("x", "y", "z")));
Set<DatasetField> expected = new HashSet<>();
expected.add(datasetField);
expected.add(anotherDatasetField);
// input args to the getFieldLineage below does not matter since data returned is mocked
FieldLineageSummary summary = fieldLineageAdmin.getFieldLineage(Constants.FieldLineage.Direction.INCOMING, new EndPointField(endPoint, "somefield"), 0, Long.MAX_VALUE);
Assert.assertEquals(expected, summary.getIncoming());
Assert.assertNull(summary.getOutgoing());
summary = fieldLineageAdmin.getFieldLineage(Constants.FieldLineage.Direction.OUTGOING, new EndPointField(endPoint, "somefield"), 0, Long.MAX_VALUE);
Assert.assertEquals(expected, summary.getOutgoing());
Assert.assertNull(summary.getIncoming());
summary = fieldLineageAdmin.getFieldLineage(Constants.FieldLineage.Direction.BOTH, new EndPointField(endPoint, "somefield"), 0, Long.MAX_VALUE);
Assert.assertEquals(expected, summary.getOutgoing());
Assert.assertEquals(expected, summary.getIncoming());
}
Aggregations