embulk-input-randomj 0.1.5 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02171e37d576c90cc852682e1840fb7ffa99a2bb
4
- data.tar.gz: 37cf924f4584b8457dd918291bcb23aae68ab13e
3
+ metadata.gz: ab0f7f5168b89c9ae46492aca972aebfda891f20
4
+ data.tar.gz: d3ea8441e1dd85765cf8f5ca940a67d6c4b45f9d
5
5
  SHA512:
6
- metadata.gz: 27123e79c34a9c01f950d984835d0777087d568f7e30c9fc32c6ede1434add8605ebe1f7daed7996884a432586fde29a39e105e112cf574221bc910ea258ed54
7
- data.tar.gz: ac416c1b693ff0601b15dcf4ab009cf2fa92f7a8d68bbd07dc297ece7975c5a7fa7d5642472c7a3c0853957d494047b2fac7acd11b8f2cd17049423489216022
6
+ metadata.gz: 094c98bdd73e06a67981422f0a1b4974e95b921056902b8eb3f1438d5171a0e926a8ee9d1d483103861a10b2902d72cd11390e96f9bc5dca7f9f5490d01a36bb
7
+ data.tar.gz: 2c8ed6182a6891aa39a72894abcdc983756cd8cc411159fa8e730d0628425bd0492a4c1e73de62f1d1f0cc21deb97747ada43c409c3f9d4b50ae9c28ed7bac5b
@@ -3,6 +3,7 @@ plugins {
3
3
  id "com.github.jruby-gradle.base" version "0.1.5"
4
4
  id "java"
5
5
  id "checkstyle"
6
+ id "findbugs"
6
7
  }
7
8
  import com.github.jrubygradle.JRubyExec
