Search in sources :

Example 1 with JDBCTableCatalog

use of org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCTableCatalog in project OpenLineage by OpenLineage.

the class JdbcHandler method getDatasetIdentifier.

@SneakyThrows
@Override
public DatasetIdentifier getDatasetIdentifier(SparkSession session, TableCatalog tableCatalog, Identifier identifier, Map<String, String> properties) {
    JDBCTableCatalog catalog = (JDBCTableCatalog) tableCatalog;
    JDBCOptions options = (JDBCOptions) FieldUtils.readField(catalog, "options", true);
    String name = Stream.concat(Arrays.stream(identifier.namespace()), Stream.of(identifier.name())).collect(Collectors.joining("."));
    return new DatasetIdentifier(name, JdbcUtils.sanitizeJdbcUrl(options.url()));
}
Also used : JDBCTableCatalog(org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCTableCatalog) JDBCOptions(org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions) DatasetIdentifier(io.openlineage.spark.agent.util.DatasetIdentifier) SneakyThrows(lombok.SneakyThrows)

Example 2 with JDBCTableCatalog

use of org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCTableCatalog in project OpenLineage by OpenLineage.

the class JdbcHandlerTest method testGetDatasetIdentifier.

@Test
@SneakyThrows
public void testGetDatasetIdentifier() {
    JdbcHandler handler = new JdbcHandler();
    JDBCTableCatalog tableCatalog = new JDBCTableCatalog();
    JDBCOptions options = mock(JDBCOptions.class);
    when(options.url()).thenReturn("jdbc:postgresql://postgreshost:5432");
    FieldUtils.writeField(tableCatalog, "options", options, true);
    DatasetIdentifier datasetIdentifier = handler.getDatasetIdentifier(mock(SparkSession.class), tableCatalog, Identifier.of(new String[] { "database", "schema" }, "table"), new HashMap<>());
    assertEquals("database.schema.table", datasetIdentifier.getName());
    assertEquals("postgresql://postgreshost:5432", datasetIdentifier.getNamespace());
}
Also used : JDBCTableCatalog(org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCTableCatalog) JDBCOptions(org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions) SparkSession(org.apache.spark.sql.SparkSession) DatasetIdentifier(io.openlineage.spark.agent.util.DatasetIdentifier) Test(org.junit.jupiter.api.Test) SneakyThrows(lombok.SneakyThrows)

Aggregations

DatasetIdentifier (io.openlineage.spark.agent.util.DatasetIdentifier)2 SneakyThrows (lombok.SneakyThrows)2 JDBCOptions (org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions)2 JDBCTableCatalog (org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCTableCatalog)2 SparkSession (org.apache.spark.sql.SparkSession)1 Test (org.junit.jupiter.api.Test)1