Skip to content

Commit 82b77d1

Browse files
Merge pull request #35 from cloudsufi/override-schema-release
[cherrypick][PLUGIN-1809]Fix added to override schema
2 parents bc1a68c + 41813c6 commit 82b77d1

File tree

8 files changed

+145
-13
lines changed

8 files changed

+145
-13
lines changed

.github/workflows/build-report.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright © 2024 Cask Data, Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
3+
# use this file except in compliance with the License. You may obtain a copy of
4+
# the License at
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
# Unless required by applicable law or agreed to in writing, software
7+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
8+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
9+
# License for the specific language governing permissions and limitations under
10+
# the License.
11+
12+
# This workflow will build a Java project with Maven
13+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
14+
# Note: Any changes to this workflow would be used only after merging into develop
15+
name: Build Unit Tests Report
16+
17+
on:
18+
workflow_run:
19+
workflows:
20+
- Build with unit tests
21+
types:
22+
- completed
23+
24+
jobs:
25+
build:
26+
runs-on: ubuntu-latest
27+
28+
if: ${{ github.event.workflow_run.conclusion != 'skipped' }}
29+
30+
steps:
31+
# Pinned 1.0.0 version
32+
- uses: marocchino/action-workflow_run-status@54b6e87d6cb552fc5f36dbe9a722a6048725917a
33+
34+
- name: Download artifact
35+
uses: actions/download-artifact@v4
36+
with:
37+
github-token: ${{ secrets.GITHUB_TOKEN }}
38+
run-id: ${{ github.event.workflow_run.id }}
39+
path: artifacts/
40+
41+
- name: Surefire Report
42+
# Pinned 3.5.2 version
43+
uses: mikepenz/action-junit-report@16a9560bd02f11e7e3bf6b3e2ef6bba6c9d07c32
44+
if: always()
45+
with:
46+
report_paths: '**/target/surefire-reports/TEST-*.xml'
47+
github_token: ${{ secrets.GITHUB_TOKEN }}
48+
detailed_summary: true
49+
commit: ${{ github.event.workflow_run.head_sha }}
50+
check_name: Build Test Report

