Java Code Examples for org.apache.nifi.provenance.ProvenanceEventRecord#getTransitUri()

The following examples show how to use org.apache.nifi.provenance.ProvenanceEventRecord#getTransitUri() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AwsS3Directory.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public DataSetRefs analyze(AnalysisContext context, ProvenanceEventRecord event) {
    final String transitUri = event.getTransitUri();
    if (transitUri == null) {
        return null;
    }

    final String directoryUri;
    if (StringUtils.countMatches(transitUri, '/') > 3) {
        // directory exists => drop last '/' and the file name
        directoryUri = transitUri.substring(0, transitUri.lastIndexOf('/'));
    } else {
        // no directory => keep last '/', drop only the file name
        directoryUri = transitUri.substring(0, transitUri.lastIndexOf('/') + 1);
    }
    final URI uri = parseUri(directoryUri);

    final String namespace = context.getNamespaceResolver().fromHostNames(uri.getHost());

    final Referenceable ref = createDirectoryRef(uri, namespace);

    return singleDataSetRef(event.getComponentId(), event.getEventType(), ref);
}
 
Example 2
Source File: HBaseTable.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public DataSetRefs analyze(AnalysisContext context, ProvenanceEventRecord event) {

    final String transitUri = event.getTransitUri();
    final Matcher uriMatcher = URI_PATTERN.matcher(transitUri);
    if (!uriMatcher.matches()) {
        logger.warn("Unexpected transit URI: {}", new Object[]{transitUri});
        return null;
    }

    final Referenceable ref = new Referenceable(TYPE);
    final String[] hostNames = splitHostNames(uriMatcher.group(1));
    final String namespace = context.getNamespaceResolver().fromHostNames(hostNames);

    final String tableName = uriMatcher.group(2);
    ref.set(ATTR_NAME, tableName);
    ref.set(ATTR_QUALIFIED_NAME, toQualifiedName(namespace, tableName));
    // TODO: 'uri' is a mandatory attribute, but what should we set?
    ref.set(ATTR_URI, transitUri);

    return singleDataSetRef(event.getComponentId(), event.getEventType(), ref);
}
 
Example 3
Source File: PutHiveStreaming.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public DataSetRefs analyze(AnalysisContext context, ProvenanceEventRecord event) {
    if (event.getTransitUri() == null) {
        return null;
    }

    final URI uri = parseUri(event.getTransitUri());
    final String namespace = context.getNamespaceResolver().fromHostNames(uri.getHost());
    final Set<Tuple<String, String>> outputTables = parseTableNames(null, event.getAttribute(ATTR_OUTPUT_TABLES));
    if (outputTables.isEmpty()) {
        return null;
    }

    final DataSetRefs refs = new DataSetRefs(event.getComponentId());
    outputTables.forEach(tableName -> {
        final Referenceable ref = createTableRef(namespace, tableName);
        refs.addOutput(ref);
    });
    return refs;
}
 
Example 4
Source File: KafkaTopic.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public DataSetRefs analyze(AnalysisContext context, ProvenanceEventRecord event) {
    final Referenceable ref = new Referenceable(TYPE);

    final String transitUri = event.getTransitUri();
    if (transitUri == null) {
        return null;
    }

    final Matcher uriMatcher = URI_PATTERN.matcher(transitUri);
    if (!uriMatcher.matches()) {
        logger.warn("Unexpected transit URI: {}", new Object[]{transitUri});
        return null;
    }

    final String[] hostNames = splitHostNames(uriMatcher.group(1));
    final String namespace = context.getNamespaceResolver().fromHostNames(hostNames);

    final String topicName = uriMatcher.group(2);

    ref.set(ATTR_NAME, topicName);
    ref.set(ATTR_TOPIC, topicName);
    ref.set(ATTR_QUALIFIED_NAME, toQualifiedName(namespace, topicName));
    ref.set(ATTR_URI, transitUri);

    return singleDataSetRef(event.getComponentId(), event.getEventType(), ref);
}
 
Example 5
Source File: Hive2JDBC.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public DataSetRefs analyze(AnalysisContext context, ProvenanceEventRecord event) {

    // Replace the colon so that the schema in the URI can be parsed correctly.
    final String transitUri = event.getTransitUri();
    if (transitUri == null) {
        return null;
    }

    final Matcher uriMatcher = URI_PATTERN.matcher(transitUri);
    if (!uriMatcher.matches()) {
        logger.warn("Unexpected transit URI: {}", new Object[]{transitUri});
        return null;
    }

    final String namespace = context.getNamespaceResolver().fromHostNames(splitHostNames(uriMatcher.group(1)));
    String connectedDatabaseName = null;
    if (uriMatcher.groupCount() > 1) {
        // Try to find connected database name from connection parameters.
        final String[] connectionParams = uriMatcher.group(2).split(";");
        connectedDatabaseName = connectionParams[0];
    }

    if (StringUtils.isEmpty(connectedDatabaseName)) {
        // If not found, then use "default".
        connectedDatabaseName = "default";
    }

    final Set<Tuple<String, String>> inputTables = parseTableNames(connectedDatabaseName, event.getAttribute(ATTR_INPUT_TABLES));
    final Set<Tuple<String, String>> outputTables = parseTableNames(connectedDatabaseName, event.getAttribute(ATTR_OUTPUT_TABLES));

    if (inputTables.isEmpty() && outputTables.isEmpty()) {
        // If input/output tables are unknown, create database level lineage.
        // Handle case insensitivity of database and table names in Hive: send names uniformly in lower case
        return getDatabaseRef(event.getComponentId(), event.getEventType(), namespace, connectedDatabaseName.toLowerCase());
    }

    final DataSetRefs refs = new DataSetRefs(event.getComponentId());
    addRefs(refs, true, namespace, inputTables);
    addRefs(refs, false, namespace, outputTables);
    return refs;
}