Skip to content

Commit c4a7996

Browse files
author
bajram-adapt
committed
Show new error message when output schema is not maching input
1 parent fb973c5 commit c4a7996

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@
2222

2323
<groupId>io.cdap.plugin</groupId>
2424
<artifactId>dynamic-spark</artifactId>
25-
<version>2.2.2</version>
25+
<version>2.2.3-SNAPSHOT</version>
2626

2727
<properties>
2828
<!-- properties for script build step that creates the config files for the artifacts -->
2929
<data.pipeline.parent>system:cdap-data-pipeline[6.0.0-SNAPSHOT,7.0.0-SNAPSHOT)</data.pipeline.parent>
3030
<data.stream.parent>system:cdap-data-streams[6.0.0-SNAPSHOT,7.0.0-SNAPSHOT)</data.stream.parent>
3131

32-
<cdap.version>6.1.3-SNAPSHOT</cdap.version>
32+
<cdap.version>6.1.1</cdap.version>
3333
<spark.version>2.1.3</spark.version>
3434
<logback.version>1.0.9</logback.version>
35+
<hydrator-common.version>2.4.0</hydrator-common.version>
3536

3637
<surefire.redirectTestOutputToFile>true</surefire.redirectTestOutputToFile>
3738
</properties>
@@ -100,6 +101,11 @@
100101
<version>4.11</version>
101102
<scope>test</scope>
102103
</dependency>
104+
<dependency>
105+
<groupId>io.cdap.plugin</groupId>
106+
<artifactId>hydrator-common</artifactId>
107+
<version>${hydrator-common.version}</version>
108+
</dependency>
103109
<dependency>
104110
<groupId>io.cdap.cdap</groupId>
105111
<artifactId>hydrator-test</artifactId>

src/main/java/io/cdap/plugin/spark/dynamic/ScalaSparkCompute.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.cdap.cdap.api.data.schema.Schema;
2525
import io.cdap.cdap.api.plugin.PluginConfig;
2626
import io.cdap.cdap.api.spark.sql.DataFrames;
27+
import io.cdap.cdap.etl.api.FailureCollector;
2728
import io.cdap.cdap.etl.api.PipelineConfigurer;
2829
import io.cdap.cdap.etl.api.StageConfigurer;
2930
import io.cdap.cdap.etl.api.batch.SparkCompute;
@@ -98,6 +99,13 @@ public JavaRDD<StructuredRecord> transform(SparkExecutionPluginContext context,
9899
// If there is no output schema configured, derive it from the DataFrame
99100
// Otherwise, assume the DataFrame has the correct schema already
100101
outputSchema = DataFrames.toSchema((DataType) invokeDataFrameMethod(result, "schema"));
102+
} else {
103+
Schema dataSchema = DataFrames.toSchema((DataType) invokeDataFrameMethod(result, "schema"));
104+
if (!dataSchema.isCompatible(outputSchema)) {
105+
FailureCollector collector = context.getFailureCollector();
106+
collector.addFailure("Schema mismatch.", "Output schema is not matching input schema.");
107+
collector.getOrThrowException();
108+
}
101109
}
102110
//noinspection unchecked
103111
return ((JavaRDD<Row>) invokeDataFrameMethod(result, "toJavaRDD")).map(new RowToRecord(outputSchema));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy