Search in sources :

Example 1 with CatalogUtils3

use of io.openlineage.spark3.agent.lifecycle.plan.catalog.CatalogUtils3 in project OpenLineage by OpenLineage.

the class PlanUtils3Test method testGetDatasetIdentifier.

@Test
public void testGetDatasetIdentifier() {
    DatasetIdentifier di = mock(DatasetIdentifier.class);
    try (MockedStatic<CatalogUtils3> mocked = mockStatic(CatalogUtils3.class)) {
        when(CatalogUtils3.getDatasetIdentifier(sparkSession, tableCatalog, identifier, tableProperties)).thenReturn(di);
        assertEquals(di, PlanUtils3.getDatasetIdentifier(openLineageContext, tableCatalog, identifier, tableProperties).get());
    }
}
Also used : DatasetIdentifier(io.openlineage.spark.agent.util.DatasetIdentifier) CatalogUtils3(io.openlineage.spark3.agent.lifecycle.plan.catalog.CatalogUtils3) Test(org.junit.jupiter.api.Test)

Example 2 with CatalogUtils3

use of io.openlineage.spark3.agent.lifecycle.plan.catalog.CatalogUtils3 in project OpenLineage by OpenLineage.

the class PlanUtils3Test method testIncludeProviderFacet.

@Test
public void testIncludeProviderFacet() {
    try (MockedStatic<CatalogUtils3> mocked = mockStatic(CatalogUtils3.class)) {
        Map<String, OpenLineage.DatasetFacet> facets = new HashMap<>();
        TableProviderFacet tableProviderFacet = new TableProviderFacet("iceberg", "parquet");
        when(CatalogUtils3.getTableProviderFacet(tableCatalog, tableProperties)).thenReturn(Optional.of(tableProviderFacet));
        PlanUtils3.includeProviderFacet(tableCatalog, tableProperties, facets);
        assertEquals(tableProviderFacet, facets.get("tableProvider"));
    }
}
Also used : HashMap(java.util.HashMap) CatalogUtils3(io.openlineage.spark3.agent.lifecycle.plan.catalog.CatalogUtils3) TableProviderFacet(io.openlineage.spark.agent.facets.TableProviderFacet) Test(org.junit.jupiter.api.Test)

Example 3 with CatalogUtils3

use of io.openlineage.spark3.agent.lifecycle.plan.catalog.CatalogUtils3 in project OpenLineage by OpenLineage.

the class PlanUtils3Test method testGetDatasetIdentifierWhenCatalogUnsupported.

@Test
public void testGetDatasetIdentifierWhenCatalogUnsupported() {
    try (MockedStatic<CatalogUtils3> mocked = mockStatic(CatalogUtils3.class)) {
        when(CatalogUtils3.getDatasetIdentifier(sparkSession, tableCatalog, identifier, tableProperties)).thenThrow(new UnsupportedCatalogException("exception"));
        assertEquals(Optional.empty(), PlanUtils3.getDatasetIdentifier(openLineageContext, tableCatalog, identifier, tableProperties));
    }
}
Also used : UnsupportedCatalogException(io.openlineage.spark3.agent.lifecycle.plan.catalog.UnsupportedCatalogException) CatalogUtils3(io.openlineage.spark3.agent.lifecycle.plan.catalog.CatalogUtils3) Test(org.junit.jupiter.api.Test)

Example 4 with CatalogUtils3

use of io.openlineage.spark3.agent.lifecycle.plan.catalog.CatalogUtils3 in project OpenLineage by OpenLineage.

the class PlanUtils3Test method testFromDataSourceV2RelationWhenDatasetIdentifierEmpty.

