use of io.openlineage.client.OpenLineage in project OpenLineage by OpenLineage.
the class CreateTableLikeCommandVisitorTest method testCreateTableLikeCommand.
@Test
@SneakyThrows
void testCreateTableLikeCommand() {
CatalogTable sourceCatalogTable = mock(CatalogTable.class);
when(sparkSession.sparkContext()).thenReturn(mock(SparkContext.class));
when(sparkSession.sessionState()).thenReturn(sessionState);
when(sessionState.catalog()).thenReturn(sessionCatalog);
when(sessionCatalog.getTempViewOrPermanentTableMetadata(sourceTableIdentifier)).thenReturn(sourceCatalogTable);
when(sessionCatalog.defaultTablePath(targetTableIdentifier)).thenReturn(new URI("/tmp/warehouse/newtable"));
when(sourceCatalogTable.schema()).thenReturn(schema);
CreateTableLikeCommandVisitor visitor = new CreateTableLikeCommandVisitor(OpenLineageContext.builder().sparkSession(Optional.of(sparkSession)).sparkContext(sparkSession.sparkContext()).openLineage(new OpenLineage(OpenLineageClient.OPEN_LINEAGE_CLIENT_URI)).build());
CreateTableLikeCommand command = new CreateTableLikeCommand(targetTableIdentifier, sourceTableIdentifier, CatalogStorageFormat.empty(), Option$.MODULE$.empty(), Map$.MODULE$.empty(), false);
assertThat(visitor.isDefinedAt(command)).isTrue();
List<OpenLineage.OutputDataset> datasets = visitor.apply(command);
assertEquals(1, datasets.size());
OpenLineage.OutputDataset outputDataset = datasets.get(0);
assertEquals(OpenLineage.LifecycleStateChangeDatasetFacet.LifecycleStateChange.CREATE, outputDataset.getFacets().getLifecycleStateChange().getLifecycleStateChange());
assertEquals("/tmp/warehouse/newtable", outputDataset.getName());
assertEquals("file", outputDataset.getNamespace());
}
use of io.openlineage.client.OpenLineage in project OpenLineage by OpenLineage.
the class LogicalRelationDatasetBuilderTest method testApply.
@ParameterizedTest
@ValueSource(strings = { "postgresql://postgreshost:5432/sparkdata", "jdbc:oracle:oci8:@sparkdata", "jdbc:oracle:thin@sparkdata:1521:orcl", "mysql://localhost/sparkdata" })
void testApply(String connectionUri) {
OpenLineage openLineage = new OpenLineage(OpenLineageClient.OPEN_LINEAGE_CLIENT_URI);
String jdbcUrl = "jdbc:" + connectionUri;
String sparkTableName = "my_spark_table";
JDBCRelation relation = new JDBCRelation(new StructType(new StructField[] { new StructField("name", StringType$.MODULE$, false, null) }), new Partition[] {}, new JDBCOptions(jdbcUrl, sparkTableName, Map$.MODULE$.<String, String>newBuilder().$plus$eq(Tuple2.apply("driver", Driver.class.getName())).result()), session);
QueryExecution qe = mock(QueryExecution.class);
when(qe.optimizedPlan()).thenReturn(new LogicalRelation(relation, Seq$.MODULE$.<AttributeReference>newBuilder().$plus$eq(new AttributeReference("name", StringType$.MODULE$, false, null, ExprId.apply(1L), Seq$.MODULE$.<String>empty())).result(), Option.empty(), false));
OpenLineageContext context = OpenLineageContext.builder().sparkContext(mock(SparkContext.class)).openLineage(openLineage).queryExecution(qe).build();
LogicalRelationDatasetBuilder visitor = new LogicalRelationDatasetBuilder<>(context, DatasetFactory.output(openLineage), false);
List<OutputDataset> datasets = visitor.apply(new SparkListenerJobStart(1, 1, Seq$.MODULE$.empty(), null));
assertEquals(1, datasets.size());
OutputDataset ds = datasets.get(0);
assertEquals(connectionUri, ds.getNamespace());
assertEquals(sparkTableName, ds.getName());
assertEquals(URI.create(connectionUri), ds.getFacets().getDataSource().getUri());
assertEquals(connectionUri, ds.getFacets().getDataSource().getName());
}
use of io.openlineage.client.OpenLineage in project OpenLineage by OpenLineage.
the class SQLDWDatabricksVisitorTest method testSQLDWRelationComplexQuery.
@Test
void testSQLDWRelationComplexQuery() {
String inputName = "(SELECT * FROM dbo.table1) q";
String inputJdbcUrl = "jdbc:sqlserver://MYTESTSERVER.database.windows.net:1433;database=MYTESTDB";
String expectedName = "COMPLEX";
String expectedNamespace = "sqlserver://MYTESTSERVER.database.windows.net:1433;database=MYTESTDB;";
// Instantiate a MockSQLDWRelation
LogicalRelation lr = new LogicalRelation(new MockSqlDWBaseRelation(inputName, inputJdbcUrl), Seq$.MODULE$.<AttributeReference>newBuilder().$plus$eq(new AttributeReference("name", StringType$.MODULE$, false, null, ExprId.apply(1L), Seq$.MODULE$.<String>empty())).result(), Option.empty(), false);
TestSqlDWDatabricksVisitor visitor = new TestSqlDWDatabricksVisitor(SparkAgentTestExtension.newContext(session), DatasetFactory.output(new OpenLineage(OpenLineageClient.OPEN_LINEAGE_CLIENT_URI)));
List<OpenLineage.Dataset> datasets = visitor.apply(lr);
assertEquals(1, datasets.size());
OpenLineage.Dataset ds = datasets.get(0);
assertEquals(expectedNamespace, ds.getNamespace());
assertEquals(expectedName, ds.getName());
}
Aggregations