Skip to content

Commit 51c245b

Browse files
authored
Merge pull request #45 from trocco-io/feature/fix-insert
複数クエリの許可設定を追加
2 parents e77e639 + 83edf7b commit 51c245b

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/main/java/org/embulk/output/SnowflakeOutputPlugin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ protected JdbcOutputConnector getConnector(PluginTask task, boolean retryableMet
9494
// So, set this parameter true.
9595
// https://github.com/snowflakedb/snowflake-jdbc/blob/032bdceb408ebeedb1a9ad4edd9ee6cf7c6bb470/src/main/java/net/snowflake/client/jdbc/SnowflakeDatabaseMetaData.java#L1261-L1269
9696
props.setProperty("CLIENT_METADATA_REQUEST_USE_CONNECTION_CTX", "true");
97+
props.setProperty("MULTI_STATEMENT_COUNT", "0");
9798

9899
props.putAll(t.getOptions());
99100

src/test/java/org/embulk/output/snowflake/TestSnowflakeOutputPlugin.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public class TestSnowflakeOutputPlugin {
101101
props.setProperty("warehouse", TEST_SNOWFLAKE_WAREHOUSE);
102102
props.setProperty("db", TEST_SNOWFLAKE_DB);
103103
props.setProperty("schema", TEST_SNOWFLAKE_SCHEMA);
104+
props.setProperty("MULTI_STATEMENT_COUNT", "0");
104105
TEST_PROPERTIES = props;
105106
}
106107

@@ -287,6 +288,51 @@ public void testRuntimeReplaceStringTable() throws IOException {
287288
}
288289
}
289290

291+
@Test
292+
public void testExecuteMultiQuery() throws IOException {
293+
File in = testFolder.newFile(SnowflakeUtils.randomString(8) + ".csv");
294+
List<String> lines =
295+
Stream.of("c0:double, c1:string", "0.0,aaa", "0.1,bbb", "1.2,ccc")
296+
.collect(Collectors.toList());
297+
Files.write(in.toPath(), lines);
298+
299+
String targetTableName = generateTemporaryTableName();
300+
String targetTableFullName =
301+
String.format(
302+
"\"%s\".\"%s\".\"%s\"", TEST_SNOWFLAKE_DB, TEST_SNOWFLAKE_SCHEMA, targetTableName);
303+
runQuery(
304+
String.format("create table %s (c0 FLOAT, c1 STRING)", targetTableFullName),
305+
foreachResult(rs_ -> {}));
306+
307+
String temporaryTableName = generateTemporaryTableName();
308+
309+
final ConfigSource config =
310+
CONFIG_MAPPER_FACTORY
311+
.newConfigSource()
312+
.set("type", "snowflake")
313+
.set("user", TEST_SNOWFLAKE_USER)
314+
.set("password", TEST_SNOWFLAKE_PASSWORD)
315+
.set("host", TEST_SNOWFLAKE_HOST)
316+
.set("database", TEST_SNOWFLAKE_DB)
317+
.set("warehouse", TEST_SNOWFLAKE_WAREHOUSE)
318+
.set("schema", TEST_SNOWFLAKE_SCHEMA)
319+
.set("mode", "replace")
320+
.set("table", temporaryTableName)
321+
.set(
322+
"after_load",
323+
String.format(
324+
"insert into \"%s\" select * from \"%s\"; drop table \"%s\";",
325+
targetTableName, temporaryTableName, temporaryTableName));
326+
embulk.runOutput(config, in.toPath());
327+
328+
runQuery(
329+
String.format("select count(*) from %s;", targetTableFullName),
330+
foreachResult(
331+
rs -> {
332+
assertEquals(3, rs.getInt(1));
333+
}));
334+
}
335+
290336
@Test
291337
public void testRuntimeInsertStringTable() throws IOException {
292338
File in = testFolder.newFile(SnowflakeUtils.randomString(8) + ".csv");

0 commit comments

Comments
 (0)