@Test
public void testFromDataSourceV2RelationWhenDatasetIdentifierEmpty() {
    try (MockedStatic<CatalogUtils3> mocked = mockStatic(CatalogUtils3.class)) {
        DatasetIdentifier di = mock(DatasetIdentifier.class);
        OpenLineage.Dataset dataset = mock(OpenLineage.Dataset.class);
        when(CatalogUtils3.getDatasetIdentifier(sparkSession, tableCatalog, identifier, tableProperties)).thenThrow(new UnsupportedCatalogException("exception"));
        when(datasetFactory.getDataset(di, schema)).thenReturn(dataset);
        assertEquals(Collections.emptyList(), PlanUtils3.fromDataSourceV2Relation(datasetFactory, openLineageContext, dataSourceV2Relation));
    }
}
Also used : UnsupportedCatalogException(io.openlineage.spark3.agent.lifecycle.plan.catalog.UnsupportedCatalogException) DatasetIdentifier(io.openlineage.spark.agent.util.DatasetIdentifier) OpenLineage(io.openlineage.client.OpenLineage) CatalogUtils3(io.openlineage.spark3.agent.lifecycle.plan.catalog.CatalogUtils3) Test(org.junit.jupiter.api.Test)

Example 5 with CatalogUtils3

use of io.openlineage.spark3.agent.lifecycle.plan.catalog.CatalogUtils3 in project OpenLineage by OpenLineage.

the class PlanUtils3Test method testFromDataSourceV2Relation.

@Test
public void testFromDataSourceV2Relation() {
    try (MockedStatic<CatalogUtils3> mocked = mockStatic(CatalogUtils3.class)) {
        try (MockedStatic<PlanUtils> mockedPlanUtils = mockStatic(PlanUtils.class)) {
            DatasetIdentifier di = mock(DatasetIdentifier.class);
            when(di.getNamespace()).thenReturn("file://tmp");
            when(di.getName()).thenReturn("name");
            OpenLineage.DatasetFacets datasetFacets = mock(OpenLineage.DatasetFacets.class);
            OpenLineage.Dataset dataset = mock(OpenLineage.Dataset.class);
            OpenLineage.SchemaDatasetFacet schemaDatasetFacet = mock(OpenLineage.SchemaDatasetFacet.class);
            OpenLineage.DatasourceDatasetFacet datasourceDatasetFacet = mock(OpenLineage.DatasourceDatasetFacet.class);
            when(PlanUtils.schemaFacet(openLineage, schema)).thenReturn(schemaDatasetFacet);
            when(PlanUtils.datasourceFacet(openLineage, di.getNamespace())).thenReturn(datasourceDatasetFacet);
            when(datasetFacetsBuilder.schema(schemaDatasetFacet)).thenReturn(datasetFacetsBuilder);
            when(datasetFacetsBuilder.dataSource(datasourceDatasetFacet)).thenReturn(datasetFacetsBuilder);
            when(datasetFacetsBuilder.build()).thenReturn(datasetFacets);
            when(CatalogUtils3.getDatasetIdentifier(sparkSession, tableCatalog, identifier, tableProperties)).thenReturn(di);
            when(datasetFactory.getDataset(di.getName(), di.getNamespace(), datasetFacets)).thenReturn(dataset);
            assertEquals(Collections.singletonList(dataset), PlanUtils3.fromDataSourceV2Relation(datasetFactory, openLineageContext, dataSourceV2Relation));
        }
    }
}
Also used : DatasetIdentifier(io.openlineage.spark.agent.util.DatasetIdentifier) OpenLineage(io.openlineage.client.OpenLineage) CatalogUtils3(io.openlineage.spark3.agent.lifecycle.plan.catalog.CatalogUtils3) PlanUtils(io.openlineage.spark.agent.util.PlanUtils) Test(org.junit.jupiter.api.Test)

Aggregations

CatalogUtils3 (io.openlineage.spark3.agent.lifecycle.plan.catalog.CatalogUtils3)5 Test (org.junit.jupiter.api.Test)5 DatasetIdentifier (io.openlineage.spark.agent.util.DatasetIdentifier)3 OpenLineage (io.openlineage.client.OpenLineage)2 UnsupportedCatalogException (io.openlineage.spark3.agent.lifecycle.plan.catalog.UnsupportedCatalogException)2 TableProviderFacet (io.openlineage.spark.agent.facets.TableProviderFacet)1 PlanUtils (io.openlineage.spark.agent.util.PlanUtils)1 HashMap (java.util.HashMap)1