Search in sources :

Example 1 with DataSourceV2Relation

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

the class AppendDataDatasetBuilderTest method testApplyWithDataSourceV2Relation.

@Test
public void testApplyWithDataSourceV2Relation() {
    AppendData appendData = mock(AppendData.class);
    DataSourceV2Relation relation = mock(DataSourceV2Relation.class);
    OpenLineage.OutputDataset dataset = mock(OpenLineage.OutputDataset.class);
    when(appendData.table()).thenReturn(relation);
    try (MockedStatic mockedPlanUtils3 = mockStatic(PlanUtils3.class)) {
        try (MockedStatic mockedFacetUtils = mockStatic(DatasetVersionDatasetFacetUtils.class)) {
            when(DatasetVersionDatasetFacetUtils.extractVersionFromDataSourceV2Relation(relation)).thenReturn(Optional.of("v2"));
            when(PlanUtils3.fromDataSourceV2Relation(eq(factory), eq(context), eq(relation), any())).thenReturn(Collections.singletonList(dataset));
            List<OpenLineage.OutputDataset> datasets = builder.apply(appendData);
            assertEquals(1, datasets.size());
            assertEquals(dataset, datasets.get(0));
        }
    }
}
Also used : DataSourceV2Relation(org.apache.spark.sql.execution.datasources.v2.DataSourceV2Relation) AppendData(org.apache.spark.sql.catalyst.plans.logical.AppendData) MockedStatic(org.mockito.MockedStatic) OpenLineage(io.openlineage.client.OpenLineage) Test(org.junit.jupiter.api.Test)

Example 2 with DataSourceV2Relation

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

the class DataSourceV2ScanRelationInputDatasetBuilderTest method testApply.

@Test
public void testApply() {
    OpenLineage.DatasetFacetsBuilder datasetFacetsBuilder = mock(OpenLineage.DatasetFacetsBuilder.class);
    List<OpenLineage.InputDataset> datasets = mock(List.class);
    DataSourceV2ScanRelation scanRelation = mock(DataSourceV2ScanRelation.class);
    DataSourceV2Relation relation = mock(DataSourceV2Relation.class);
    when(openLineage.newDatasetFacetsBuilder()).thenReturn(datasetFacetsBuilder);
    when(context.getOpenLineage()).thenReturn(openLineage);
    when(scanRelation.relation()).thenReturn(relation);
    try (MockedStatic planUtils3MockedStatic = mockStatic(PlanUtils3.class)) {
        try (MockedStatic facetUtilsMockedStatic = mockStatic(DatasetVersionDatasetFacetUtils.class)) {
            when(PlanUtils3.fromDataSourceV2Relation(factory, context, relation, datasetFacetsBuilder)).thenReturn(datasets);
            assertEquals(datasets, builder.apply(scanRelation));
            facetUtilsMockedStatic.verify(() -> DatasetVersionDatasetFacetUtils.includeDatasetVersion(context, datasetFacetsBuilder, relation), times(1));
        }
    }
}
Also used : DataSourceV2Relation(org.apache.spark.sql.execution.datasources.v2.DataSourceV2Relation) MockedStatic(org.mockito.MockedStatic) OpenLineage(io.openlineage.client.OpenLineage) DataSourceV2ScanRelation(org.apache.spark.sql.execution.datasources.v2.DataSourceV2ScanRelation) Test(org.junit.jupiter.api.Test)

Example 3 with DataSourceV2Relation

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

the class DatasetVersionDatasetFacetUtilsTest method testIncludeDatasetVersion.

