Search in sources :

Example 1 with DeltaTableV2

use of org.apache.spark.sql.delta.catalog.DeltaTableV2 in project OpenLineage by OpenLineage.

the class DeltaHandler method getDatasetVersion.

@SneakyThrows
public Optional<String> getDatasetVersion(TableCatalog tableCatalog, Identifier identifier, Map<String, String> properties) {
    DeltaCatalog deltaCatalog = (DeltaCatalog) tableCatalog;
    Table table = deltaCatalog.loadTable(identifier);
    if (table instanceof DeltaTableV2) {
        DeltaTableV2 deltaTable = (DeltaTableV2) table;
        return Optional.of(Long.toString(deltaTable.snapshot().version()));
    }
    return Optional.empty();
}
Also used : DeltaTableV2(org.apache.spark.sql.delta.catalog.DeltaTableV2) DeltaCatalog(org.apache.spark.sql.delta.catalog.DeltaCatalog) Table(org.apache.spark.sql.connector.catalog.Table) SneakyThrows(lombok.SneakyThrows)

Example 2 with DeltaTableV2

use of org.apache.spark.sql.delta.catalog.DeltaTableV2 in project OpenLineage by OpenLineage.

the class DeltaHandlerTest method testGetVersionString.

@Test
public void testGetVersionString() {
    DeltaCatalog deltaCatalog = mock(DeltaCatalog.class);
    DeltaTableV2 deltaTable = mock(DeltaTableV2.class, RETURNS_DEEP_STUBS);
    Identifier identifier = Identifier.of(new String[] { "database", "schema" }, "table");
    DeltaHandler deltaHandler = new DeltaHandler();
    when(deltaCatalog.loadTable(identifier)).thenReturn(deltaTable);
    when(deltaTable.snapshot().version()).thenReturn(2L);
    Optional<String> version = deltaHandler.getDatasetVersion(deltaCatalog, identifier, Collections.emptyMap());
    assertTrue(version.isPresent());
    assertEquals(version.get(), "2");
}
Also used : DeltaTableV2(org.apache.spark.sql.delta.catalog.DeltaTableV2) DeltaCatalog(org.apache.spark.sql.delta.catalog.DeltaCatalog) Identifier(org.apache.spark.sql.connector.catalog.Identifier) Test(org.junit.jupiter.api.Test)

Aggregations

DeltaCatalog (org.apache.spark.sql.delta.catalog.DeltaCatalog)2 DeltaTableV2 (org.apache.spark.sql.delta.catalog.DeltaTableV2)2 SneakyThrows (lombok.SneakyThrows)1 Identifier (org.apache.spark.sql.connector.catalog.Identifier)1 Table (org.apache.spark.sql.connector.catalog.Table)1 Test (org.junit.jupiter.api.Test)1