8
9
  repositories {
@@ -13,7 +14,7 @@ configurations {
13
14
  provided
14
15
  }
15
16
 
16
- version = "0.1.5"
17
+ version = "0.2.0"
17
18
 
18
19
  sourceCompatibility = 1.8
19
20
  targetCompatibility = 1.8
@@ -0,0 +1,89 @@
1
+ package org.embulk.input.randomj;
2
+
3
+ import org.apache.commons.text.CharacterPredicates;
4
+ import org.apache.commons.text.RandomStringGenerator;
5
+ import org.embulk.input.randomj.RandomjInputPlugin.PluginTask;
6
+ import org.embulk.spi.Column;
7
+ import org.embulk.spi.ColumnVisitor;
8
+ import org.embulk.spi.PageBuilder;
9
+ import org.embulk.spi.time.Timestamp;
10
+
11
+ import java.time.LocalDateTime;
12
+ import java.time.ZoneId;
13
+ import java.util.Random;
14
+
15
+ public class RandomColumnVisitor
16
+ implements ColumnVisitor
17
+ {
18
+ private final PageBuilder pageBuilder;
19
+ private final PluginTask task;
20
+ private final Integer row;
21
+ private final Random rnd;
22
+ private final RandomStringGenerator generator = new RandomStringGenerator.Builder()
23
+ .withinRange('0', 'z')
24
+ .filteredBy(CharacterPredicates.LETTERS, CharacterPredicates.DIGITS)
25
+ .build();
26
+ private final ZoneId zoneId = ZoneId.systemDefault();
27
+
28
+ public RandomColumnVisitor(PageBuilder pageBuilder, PluginTask task, Integer row)
29
+ {
30
+ this.task = task;
31
+ this.pageBuilder = pageBuilder;
32
+ this.row = row;
33
+ this.rnd = new Random();
34
+ }
35
+
36
+ @Override
37
+ public void booleanColumn(Column column)
38
+ {
39
+ if (Math.random() < 0.5) {
40
+ pageBuilder.setBoolean(column, false);
41
+ }
42
+ else {
43
+ pageBuilder.setBoolean(column, true);
44
+ }
45
+ }
46
+
47
+ @Override
48
+ public void longColumn(Column column)
49
+ {
50
+ final String pk = task.getPrimaryKey();
51
+ if (column.getName().equals(pk)) {
52
+ pageBuilder.setLong(column, row);
53
+ }
54
+ else {
55
+ pageBuilder.setLong(column, rnd.nextInt(10000));
56
+ }
57
+ }
58
+
59
+ @Override
60
+ public void doubleColumn(Column column)
61
+ {
62
+ pageBuilder.setDouble(column, rnd.nextDouble() * 10000);
63
+ }
64
+
65
+ @Override
66
+ public void stringColumn(Column column)
67
+ {
68
+ pageBuilder.setString(column, generator.generate(32));
69
+ }
70
+
71
+ @Override
72
+ public void timestampColumn(Column column)
73
+ {
74
+ final double randd = Math.random();
75
+ LocalDateTime randomDate = LocalDateTime.now()
76
+ .plusDays((long) (randd * 100))
77
+ .plusSeconds((long) (randd * 1000000));
78
+ Timestamp timestamp = Timestamp.ofEpochSecond(
79
+ randomDate.atZone(zoneId).toEpochSecond()
80
+ );
81
+ pageBuilder.setTimestamp(column, timestamp);
82
+ }
83
+
84
+ @Override
85
+ public void jsonColumn(Column column)
86
+ {
87
+ throw new UnsupportedOperationException("orc output plugin does not support json type");
88
+ }
89
+ }
@@ -9,20 +9,14 @@ import org.embulk.config.ConfigSource;
9
9
  import org.embulk.config.Task;
10
10
  import org.embulk.config.TaskReport;
11
11
  import org.embulk.config.TaskSource;
12
- import org.embulk.spi.Column;
13
12
  import org.embulk.spi.Exec;
14
13
  import org.embulk.spi.InputPlugin;
15
14
  import org.embulk.spi.PageBuilder;
16
15
  import org.embulk.spi.PageOutput;
17
16
  import org.embulk.spi.Schema;
18
17
  import org.embulk.spi.SchemaConfig;
19
- import org.embulk.spi.time.Timestamp;
20
- import org.embulk.spi.type.Type;
21
18
 
22
- import java.time.LocalDateTime;
23
- import java.time.ZoneId;
24
19
  import java.util.List;
25
- import java.util.Random;
26
20
  import java.util.stream.IntStream;
27
21
 
28
22
  public class RandomjInputPlugin
@@ -90,54 +84,12 @@ public class RandomjInputPlugin
90
84
  Integer rows = task.getRows();
91
85
  try (PageBuilder pagebuilder =
92
86
  new PageBuilder(Exec.getBufferAllocator(), schema, output)) {
93
- Random rnd = new Random();
94
87
  IntStream.rangeClosed(
95
88
  taskIndex * rows + 1,
96
89
  taskIndex * rows + rows
97
90
  ).boxed().forEach(rowNumber -> {
98
- for (Column column : schema.getColumns()) {
99
- final Integer i = column.getIndex();
100
- Type t = column.getType();
101
- switch (t.getName()) {
102
- case "long":
103
- final String pk = task.getPrimaryKey();
104
- if (column.getName().equals(pk)) {
105
- pagebuilder.setLong(i, rowNumber);
106
- }
107
- else {
108
- pagebuilder.setLong(i, rnd.nextInt(10000));
109
- }
110
- break;
111
- case "double":
112
- pagebuilder.setDouble(i, rnd.nextDouble() * 10000);
113
- break;
114
- case "boolean":
115
- if (Math.random() < 0.5) {
116
- pagebuilder.setBoolean(i, false);
117
- }
118
- else {
119
- pagebuilder.setBoolean(i, true);
120
- }
121
- break;
122
- case "string":
123
- pagebuilder.setString(i, generator.generate(32));
124
- break;
125
- case "timestamp":
126
- final ZoneId zoneId = ZoneId.systemDefault();
127
- final double randd = Math.random();
128
- LocalDateTime randomDate = LocalDateTime.now()
129
- .plusDays((long) (randd * 100))
130
- .plusSeconds((long) (randd * 1000000));
131
- Timestamp timestamp = Timestamp.ofEpochSecond(
132
- randomDate.atZone(zoneId).toEpochSecond()
133
- );
134
- pagebuilder.setTimestamp(column, timestamp);
135
- break;
136
- default:
137
- System.out.println("Unsupported type");
138
- break;
139
- }
140
- }
91
+ RandomColumnVisitor visitor = new RandomColumnVisitor(pagebuilder, task, rowNumber);
92
+ schema.visitColumns(visitor);
141
93
  pagebuilder.addRecord();
142
94
  });
143
95
  pagebuilder.finish();
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-randomj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yuokada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-04 00:00:00.000000000 Z
11
+ date: 2017-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -52,18 +52,17 @@ files:
52
52
  - build.gradle
53
53
  - config/checkstyle/checkstyle.xml
54
54
  - config/checkstyle/default.xml
55
- - embulk-input-randomj.iml
56
55
  - example/config.yml
57
56
  - gradle/wrapper/gradle-wrapper.jar
58
57
  - gradle/wrapper/gradle-wrapper.properties
59
58
  - gradlew
60
- - gradlew.bat
61
59
  - lib/embulk/input/randomj.rb
60
+ - src/main/java/org/embulk/input/randomj/RandomColumnVisitor.java
62
61
  - src/main/java/org/embulk/input/randomj/RandomjInputPlugin.java
63
62
  - src/test/java/org/embulk/input/randomj/TestRandomjInputPlugin.java
64
63
  - classpath/commons-lang3-3.5.jar
65
64
  - classpath/commons-text-1.1.jar
66
- - classpath/embulk-input-randomj-0.1.5.jar
65
+ - classpath/embulk-input-randomj-0.2.0.jar
67
66
  homepage: https://github.com/yuokada/embulk-input-randomj
68
67
  licenses:
69
68
  - MIT
@@ -1,13 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module external.linked.project.id="embulk-input-randomj" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="0.1.5" type="JAVA_MODULE" version="4">
3
- <component name="NewModuleRootManager" inherit-compiler-output="true">
4
- <exclude-output />
5
- <content url="file://$MODULE_DIR$">
6
- <excludeFolder url="file://$MODULE_DIR$/.gradle" />
7
- <excludeFolder url="file://$MODULE_DIR$/build" />
8
- <excludeFolder url="file://$MODULE_DIR$/out" />
9
- </content>
10
- <orderEntry type="inheritedJdk" />
11
- <orderEntry type="sourceFolder" forTests="false" />
12
- </component>
13
- </module>
@@ -1,84 +0,0 @@
1
- @if "%DEBUG%" == "" @echo off
2
- @rem ##########################################################################
3
- @rem
4
- @rem Gradle startup script for Windows
5
- @rem
6
- @rem ##########################################################################
7
-
8
- @rem Set local scope for the variables with windows NT shell
9
- if "%OS%"=="Windows_NT" setlocal
10
-
11
- set DIRNAME=%~dp0
12
- if "%DIRNAME%" == "" set DIRNAME=.
13
- set APP_BASE_NAME=%~n0
14
- set APP_HOME=%DIRNAME%
15
-
16
- @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17
- set DEFAULT_JVM_OPTS=
18
-
19
- @rem Find java.exe
20
- if defined JAVA_HOME goto findJavaFromJavaHome
21
-
22
- set JAVA_EXE=java.exe
23
- %JAVA_EXE% -version >NUL 2>&1
24
- if "%ERRORLEVEL%" == "0" goto init
25
-
26
- echo.
27
- echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28
- echo.
29
- echo Please set the JAVA_HOME variable in your environment to match the
30
- echo location of your Java installation.
31
-
32
- goto fail
33
-
34
- :findJavaFromJavaHome
35
- set JAVA_HOME=%JAVA_HOME:"=%
36
- set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37
-
38
- if exist "%JAVA_EXE%" goto init
39
-
40
- echo.
41
- echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42
- echo.
43
- echo Please set the JAVA_HOME variable in your environment to match the
44
- echo location of your Java installation.
45
-
46
- goto fail
47
-
48
- :init
49
- @rem Get command-line arguments, handling Windows variants
50
-
51
- if not "%OS%" == "Windows_NT" goto win9xME_args
52
-
53
- :win9xME_args
54
- @rem Slurp the command line arguments.
55
- set CMD_LINE_ARGS=
56
- set _SKIP=2
57
-
58
- :win9xME_args_slurp
59
- if "x%~1" == "x" goto execute
60
-
61
- set CMD_LINE_ARGS=%*
62
-
63
- :execute
64
- @rem Setup the command line
65
-
66
- set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67
-
68
- @rem Execute Gradle
69
- "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70
-
71
- :end
72
- @rem End local scope for the variables with windows NT shell
73
- if "%ERRORLEVEL%"=="0" goto mainEnd
74
-
75
- :fail
76
- rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77
- rem the _cmd.exe /c_ return code!
78
- if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79
- exit /b 1
80
-
81
- :mainEnd
82
- if "%OS%"=="Windows_NT" endlocal
83
-
84
- :omega