@Test
public void testIncludeDatasetVersion() {
    OpenLineage.DatasetFacetsBuilder datasetFacetsBuilder = new OpenLineage.DatasetFacetsBuilder();
    DataSourceV2Relation relation = mock(DataSourceV2Relation.class);
    OpenLineage.DatasetVersionDatasetFacet datasetVersionDatasetFacet = mock(OpenLineage.DatasetVersionDatasetFacet.class);
    when(datasetVersionDatasetFacet.getDatasetVersion()).thenReturn("v2");
    when(openLineage.newDatasetVersionDatasetFacet("v2")).thenReturn(datasetVersionDatasetFacet);
    when(relation.identifier()).thenReturn(Option.apply(identifier));
    when(relation.catalog()).thenReturn(Option.apply(tableCatalog));
    when(relation.table()).thenReturn(table);
    when(table.properties()).thenReturn(tableProperties);
    try (MockedStatic mocked = mockStatic(CatalogUtils3.class)) {
        when(CatalogUtils3.getDatasetVersion(tableCatalog, identifier, tableProperties)).thenReturn(Optional.of("v2"));
        DatasetVersionDatasetFacetUtils.includeDatasetVersion(openLineageContext, datasetFacetsBuilder, relation);
        assertEquals("v2", datasetFacetsBuilder.build().getVersion().getDatasetVersion());
    }
}
Also used : DataSourceV2Relation(org.apache.spark.sql.execution.datasources.v2.DataSourceV2Relation) MockedStatic(org.mockito.MockedStatic) OpenLineage(io.openlineage.client.OpenLineage) Test(org.junit.jupiter.api.Test)

Example 4 with DataSourceV2Relation

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

the class DatasetVersionDatasetFacetUtilsTest method testIncludeDatasetVersionWhenNoDatasetVersion.

@Test
public void testIncludeDatasetVersionWhenNoDatasetVersion() {
    OpenLineage.DatasetFacetsBuilder datasetFacetsBuilder = new OpenLineage.DatasetFacetsBuilder();
    DataSourceV2Relation relation = mock(DataSourceV2Relation.class);
    when(relation.identifier()).thenReturn(Option.apply(identifier));
    when(relation.catalog()).thenReturn(Option.apply(tableCatalog));
    when(relation.table()).thenReturn(table);
    when(table.properties()).thenReturn(tableProperties);
    try (MockedStatic mocked = mockStatic(CatalogUtils3.class)) {
        when(CatalogUtils3.getDatasetVersion(tableCatalog, identifier, tableProperties)).thenReturn(Optional.empty());
        DatasetVersionDatasetFacetUtils.includeDatasetVersion(openLineageContext, datasetFacetsBuilder, relation);
        assertEquals(null, datasetFacetsBuilder.build().getVersion());
    }
}
Also used : DataSourceV2Relation(org.apache.spark.sql.execution.datasources.v2.DataSourceV2Relation) MockedStatic(org.mockito.MockedStatic) OpenLineage(io.openlineage.client.OpenLineage) Test(org.junit.jupiter.api.Test)

Example 5 with DataSourceV2Relation

use of org.apache.spark.sql.execution.datasources.v2.DataSourceV2Relation in project iceberg by apache.

the class BaseProcedure method refreshSparkCache.

protected void refreshSparkCache(Identifier ident, Table table) {
    CacheManager cacheManager = spark.sharedState().cacheManager();
    DataSourceV2Relation relation = DataSourceV2Relation.create(table, Option.apply(tableCatalog), Option.apply(ident));
    cacheManager.recacheByPlan(spark, relation);
}
Also used : DataSourceV2Relation(org.apache.spark.sql.execution.datasources.v2.DataSourceV2Relation) CacheManager(org.apache.spark.sql.execution.CacheManager)

Aggregations

DataSourceV2Relation (org.apache.spark.sql.execution.datasources.v2.DataSourceV2Relation)6 OpenLineage (io.openlineage.client.OpenLineage)5 Test (org.junit.jupiter.api.Test)4 MockedStatic (org.mockito.MockedStatic)4 AppendData (org.apache.spark.sql.catalyst.plans.logical.AppendData)1 CacheManager (org.apache.spark.sql.execution.CacheManager)1 DataSourceV2ScanRelation (org.apache.spark.sql.execution.datasources.v2.DataSourceV2ScanRelation)1