embulk-filter-to_json 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61aa0b5546d040c6b672178d874162e4d0aefe68
4
- data.tar.gz: 35ab7bda1b560d51d4364e423a7cef2fd6bb065b
3
+ metadata.gz: 8a2d6613b30db7bf15e431eaa828fa6266548b09
4
+ data.tar.gz: e4f4bdc55bca27448165e800a3e661c63bf21f00
5
5
  SHA512:
6
- metadata.gz: 1bff2741559fafdbf38e4bde4066723817de5ab026b1952f2b5ba811b635abb8cdca8e9197766b480023c6f894d5e6a00ac52fd445ed301ae92aed39e12c7895
7
- data.tar.gz: e48ce9eea0782dd91a63220b6147cb8e70a8607ce7c3747275aa870066cf35f7e7edc281e53852c629ecc4384f71534db9ab337c279212c59c975eb2acc6df62
6
+ metadata.gz: 63edc8f69fc088734834d8672192c30fb44bb3cb6107eacb82a918fe2b2983e3156be8b5c0cd57fca0cb2d3898fcc615521647ee64ead6467ab6e7d3119e35f6
7
+ data.tar.gz: f104fe440ab7d1b46579d22c3a93a51abd906c9af0534a592e568d6bed5f146cea7b5412efe4c17534f094309a87f664ae609c279dfb43225580291e0b650815
@@ -1,3 +1,12 @@
1
+ 0.0.4 (2016-01-25)
2
+ ==================
3
+ - incompatible change: `timezone` / `format` options removed
4
+ - add: `default_timezone` / `default_format` options
5
+
6
+ 0.0.3 (2016-01-25)
7
+ ==================
8
+ - add: support timezone and timestamp format options
9
+
1
10
  0.0.2 (2016-01-23)
2
11
  ==================
3
12
  - incompatible change: option `column_name` is removed
data/README.md CHANGED
@@ -12,6 +12,8 @@ Convert a record to jsonl.
12
12
  - **name** (string, default: `"json_payload"`)
13
13
  - **type** string or json (string, default: `"string"`)
14
14
  - **skip_if_null**: input column name list (array of string, default: `[]`)
15
+ - **default_timezone**: option for timestamp column, specify the timezone of timestamp value (string, default is `UTC`)
16
+ - **default_format**: option for timestamp column, specify the format of timestamp value (string, default is `%Y-%m-%d %H:%M:%S.%N %z`)
15
17
 
16
18
  ## Example
17
19
 
@@ -22,6 +24,7 @@ filters:
22
24
  name: test
23
25
  type: string
24
26
  skip_if_null: [id]