.github/workflows/main.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright © 2024 Cask Data, Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
3+
# use this file except in compliance with the License. You may obtain a copy of
4+
# the License at
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
# Unless required by applicable law or agreed to in writing, software
7+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
8+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
9+
# License for the specific language governing permissions and limitations under
10+
# the License.
11+
12+
# This workflow will build a Java project with Maven
13+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
14+
# Note: Any changes to this workflow would be used only after merging into develop
15+
name: Build with unit tests
16+
17+
on:
18+
push:
19+
branches: [ develop, release/** ]
20+
pull_request:
21+
branches: [ develop, release/** ]
22+
types: [opened, synchronize, reopened, labeled]
23+
24+
jobs:
25+
build:
26+
runs-on: k8s-runner-build
27+
28+
# We allow builds:
29+
# 1) When it's a merge into a branch
30+
# 2) For PRs that are labeled as build and
31+
# - It's a code change
32+
# - A build label was just added
33+
# A bit complex, but prevents builds when other labels are manipulated
34+
if: >
35+
github.event_name == 'push'
36+
|| (contains(github.event.pull_request.labels.*.name, 'build')
37+
&& (github.event.action != 'labeled' || github.event.label.name == 'build')
38+
)
39+
steps:
40+
- uses: actions/checkout@v3
41+
with:
42+
ref: ${{ github.event.workflow_run.head_sha }}
43+
- name: Cache
44+
uses: actions/cache@v3
45+
with:
46+
path: ~/.m2/repository
47+
key: ${{ runner.os }}-maven-${{ github.workflow }}-${{ hashFiles('**/pom.xml') }}
48+
restore-keys: |
49+
${{ runner.os }}-maven-${{ github.workflow }}
50+
- name: Build with Maven
51+
run: mvn clean test -fae -T 2 -B -V -DcloudBuild -Dmaven.wagon.http.retryHandler.count=3 -Dmaven.wagon.httpconnectionManager.ttlSeconds=25
52+
- name: Archive build artifacts
53+
uses: actions/upload-artifact@v4
54+
if: always()
55+
with:
56+
name: reports-${{ github.run_id }}
57+
path: |
58+
**/target/rat.txt
59+
**/target/surefire-reports/*

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
<surefire.redirectTestOutputToFile>true</surefire.redirectTestOutputToFile>
3030
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3131
<!-- version properties -->
32-
<cdap.version>6.1.0-SNAPSHOT</cdap.version>
33-
<hydrator.version>2.3.0-SNAPSHOT</hydrator.version>
32+
<cdap.version>6.4.1</cdap.version>
33+
<hydrator.version>2.6.1</hydrator.version>
3434
<commons.csv.version>1.6</commons.csv.version>
3535
<hadoop.version>2.8.0</hadoop.version>
3636
<spark2.version>2.3.1</spark2.version>
@@ -398,8 +398,8 @@
398398
<version>1.1.0</version>
399399
<configuration>
400400
<cdapArtifacts>
401-
<parent>system:cdap-data-pipeline[6.1.0-SNAPSHOT,7.0.0-SNAPSHOT)</parent>
402-
<parent>system:cdap-data-streams[6.1.0-SNAPSHOT,7.0.0-SNAPSHOT)</parent>
401+
<parent>system:cdap-data-pipeline[6.4.1-SNAPSHOT,7.0.0-SNAPSHOT)</parent>
402+
<parent>system:cdap-data-streams[6.4.1-SNAPSHOT,7.0.0-SNAPSHOT)</parent>
403403
</cdapArtifacts>
404404
</configuration>
405405
<executions>

src/main/java/io/cdap/plugin/snowflake/common/util/QueryUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
public class QueryUtil {
2323

2424
// Matches "limit <number>". Also "limit $$$$" and "limit ''" which means unlimited in Snowflake.
25-
private static final String LIMIT_PATTERN = "(?i)LIMIT (''|\\$\\$\\$\\$|\\d+)";
25+
private static final String LIMIT_PATTERN = "(?i)LIMIT (NULL|''|\\$\\$\\$\\$|\\d+)";
2626
private static final String LIMIT_STRING = "limit %s";
2727

2828
private QueryUtil() {

src/main/java/io/cdap/plugin/snowflake/source/batch/SnowflakeBatchSource.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ public void prepareRun(BatchSourceContext context) {
8787
@Override
8888
public void initialize(BatchRuntimeContext context) throws Exception {
8989
super.initialize(context);
90-
SnowflakeSourceAccessor snowflakeAccessor = new SnowflakeSourceAccessor(config);
91-
Schema schema = SchemaHelper.getSchema(snowflakeAccessor, config.getImportQuery());
90+
Schema schema = SchemaHelper.getSchema(config, context.getFailureCollector());
9291
this.transformer = new SnowflakeMapToRecordTransformer(schema);
9392
}
9493

src/test/java/io/cdap/plugin/snowflake/common/BaseSnowflakeTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
package io.cdap.plugin.snowflake.common;
1818

1919
import io.cdap.cdap.etl.mock.test.HydratorTestBase;
20+
import io.cdap.cdap.test.TestConfiguration;
2021
import io.cdap.plugin.snowflake.Constants;
2122
import io.cdap.plugin.snowflake.common.client.SnowflakeAccessorTest;
2223
import io.cdap.plugin.snowflake.source.batch.SnowflakeBatchSourceConfig;
2324
import io.cdap.plugin.snowflake.source.batch.SnowflakeBatchSourceConfigBuilder;
2425
import net.snowflake.client.jdbc.SnowflakeBasicDataSource;
2526
import org.junit.Assume;
2627
import org.junit.BeforeClass;
28+
import org.junit.ClassRule;
2729
import org.junit.Rule;
2830
import org.junit.internal.AssumptionViolatedException;
2931
import org.junit.rules.TestName;
@@ -55,6 +57,9 @@ public abstract class BaseSnowflakeTest extends HydratorTestBase {
5557

5658
private static final Logger LOG = LoggerFactory.getLogger(SnowflakeAccessorTest.class);
5759

60+
@ClassRule
61+
public static final TestConfiguration TEST_CONFIG = new TestConfiguration("explore.enabled", false);
62+
5863
protected static final String ACCOUNT_NAME = System.getProperty("snowflake.test.account.name");
5964
protected static final String DATABASE = System.getProperty("snowflake.test.database");
6065
protected static final String SCHEMA = System.getProperty("snowflake.test.schema");

src/test/java/io/cdap/plugin/snowflake/common/util/SchemaHelperTest.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,24 @@ public void testGetSchemaInvalidJson() {
6565

6666
@Test
6767
public void testGetSchemaFromSnowflakeUnknownType() throws IOException {
68+
String importQuery = "SELECT * FROM someTable";
6869
MockFailureCollector collector = new MockFailureCollector(MOCK_STAGE);
6970
SnowflakeSourceAccessor snowflakeAccessor = Mockito.mock(SnowflakeSourceAccessor.class);
7071

7172
List<SnowflakeFieldDescriptor> sample = new ArrayList<>();
7273
sample.add(new SnowflakeFieldDescriptor("field1", -1000, false));
7374

74-
Mockito.when(snowflakeAccessor.describeQuery(null)).thenReturn(sample);
75+
Mockito.when(snowflakeAccessor.describeQuery(importQuery)).thenReturn(sample);
7576

76-
SchemaHelper.getSchema(snowflakeAccessor, null, collector, null);
77+
SchemaHelper.getSchema(snowflakeAccessor, null, collector, importQuery);
7778

7879
ValidationAssertions.assertValidationFailed(
7980
collector, Collections.singletonList(SnowflakeBatchSourceConfig.PROPERTY_SCHEMA));
8081
}
8182

8283
@Test
8384
public void testGetSchemaFromSnowflake() throws IOException {
85+
String importQuery = "SELECT * FROM someTable";
8486
MockFailureCollector collector = new MockFailureCollector(MOCK_STAGE);
8587
SnowflakeSourceAccessor snowflakeAccessor = Mockito.mock(SnowflakeSourceAccessor.class);
8688

@@ -142,9 +144,9 @@ public void testGetSchemaFromSnowflake() throws IOException {
142144
Schema.Field.of("field134", Schema.nullableOf(Schema.of(Schema.LogicalType.TIMESTAMP_MICROS)))
143145
);
144146

145-
Mockito.when(snowflakeAccessor.describeQuery(null)).thenReturn(sample);
147+
Mockito.when(snowflakeAccessor.describeQuery(importQuery)).thenReturn(sample);
146148

147-
Schema actual = SchemaHelper.getSchema(snowflakeAccessor, null, collector, null);
149+
Schema actual = SchemaHelper.getSchema(snowflakeAccessor, null, collector, importQuery);
148150

149151
Assert.assertTrue(collector.getValidationFailures().isEmpty());
150152
Assert.assertEquals(expected, actual);
@@ -182,4 +184,21 @@ public void testGetSchemaWhenMacroIsEnabledSchemaIsNull() {
182184
Assert.assertNull(actual);
183185

184186
}
187+
188+
@Test
189+
public void testGetSchemaManuallyUpdatedTheSchema() {
190+
Schema expected = Schema.recordOf("test",
191+
Schema.Field.of("test_field", Schema.nullableOf(Schema.of(Schema.Type.LONG)))
192+
);
193+
194+
SnowflakeBatchSourceConfig mockConfig = Mockito.mock(SnowflakeBatchSourceConfig.class);
195+
Mockito.when(mockConfig.canConnect()).thenReturn(false);
196+
Mockito.when(mockConfig.getSchema()).thenReturn(expected.toString());
197+
198+
MockFailureCollector collector = new MockFailureCollector(MOCK_STAGE);
199+
Schema actual = SchemaHelper.getSchema(mockConfig, collector);
200+
201+
Assert.assertTrue(collector.getValidationFailures().isEmpty());
202+
Assert.assertEquals(expected, actual);
203+
}
185204
}

src/test/java/io/cdap/plugin/snowflake/source/batch/SnowflakeMapToRecordTransformerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public void transform() {
5050
row.put("COLUMN_CHARACTER", "2");
5151
row.put("COLUMN_STRING", "text_115");
5252
row.put("COLUMN_TEXT", "text_116");
53-
row.put("COLUMN_BINARY", "text_117");
54-
row.put("COLUMN_VARBINARY", "text_118");
53+
row.put("COLUMN_BINARY", "746578745f313137");
54+
row.put("COLUMN_VARBINARY", "746578745f313138");
5555
row.put("COLUMN_BOOLEAN", "true");
5656
row.put("COLUMN_DATE", "2019-01-01");
5757
row.put("COLUMN_DATETIME", "2019-01-01T01:01:01+00:00");

0 commit comments

Comments
 (0)