-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15388 from cdapio/skip_rdd_conversion_pushdown
[CDAP-20658] Remove unneeded DataFrame->RDD conversion
- Loading branch information
Showing
5 changed files
with
166 additions
and
20 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...or-spark-core-base/src/main/java/io/cdap/cdap/etl/spark/batch/BatchCollectionFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright © 2023 Cask Data, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package io.cdap.cdap.etl.spark.batch; | ||
|
||
import io.cdap.cdap.api.data.DatasetContext; | ||
import io.cdap.cdap.api.spark.JavaSparkExecutionContext; | ||
import io.cdap.cdap.etl.spark.function.FunctionCache; | ||
import org.apache.spark.api.java.JavaSparkContext; | ||
import org.apache.spark.sql.SQLContext; | ||
|
||
/** | ||
* Interface for factories that has all data needed to create a {@link BatchCollection} | ||
* when provided with various contexts. An instance of this factory is backed by a specific | ||
* single data set (RDD / Spark DataSet / Spark DataFrame / ...). | ||
* @see RDDCollectionFactory | ||
* @see DataframeCollectionFactory | ||
*/ | ||
public interface BatchCollectionFactory<T> { | ||
|
||
/** | ||
* Create new BatchCollection with the data from this factory object using contexts | ||
* provided in the parameters. | ||
* @param sec java spark execution context | ||
* @param jsc java spark context | ||
* @param sqlContext sql context | ||
* @param datasetContext dataset context | ||
* @param sinkFactory sink factory | ||
* @param functionCacheFactory function cache factory | ||
* @return specific instance of BatchCollection backed by this factory data. | ||
*/ | ||
BatchCollection<T> create(JavaSparkExecutionContext sec, JavaSparkContext jsc, | ||
SQLContext sqlContext, DatasetContext datasetContext, SparkBatchSinkFactory sinkFactory, | ||
FunctionCache.Factory functionCacheFactory); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...park-core-base/src/main/java/io/cdap/cdap/etl/spark/batch/DataframeCollectionFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright © 2023 Cask Data, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package io.cdap.cdap.etl.spark.batch; | ||
|
||
import io.cdap.cdap.api.data.DatasetContext; | ||
import io.cdap.cdap.api.data.schema.Schema; | ||
import io.cdap.cdap.api.spark.JavaSparkExecutionContext; | ||
import io.cdap.cdap.etl.spark.function.FunctionCache; | ||
import org.apache.spark.api.java.JavaSparkContext; | ||
import org.apache.spark.sql.Dataset; | ||
import org.apache.spark.sql.Row; | ||
import org.apache.spark.sql.SQLContext; | ||
|
||
/** | ||
* Factory that creates a {@link DataframeCollection} | ||
*/ | ||
public class DataframeCollectionFactory<T> implements BatchCollectionFactory<T> { | ||
|
||
private final Schema schema; | ||
private final Dataset<Row> dataFrame; | ||
|
||
/** | ||
* Creates dataFrame-based pull result | ||
* | ||
* @param schema schema of the dataFrame | ||
* @param dataFrame result dataFrame | ||
*/ | ||
public DataframeCollectionFactory(Schema schema, Dataset<Row> dataFrame) { | ||
this.schema = schema; | ||
this.dataFrame = dataFrame; | ||
} | ||
|
||
@Override | ||
public BatchCollection<T> create(JavaSparkExecutionContext sec, JavaSparkContext jsc, | ||
SQLContext sqlContext, DatasetContext datasetContext, SparkBatchSinkFactory sinkFactory, | ||
FunctionCache.Factory functionCacheFactory) { | ||
return (BatchCollection<T>) new DataframeCollection( | ||
schema, dataFrame, sec, jsc, sqlContext, datasetContext, | ||
sinkFactory, functionCacheFactory); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...ator-spark-core-base/src/main/java/io/cdap/cdap/etl/spark/batch/RDDCollectionFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright © 2023 Cask Data, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package io.cdap.cdap.etl.spark.batch; | ||
|
||
import io.cdap.cdap.api.data.DatasetContext; | ||
import io.cdap.cdap.api.spark.JavaSparkExecutionContext; | ||
import io.cdap.cdap.etl.spark.function.FunctionCache; | ||
import org.apache.spark.api.java.JavaRDD; | ||
import org.apache.spark.api.java.JavaSparkContext; | ||
import org.apache.spark.sql.SQLContext; | ||
|
||
/** | ||
* Factory that creates a {@link RDDCollection<T>} | ||
*/ | ||
public class RDDCollectionFactory<T> implements BatchCollectionFactory<T> { | ||
|
||
private final JavaRDD<T> rdd; | ||
|
||
/** | ||
* Creates JavaRDD-based pull result | ||
*/ | ||
public RDDCollectionFactory(JavaRDD<T> rdd) { | ||
this.rdd = rdd; | ||
} | ||
|
||
@Override | ||
public BatchCollection<T> create(JavaSparkExecutionContext sec, JavaSparkContext jsc, | ||
SQLContext sqlContext, DatasetContext datasetContext, SparkBatchSinkFactory sinkFactory, | ||
FunctionCache.Factory functionCacheFactory) { | ||
return new RDDCollection<>(sec, functionCacheFactory, jsc, sqlContext, datasetContext, | ||
sinkFactory, rdd); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters