Skip to content

Commit 6d7a9b4

Browse files
committed
PLUGIN-1883: Fix failing test case and set schema to null if both importQuery & tableName is null
1 parent 482c537 commit 6d7a9b4

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private static Schema getParsedSchema(String schema) {
115115
}
116116
try {
117117
return Schema.parseJson(schema);
118-
} catch (IOException e) {
118+
} catch (IOException | IllegalStateException e) {
119119
throw new SchemaParseException(e);
120120
}
121121
}
@@ -129,7 +129,7 @@ private static Schema getSchema(SnowflakeAccessor snowflakeAccessor, @Nullable S
129129
} else if (!Strings.isNullOrEmpty(importQuery)) {
130130
result = snowflakeAccessor.describeQuery(importQuery);
131131
} else {
132-
throw new SchemaParseException("Either 'Import Query' or 'Table Name' must be provided");
132+
return null;
133133
}
134134
List<Schema.Field> fields = result.stream()
135135
.map(fieldDescriptor -> Schema.Field.of(fieldDescriptor.getName(), getSchema(fieldDescriptor)))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void testGetSchemaInvalidJson() {
6565
}
6666

6767
@Test
68-
public void testGetSchemaFromSnowflakeUnknownType() throws IOException {
68+
public void testGetSchemaFromSnowflakeUnknownType() throws IOException, SQLException {
6969
String importQuery = "SELECT * FROM someTable";
7070
String tableName = "USER";
7171
MockFailureCollector collector = new MockFailureCollector(MOCK_STAGE);
@@ -74,7 +74,7 @@ public void testGetSchemaFromSnowflakeUnknownType() throws IOException {
7474
List<SnowflakeFieldDescriptor> sample = new ArrayList<>();
7575
sample.add(new SnowflakeFieldDescriptor("field1", -1000, false));
7676

77-
Mockito.when(snowflakeAccessor.describeQuery(importQuery)).thenReturn(sample);
77+
Mockito.when(snowflakeAccessor.describeTable(null, tableName)).thenReturn(sample);
7878

7979
SchemaHelper.getSchema(snowflakeAccessor, null, collector, tableName, importQuery);
8080

0 commit comments

Comments
 (0)