Skip to content

Commit 77a4475

Browse files
author
Pushpender Saini
authored
Merge pull request #63 from cloudsufi/bugfix/ref-name-fix
[PLUGIN-1752] Changed parent class to ReferenceBatchSource
2 parents c7fff76 + f06b0df commit 77a4475

2 files changed

Lines changed: 61 additions & 1 deletion

File tree

src/main/java/io/cdap/plugin/MultiTableDBSource.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import io.cdap.cdap.etl.api.batch.BatchSourceContext;
3333
import io.cdap.plugin.common.Asset;
3434
import io.cdap.plugin.common.LineageRecorder;
35+
import io.cdap.plugin.common.ReferenceBatchSource;
36+
import io.cdap.plugin.common.ReferencePluginConfig;
3537
import io.cdap.plugin.common.SourceInputFormatProvider;
3638
import io.cdap.plugin.format.DBTableInfo;
3739
import io.cdap.plugin.format.MultiSQLStatementInputFormat;
@@ -63,19 +65,21 @@
6365
@Description("Reads from multiple tables in a relational database. " +
6466
"Outputs one record for each row in each table, with the table name as a record field. " +
6567
"Also sets a pipeline argument for each table read, which contains the table schema. ")
66-
public class MultiTableDBSource extends BatchSource<NullWritable, RecordWrapper, StructuredRecord> {
68+
public class MultiTableDBSource extends ReferenceBatchSource<NullWritable, RecordWrapper, StructuredRecord> {
6769
private static final Logger LOG = LoggerFactory.getLogger(MultiTableDBSource.class);
6870

6971
private static final String JDBC_PLUGIN_ID = "jdbc.driver";
7072

7173
private final MultiTableConf conf;
7274

7375
public MultiTableDBSource(MultiTableConf conf) {
76+
super(new ReferencePluginConfig(conf.getReferenceName()));
7477
this.conf = conf;
7578
}
7679

7780
@Override
7881
public void configurePipeline(PipelineConfigurer pipelineConfigurer) {
82+
super.configurePipeline(pipelineConfigurer);
7983
Class<? extends Driver> jdbcDriverClass = pipelineConfigurer.usePluginClass("jdbc", conf.getJdbcPluginName(),
8084
JDBC_PLUGIN_ID,
8185
PluginProperties.builder().build());
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright © 2024 Cask Data, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package io.cdap.plugin;
18+
19+
20+
import io.cdap.cdap.api.data.schema.Schema;
21+
import io.cdap.cdap.etl.api.validation.ValidationException;
22+
import io.cdap.cdap.etl.mock.common.MockPipelineConfigurer;
23+
import io.cdap.plugin.format.MultiTableConf;
24+
25+
import org.junit.Assert;
26+
import org.junit.Before;
27+
import org.junit.Test;
28+
29+
/**
30+
* Tests for MultiTableDBSource
31+
*/
32+
public class MultiTableDBSourceTest {
33+
34+
MockPipelineConfigurer mockPipelineConfigurer = new MockPipelineConfigurer(Schema.of(Schema.Type.STRING));
35+
MultiTableDBSource multiTableDBSource;
36+
String referenceNameWithSpace = "Hello MultiTable";
37+
38+
@Before
39+
public void setUp() {
40+
multiTableDBSource = new MultiTableDBSource(new MultiTableConf(referenceNameWithSpace));
41+
}
42+
43+
/**
44+
* Plugin should not allow space in reference name for MultiTableDBSource
45+
*/
46+
@Test
47+
public void testMultiTableReferenceNameWithSpace() {
48+
try {
49+
multiTableDBSource.configurePipeline(mockPipelineConfigurer);
50+
} catch (ValidationException e) {
51+
// expected
52+
}
53+
Assert.assertEquals(1, mockPipelineConfigurer.getStageConfigurer().getFailureCollector().getValidationFailures()
54+
.size());
55+
}
56+
}

0 commit comments

Comments
 (0)