27
+ timezone: Asia/Tokyo
25
28
  ```
26
29
 
27
30
  ## Run Example
@@ -13,7 +13,7 @@ configurations {
13
13
  provided
14
14
  }
15
15
 
16
- version = "0.0.2"
16
+ version = "0.0.4"
17
17
 
18
18
  sourceCompatibility = 1.7
19
19
  targetCompatibility = 1.7
@@ -19,5 +19,6 @@ filters:
19
19
  name: test
20
20
  type: string
21
21
  skip_if_null: [id]
22
+ default_timezone: Asia/Tokyo
22
23
  out:
23
24
  type: stdout
@@ -2,7 +2,6 @@ package org.embulk.filter.to_json;
2
2
 
3
3
  import com.fasterxml.jackson.core.JsonProcessingException;
4
4
  import com.fasterxml.jackson.databind.ObjectMapper;
5
- import com.google.common.base.Optional;
6
5
  import com.google.common.collect.Lists;
7
6
  import com.google.common.collect.Maps;
8
7
  import org.embulk.config.ConfigException;
@@ -10,8 +9,8 @@ import org.embulk.spi.Column;
10
9
  import org.embulk.spi.ColumnVisitor;
11
10
  import org.embulk.spi.PageBuilder;
12
11
  import org.embulk.spi.PageReader;
13
- import org.embulk.spi.Schema;
14
12
  import org.embulk.spi.json.JsonParser;
13
+ import org.embulk.spi.time.TimestampFormatter;
15
14
  import org.embulk.spi.type.Types;
16
15
 
17
16
  import java.io.IOException;
@@ -107,15 +106,17 @@ public class ColumnVisitorToJsonImpl
107
106
  private final Map<String, Object> map;
108
107
  private final PageReader pageReader;
109
108
  private final ColumnSetter columnSetter;
109
+ private final TimestampFormatter timestampFormatter;
110
110
  private List<String> skipColumnsIfNull = Lists.newArrayList();
111
111
  private boolean skipRecordFlag = false;
112
112
 
113
113
  ColumnVisitorToJsonImpl(PageReader pageReader, PageBuilder pageBuilder,
114
- Column outputColumn, List<String> skipColumnsIfNull)
114
+ Column outputColumn, TimestampFormatter timestampFormatter, List<String> skipColumnsIfNull)
115
115
  {
116
116
  this.map = Maps.newHashMap();
117
117
  this.pageReader = pageReader;
118
118
  this.columnSetter = new ColumnSetter(pageBuilder, outputColumn);
119
+ this.timestampFormatter = timestampFormatter;
119
120
  this.skipColumnsIfNull = skipColumnsIfNull;
120
121
  }
121
122
 
@@ -171,7 +172,8 @@ public class ColumnVisitorToJsonImpl
171
172
  putNull(column);
172
173
  return;
173
174
  }
174
- map.put(column.getName(), pageReader.getTimestamp(column).toString());
175
+ String value = timestampFormatter.format(pageReader.getTimestamp(column));
176
+ map.put(column.getName(), value);
175
177
  }
176
178
 
177
179
  @Override
@@ -2,11 +2,10 @@ package org.embulk.filter.to_json;
2
2
 
3
3
  import com.google.common.base.Optional;
4
4
  import com.google.common.collect.ImmutableList;
5
- import com.google.common.collect.Lists;
6
- import com.google.common.collect.Maps;
7
5
  import org.embulk.config.Config;
8
6
  import org.embulk.config.ConfigDefault;
9
7
  import org.embulk.config.ConfigException;
8
+ import org.embulk.config.ConfigInject;
10
9
  import org.embulk.config.ConfigSource;
11
10
  import org.embulk.config.Task;
12
11
  import org.embulk.config.TaskSource;
@@ -19,12 +18,14 @@ import org.embulk.spi.PageBuilder;
19
18
  import org.embulk.spi.PageOutput;
20
19
  import org.embulk.spi.PageReader;
21
20
  import org.embulk.spi.Schema;
21
+ import org.embulk.spi.time.TimestampFormatter;
22
22
  import org.embulk.spi.type.Type;
23
23
  import org.embulk.spi.type.Types;
24
+ import org.joda.time.DateTimeZone;
25
+ import org.jruby.embed.ScriptingContainer;
24
26
  import org.slf4j.Logger;
25
27
 
26
28
  import java.util.List;
27
- import java.util.Map;
28
29
 
29
30
  public class ToJsonFilterPlugin
30
31
  implements FilterPlugin
@@ -45,6 +46,17 @@ public class ToJsonFilterPlugin
45
46
  @Config("skip_if_null")
46
47
  @ConfigDefault("[]")
47
48
  List<String> getColumnNamesSkipIfNull();
49
+
50
+ @Config("default_timezone")
51
+ @ConfigDefault("\"UTC\"")
52
+ String getDefaultTimezone();
53
+
54
+ @Config("default_format")
55
+ @ConfigDefault("\"%Y-%m-%d %H:%M:%S.%N %z\"")
56
+ String getDefaultFormat();
57
+
58
+ @ConfigInject
59
+ ScriptingContainer getJRuby();
48
60
  }
49
61
 
50
62
  public interface JsonColumn
@@ -117,12 +129,16 @@ public class ToJsonFilterPlugin
117
129
  final Schema outputSchema, final PageOutput output)
118
130
  {
119
131
  final PluginTask task = taskSource.loadTask(PluginTask.class);
132
+ final DateTimeZone timezone = DateTimeZone.forID(task.getDefaultTimezone());
133
+ final TimestampFormatter timestampFormatter = new TimestampFormatter(task.getJRuby(), task.getDefaultFormat(), timezone);
134
+ final List<String> columnNamesSkipIfNull = task.getColumnNamesSkipIfNull();
135
+
120
136
  return new PageOutput()
121
137
  {
122
138
  private final PageReader pageReader = new PageReader(inputSchema);
123
139
  private final PageBuilder pageBuilder = new PageBuilder(Exec.getBufferAllocator(), outputSchema, output);
124
140
  private final ColumnVisitorToJsonImpl visitor = new ColumnVisitorToJsonImpl(pageReader, pageBuilder,
125
- outputSchema.getColumn(JSON_COLUMN_INDEX), task.getColumnNamesSkipIfNull());
141
+ outputSchema.getColumn(JSON_COLUMN_INDEX), timestampFormatter, columnNamesSkipIfNull);
126
142
 
127
143
  @Override
128
144
  public void add(Page page)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-filter-to_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Civitaspo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-23 00:00:00.000000000 Z
11
+ date: 2016-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,7 +62,7 @@ files:
62
62
  - src/main/java/org/embulk/filter/to_json/ColumnVisitorToJsonImpl.java
63
63
  - src/main/java/org/embulk/filter/to_json/ToJsonFilterPlugin.java
64
64
  - src/test/java/org/embulk/filter/to_json/TestToJsonFilterPlugin.java
65
- - classpath/embulk-filter-to_json-0.0.2.jar
65
+ - classpath/embulk-filter-to_json-0.0.4.jar
66
66
  homepage: https://github.com/civitaspo/embulk-filter-to_json
67
67
  licenses:
68
68
  - MIT