embulk-output-snowflake 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,34 +1,32 @@
1
1
  package org.embulk.output.snowflake;
2
2
 
3
3
  import com.google.common.base.Optional;
4
+ import net.snowflake.client.jdbc.SnowflakeSQLException;
5
+ import net.snowflake.client.jdbc.SnowflakeType;
4
6
  import org.embulk.output.jdbc.AbstractJdbcOutputConnector;
7
+ import org.embulk.output.jdbc.JdbcColumn;
5
8
  import org.embulk.output.jdbc.JdbcOutputConnection;
6
9
  import org.embulk.output.jdbc.TransactionIsolation;
7
10
 
8
11
  import java.sql.Connection;
12
+ import java.sql.Driver;
9
13
  import java.sql.DriverManager;
10
14
  import java.sql.SQLException;
15
+ import java.util.Enumeration;
11
16
  import java.util.Properties;
12
17
 
13
- public class SnowflakeOutputConnector
14
- extends AbstractJdbcOutputConnector
18
+ public class SnowflakeOutputConnector extends AbstractJdbcOutputConnector
15
19
  {
16
20
  private final String url;
17
21
  private final Properties properties;
18
- private final String schemaName;
19
22
 
20
- public SnowflakeOutputConnector(String url, Properties properties, String schemaName,
21
- Optional<TransactionIsolation> transactionIsolation)
23
+ public SnowflakeOutputConnector(String url, Properties properties,
24
+ Optional<TransactionIsolation> transactionIsolation)
22
25
  {
23
26
  super(transactionIsolation);
24
- try {
25
- Class.forName("com.snowflake.client.jdbc.SnowflakeDriver");
26
- } catch (Exception ex) {
27
- throw new RuntimeException(ex);
28
- }
27
+
29
28
  this.url = url;
30
29
  this.properties = properties;
31
- this.schemaName = schemaName;
32
30
  }
33
31
 
34
32
  @Override
@@ -36,7 +34,7 @@ public class SnowflakeOutputConnector
36
34
  {
37
35
  Connection c = DriverManager.getConnection(url, properties);
38
36
  try {
39
- SnowflakeOutputConnection con = new SnowflakeOutputConnection(c, schemaName);
37
+ SnowflakeOutputConnection con = new SnowflakeOutputConnection(c);
40
38
  c = null;
41
39
  return con;
42
40
  } finally {
@@ -45,4 +43,5 @@ public class SnowflakeOutputConnector
45
43
  }
46
44
  }
47
45
  }
