From 4c10228497fb2f75bdb51f3e2191df48bd571c46 Mon Sep 17 00:00:00 2001 From: Phu Nguyen Date: Mon, 4 Oct 2021 10:21:56 +0700 Subject: [PATCH 1/2] Graceful shutdown in case no records for dynamic schema --- .../java/org/embulk/input/jira/JiraInputPlugin.java | 13 ++++++++++--- .../org/embulk/input/jira/JiraInputPluginTest.java | 4 +--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/embulk/input/jira/JiraInputPlugin.java b/src/main/java/org/embulk/input/jira/JiraInputPlugin.java index 3b7e224..f7464b1 100644 --- a/src/main/java/org/embulk/input/jira/JiraInputPlugin.java +++ b/src/main/java/org/embulk/input/jira/JiraInputPlugin.java @@ -109,9 +109,16 @@ public ConfigDiff transaction(final ConfigSource config, if (task.getDynamicSchema()) { final JiraClient jiraClient = getJiraClient(); final List columns = new ArrayList<>(); - final List guessedColumns = getGuessedColumns(jiraClient, task); - for (final ConfigDiff guessedColumn : guessedColumns) { - columns.add(new ColumnConfig(CONFIG_MAPPER_FACTORY.newConfigSource().merge(guessedColumn))); + try { + final List guessedColumns = getGuessedColumns(jiraClient, task); + for (final ConfigDiff guessedColumn : guessedColumns) { + columns.add(new ColumnConfig(CONFIG_MAPPER_FACTORY.newConfigSource().merge(guessedColumn))); + } + } + catch (final ConfigException e) { + if (!e.getMessage().equals("Could not guess schema due to empty data set")) { + throw e; + } } schemaConfig = new SchemaConfig(columns); } diff --git a/src/test/java/org/embulk/input/jira/JiraInputPluginTest.java b/src/test/java/org/embulk/input/jira/JiraInputPluginTest.java index f3dc5bd..6cfbe5c 100644 --- a/src/test/java/org/embulk/input/jira/JiraInputPluginTest.java +++ b/src/test/java/org/embulk/input/jira/JiraInputPluginTest.java @@ -10,7 +10,6 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.embulk.EmbulkTestRuntime; import org.embulk.config.ConfigDiff; -import org.embulk.config.ConfigException; import org.embulk.config.ConfigSource; import org.embulk.config.TaskReport; import org.embulk.config.TaskSource; @@ -90,7 +89,6 @@ public void test_run_withEmptyResult() throws IOException verify(pageBuilder, times(1)).finish(); } - @Test(expected = ConfigException.class) public void test_runDynamicSchema_withEmptyResult() throws IOException { final JsonObject searchResponse = data.get("emptyResult").getAsJsonObject(); @@ -99,8 +97,8 @@ public void test_runDynamicSchema_withEmptyResult() throws IOException .thenReturn(searchResponse.get("statusCode").getAsInt()); when(response.getEntity()) .thenReturn(new StringEntity(searchResponse.get("body").toString())); - plugin.transaction(TestHelpers.dynamicSchemaConfig(), new Control()); + verify(pageBuilder, times(0)).addRecord(); } @Test From 0d382ea2946306cb232cd2fe61dc0b913dd54425 Mon Sep 17 00:00:00 2001 From: Phu Nguyen Date: Mon, 4 Oct 2021 10:24:15 +0700 Subject: [PATCH 2/2] Update readme and changelog --- CHANGELOG.md | 4 ++++ build.gradle | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc231ab..3d10377 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.14 - 2021-10-12 +* [enhancement] Graceful exit in case no data of dynamic schema +* PR [#70](https://github.com/treasure-data/embulk-input-jira/pull/70) + ## 0.2.13 - 2021-09-30 * [enhancement] Support dynamic schema * PR [#69](https://github.com/treasure-data/embulk-input-jira/pull/69) diff --git a/build.gradle b/build.gradle index 8770524..9c0d720 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ repositories { jcenter() } -version = "0.2.13" +version = "0.2.14" group = "com.treasuredata.embulk.plugins" description = "JIRA Embulk input plugin."