Search in sources :

Example 1 with CreatableRelationProvider

use of org.apache.spark.sql.sources.CreatableRelationProvider in project OpenLineage by OpenLineage.

the class BigQueryNodeVisitor method bigQuerySupplier.

private Optional<Supplier<BigQueryRelation>> bigQuerySupplier(LogicalPlan plan) {
    // SaveIntoDataSourceCommand is a special case because it references a CreatableRelationProvider
    // Every other write instance references a LogicalRelation(BigQueryRelation, _, _, _)
    SQLContext sqlContext = context.getSparkSession().get().sqlContext();
    if (plan instanceof SaveIntoDataSourceCommand) {
        SaveIntoDataSourceCommand saveCommand = (SaveIntoDataSourceCommand) plan;
        CreatableRelationProvider relationProvider = saveCommand.dataSource();
        if (relationProvider instanceof BigQueryRelationProvider) {
            return Optional.of(() -> (BigQueryRelation) ((BigQueryRelationProvider) relationProvider).createRelation(sqlContext, saveCommand.options(), saveCommand.schema()));
        }
    } else {
        if (plan instanceof LogicalRelation && ((LogicalRelation) plan).relation() instanceof BigQueryRelation) {
            return Optional.of(() -> (BigQueryRelation) ((LogicalRelation) plan).relation());
        }
    }
    return Optional.empty();
}
Also used : LogicalRelation(org.apache.spark.sql.execution.datasources.LogicalRelation) BigQueryRelation(com.google.cloud.spark.bigquery.BigQueryRelation) SaveIntoDataSourceCommand(org.apache.spark.sql.execution.datasources.SaveIntoDataSourceCommand) CreatableRelationProvider(org.apache.spark.sql.sources.CreatableRelationProvider) BigQueryRelationProvider(com.google.cloud.spark.bigquery.BigQueryRelationProvider) SQLContext(org.apache.spark.sql.SQLContext)

Aggregations

BigQueryRelation (com.google.cloud.spark.bigquery.BigQueryRelation)1 BigQueryRelationProvider (com.google.cloud.spark.bigquery.BigQueryRelationProvider)1 SQLContext (org.apache.spark.sql.SQLContext)1 LogicalRelation (org.apache.spark.sql.execution.datasources.LogicalRelation)1 SaveIntoDataSourceCommand (org.apache.spark.sql.execution.datasources.SaveIntoDataSourceCommand)1 CreatableRelationProvider (org.apache.spark.sql.sources.CreatableRelationProvider)1