48
- }
46
+
47
+ }
@@ -0,0 +1,17 @@
1
+ package org.embulk.output.snowflake;
2
+
3
+ import java.util.Random;
4
+
5
+ public class SnowflakeUtils {
6
+ public static final String SOURCES =
7
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
8
+
9
+ public static String randomString(int length){
10
+ Random rand = new Random();
11
+ char[] text = new char[length];
12
+ for (int i = 0; i < length; i++) {
13
+ text[i] = SOURCES.charAt(rand.nextInt(SOURCES.length()));
14
+ }
15
+ return new String(text);
16
+ }
17
+ }
@@ -0,0 +1,61 @@
1
+ package org.embulk.output.snowflake;
2
+
3
+ import com.fasterxml.jackson.annotation.JsonProperty;
4
+ import com.google.common.base.Optional;
5
+
6
+ public class StageIdentifier {
7
+ private String database;
8
+ private String schemaName;
9
+ private String stageName;
10
+ private Optional<String> destPrefix;
11
+
12
+ public StageIdentifier(String database, String schemaName, String stageName, Optional<String> destPrefix) {
13
+ this.database = database;
14
+ this.schemaName = schemaName;
15
+ this.stageName = stageName;
16
+ this.destPrefix = destPrefix;
17
+ }
18
+
19
+ public StageIdentifier() {
20
+ }
21
+
22
+ @JsonProperty
23
+ public String getDatabase() {
24
+ return database;
25
+ }
26
+
27
+ @JsonProperty
28
+ public void setDatabase(String database) {
29
+ this.database = database;
30
+ }
31
+
32
+ @JsonProperty
33
+ public String getSchemaName() {
34
+ return schemaName;
35
+ }
36
+
37
+ @JsonProperty
38
+ public void setSchemaName(String schemaName) {
39
+ this.schemaName = schemaName;
40
+ }
41
+
42
+ @JsonProperty
43
+ public String getStageName() {
44
+ return stageName;
45
+ }
46
+
47
+ @JsonProperty
48
+ public void setStageName(String stageName) {
49
+ this.stageName = stageName;
50
+ }
51
+
52
+ @JsonProperty
53
+ public Optional<String> getDestPrefix() {
54
+ return destPrefix;
55
+ }
56
+
57
+ @JsonProperty
58
+ public void setDestPrefix(Optional<String> destPrefix) {
59
+ this.destPrefix = destPrefix;
60
+ }
61
+ }
@@ -0,0 +1,20 @@
1
+ package org.embulk.output.snowflake;
2
+
3
+ import com.google.common.base.Optional;
4
+ import org.embulk.output.SnowflakeOutputPlugin;
5
+
6
+ import java.text.SimpleDateFormat;
7
+ import java.util.Date;
8
+
9
+ public class StageIdentifierHolder {
10
+ private static final String pattern = "yyyyMMdd";
11
+ private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
12
+ private static final String date = simpleDateFormat.format(new Date());
13
+ private static final String salt = SnowflakeUtils.randomString(6);
14
+ private static final String snowflakeStageName = "embulk_snowflake_" + date + salt;
15
+ private static final String snowflakeDestPrefix = date + "_" + salt;
16
+
17
+ public static StageIdentifier getStageIdentifier(SnowflakeOutputPlugin.SnowflakePluginTask t){
18
+ return new StageIdentifier(t.getDatabase(), t.getSchema(), snowflakeStageName, Optional.of(snowflakeDestPrefix));
19
+ }
20
+ }
@@ -0,0 +1,5 @@
1
+ package org.embulk.output.snowflake;
2
+
3
+ public class TestSnowflakeOutputPlugin
4
+ {
5
+ }
metadata CHANGED
@@ -1,33 +1,75 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-snowflake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Piotr Wilkowski
7
+ - giwa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-29 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Inserts or updates records to a table.
11
+ date: 2020-11-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ name: bundler
20
+ prerelease: false
21
+ type: :development
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '12.0'
33
+ name: rake
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.0'
41
+ description: Dumps records to Snowflake.
14
42
  email:
15
- - piwil@wp.pl
43
+ - ugw.gi.world@gmail.com
16
44
  executables: []
17
45
  extensions: []
18
46
  extra_rdoc_files: []
19
47
  files:
48
+ - ".gitignore"
49
+ - LICENSE.txt
20
50
  - README.md
21
51
  - build.gradle
22
- - classpath/embulk-output-jdbc-0.1.1.jar
23
- - classpath/embulk-output-snowflake-0.1.1.jar
52
+ - classpath/embulk-output-jdbc-0.8.7.jar
53
+ - classpath/embulk-output-snowflake-0.2.0.jar
54
+ - config/checkstyle/checkstyle.xml
55
+ - config/checkstyle/default.xml
56
+ - default_jdbc_driver/snowflake-jdbc-3.12.8.jar
57
+ - gradle/wrapper/gradle-wrapper.jar
58
+ - gradle/wrapper/gradle-wrapper.properties
59
+ - gradlew
60
+ - gradlew.bat
24
61
  - lib/embulk/output/snowflake.rb
25
62
  - src/main/java/org/embulk/output/SnowflakeOutputPlugin.java
63
+ - src/main/java/org/embulk/output/snowflake/SnowflakeCopyBatchInsert.java
26
64
  - src/main/java/org/embulk/output/snowflake/SnowflakeOutputConnection.java
27
65
  - src/main/java/org/embulk/output/snowflake/SnowflakeOutputConnector.java
28
- homepage: ''
66
+ - src/main/java/org/embulk/output/snowflake/SnowflakeUtils.java
67
+ - src/main/java/org/embulk/output/snowflake/StageIdentifier.java
68
+ - src/main/java/org/embulk/output/snowflake/StageIdentifierHolder.java
69
+ - src/test/java/org/embulk/output/snowflake/TestSnowflakeOutputPlugin.java
70
+ homepage: https://github.com/trocco-io/embulk-output-snowflake
29
71
  licenses:
30
- - Apache 2.0
72
+ - MIT
31
73
  metadata: {}
32
74
  post_install_message:
33
75
  rdoc_options: []
@@ -45,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
87
  version: '0'
46
88
  requirements: []
47
89
  rubyforge_project:
48
- rubygems_version: 2.4.8
90
+ rubygems_version: 2.6.13
49
91
  signing_key:
50
92
  specification_version: 4
51
93
  summary: Snowflake output plugin for Embulk