embulk-filter-calcite 0.1.0 → 0.1.1

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: fb9b57b9556e4b1ea27783f26a9e4f13275b8b92
4
- data.tar.gz: 61227ab14eceb59c0e2d40d04a101f12077cbc11
3
+ metadata.gz: a72ba31671d8572762457c6fede3f290ab0a81c2
4
+ data.tar.gz: dde80b10ba7bb64b85174a5469de93db29f89200
5
5
  SHA512:
6
- metadata.gz: d8a5c2ebc604a0af4ac45ab1c113ce2deedcaa651fd5533098fb9fc05a75f529ab8b48c522469fb71d1a89da89b8c5dd43c8f9b1540735055e074f8c8f47dca3
7
- data.tar.gz: adc86d69db46d7b426e3d869dcc687cf7324a278d6f202a0d89ac05d08124c4c0480cf288da14549644f0b7940f494f344ae08024d659000a9745f9d5b798f51
6
+ metadata.gz: 27bc215b3a74a4011271d3e082744f5eedccaa19405a2adf878e8aad0688d624f1f24b02d21a2beb1ff59e409b770b1f7fa6810ef89389ec91c96afd5df1d1d6
7
+ data.tar.gz: cc83d78f01ca54a125f39598db233a7acee8eb690e54bd069d290b318c409515fb7678f5b579817747b2ad616b51568530b892ff50ff5e69ce137849aa9e8ad7
@@ -1,3 +1,7 @@
1
+ ## 0.1.1 - 2017-03-22
2
+
3
+ * [bug fix] Use default_timezone option to configure JDBC connection timeZone param [#11](https://github.com/muga/embulk-filter-calcite/pull/11)
4
+
1
5
  ## 0.1.0 - 2017-03-17
2
6
 
3
7
  The first release
data/README.md CHANGED
@@ -33,8 +33,8 @@ Data types by Apache Calcite: https://calcite.apache.org/docs/reference.html#dat
33
33
 
34
34
  ## Configuration
35
35
 
36
- - **query**: SQL to run (string)
37
- - **default_timezone**: If the sql type of a column is `date`/`time`/`datetime` and the embulk type is `string`, column values are formatted int this default_timezone. You can overwrite timezone for each columns using column_options option. (string, default: `UTC`)
36
+ - **query**: SQL to run (string, required)
37
+ - **default_timezone**: Configure timezone that is used for JDBC connection properties and Calcite engine. This option is one of [JDBC connect parameters](https://calcite.apache.org/docs/adapter.html#jdbc-connect-string-parameters) provided by Apache Calcite. java.util.TimeZone's [AvailableIDs](http://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html#getAvailableIDs) can be specified. (string, default: 'UTC')
38
38
 
39
39
  ## Example
40
40
 
@@ -52,6 +52,14 @@ filters:
52
52
  query: SELECT first_name || last_name AS name, * FROM $PAGES
53
53
  ```
54
54
 
55
+ Adds the new column by CURRENT_TIMESTAMP function.
56
+ ```yaml
57
+ filters:
58
+ - type: calcite
59
+ query: SELECT CURRENT_TIMESTAMP, * FROM $PAGES
60
+ default_timezone: 'America/Los_Angeles'
61
+ ```
62
+
55
63
  SQL language provided by Apache Calcite: https://calcite.apache.org/docs/reference.html
56
64
 
57
65
  ## Build
@@ -17,7 +17,7 @@ configurations {
17
17
  provided
18
18
  }
19
19
 
20
- version = "0.1.0"
20
+ version = "0.1.1"
21
21
 
22
22
  sourceCompatibility = 1.7
23
23
  targetCompatibility = 1.7
@@ -84,6 +84,7 @@ public class CalciteFilterPlugin
84
84
  {
85
85
  PluginTask task = config.loadConfig(PluginTask.class);
86
86
  Properties props = System.getProperties(); // TODO should be configured as config option
87
+ setupProperties(task, props);
87
88
 
88
89
  // Set input schema in PageSchema
89
90
  PageSchema.schema = inputSchema;
@@ -107,6 +108,13 @@ public class CalciteFilterPlugin
107
108
  }
108
109
  }
109
110
 
111
+ private void setupProperties(PluginTask task, Properties props)
112
+ {
113
+ // @see https://calcite.apache.org/docs/adapter.html#jdbc-connect-string-parameters
114
+ props.setProperty("caseSensitive", "false"); // Relax case-sensitive
115
+ props.setProperty("timeZone", task.getDefaultTimeZone().getID());
116
+ }
117
+
110
118
  private PageConverter newPageConverter(PluginTask task, Schema inputSchema)
111
119
  {
112
120
  return new PageConverter(inputSchema, task.getDefaultTimeZone().toTimeZone());
@@ -116,9 +124,6 @@ public class CalciteFilterPlugin
116
124
  {
117
125
  String jdbcUrl = buildJdbcUrl();
118
126
  try {
119
- // Relax case-sensitive
120
- // @see https://calcite.apache.org/docs/adapter.html#jdbc-connect-string-parameters
121
- props.setProperty("caseSensitive", "false");
122
127
  return new Driver().connect(jdbcUrl, props);
123
128
  }
124
129
  catch (SQLException e) {
@@ -240,6 +245,7 @@ public class CalciteFilterPlugin
240
245
  ColumnGetterFactory factory = newColumnGetterFactory(task, Optional.of(pageBuilder));
241
246
  List<ColumnGetter> getters = newColumnGetters(factory, task.getQuerySchema());
242
247
  Properties props = System.getProperties(); // TODO should be configured as config option
248
+ setupProperties(task, props);
243
249
  return new FilterPageOutput(outputSchema, task.getQuery(), pageBuilder, pageConverter, getters, props);
244
250
  }
245
251
 
@@ -7,7 +7,6 @@ import org.embulk.input.jdbc.JdbcInputConnection;
7
7
  import org.embulk.input.jdbc.getter.ColumnGetter;
8
8
  import org.embulk.input.jdbc.getter.ColumnGetterFactory;
9
9
  import org.embulk.spi.PageBuilder;
10
- import org.embulk.spi.time.TimestampFormatter;
11
10
  import org.embulk.spi.type.Type;
12
11
  import org.joda.time.DateTimeZone;
13
12
 
@@ -28,18 +27,10 @@ public class FilterColumnGetterFactory
28
27
  String valueType = option.getValueType();
29
28
  Type toType = getToType(option);
30
29
  if (valueType.equals("coalesce") && sqlTypeToValueType(column, column.getSqlType()).equals("timestamp")) {
31
- return new UTCTimestampColumnGetter(to, toType, newTimestampFormatter(option, "%Y-%m-%d"));
30
+ return new FilterTimestampColumnGetter(to, toType, option.getTimeZone().or(defaultTimeZone));
32
31
  }
33
32
  else {
34
33
  return super.newColumnGetter(con, task, column, option);
35
34
  }
36
35
  }
37
-
38
- private TimestampFormatter newTimestampFormatter(JdbcColumnOption option, String defaultTimestampFormat)
39
- {
40
- return new TimestampFormatter(
41
- option.getJRuby(),
42
- option.getTimestampFormat().isPresent() ? option.getTimestampFormat().get().getFormat() : defaultTimestampFormat,
43
- option.getTimeZone().or(defaultTimeZone));
44
- }
45
36
  }
@@ -3,8 +3,8 @@ package org.embulk.filter.calcite.getter;
3
3
  import org.embulk.input.jdbc.getter.TimestampColumnGetter;
4
4
  import org.embulk.spi.PageBuilder;
5
5
  import org.embulk.spi.time.Timestamp;
6
- import org.embulk.spi.time.TimestampFormatter;
7
6
  import org.embulk.spi.type.Type;
7
+ import org.joda.time.DateTimeZone;
8
8
 
9
9
  import java.sql.ResultSet;
10
10
  import java.sql.SQLException;
@@ -13,20 +13,15 @@ import java.util.Calendar;
13
13
  import static java.util.Calendar.getInstance;
14
14
  import static java.util.TimeZone.getTimeZone;
15
15
 
16
- public class UTCTimestampColumnGetter
16
+ public class FilterTimestampColumnGetter
17
17
  extends TimestampColumnGetter
18
18
  {
19
- private static ThreadLocal<Calendar> calendar = new ThreadLocal<Calendar>() {
20
- @Override
21
- protected Calendar initialValue()
22
- {
23
- return getInstance(getTimeZone("UTC"));
24
- }
25
- };
19
+ private static final ThreadLocal<Calendar> calendar = new ThreadLocal<>();
26
20
 
27
- public UTCTimestampColumnGetter(PageBuilder to, Type toType, TimestampFormatter timestampFormatter)
21
+ public FilterTimestampColumnGetter(PageBuilder to, Type toType, DateTimeZone timeZone)
28
22
  {
29
- super(to, toType, timestampFormatter);
23
+ super(to, toType, null);
24
+ calendar.set(getInstance(getTimeZone(timeZone.getID()))); // set TLS here
30
25
  }
31
26
 
32
27
  @Override
@@ -1,2 +1,3 @@
1
1
  type: calcite
2
- query: 'SELECT id, id + 2, (id + 1) * id FROM $PAGES'
2
+ query: 'SELECT id, id + 2, (id + 1) * id FROM $PAGES'
3
+ default_timezone: 'UTC'
@@ -1,2 +1,3 @@
1
1
  type: calcite
2
- query: 'SELECT * FROM $PAGES'
2
+ query: 'SELECT * FROM $PAGES'
3
+ default_timezone: 'UTC'
@@ -1,2 +1,3 @@
1
1
  type: calcite
2
- query: 'SELECT purchase, purchase || purchase, CHAR_LENGTH(purchase), SUBSTRING(purchase FROM 2), SUBSTRING(purchase FROM 2 FOR 4) FROM $PAGES'
2
+ query: 'SELECT purchase, purchase || purchase, CHAR_LENGTH(purchase), SUBSTRING(purchase FROM 2), SUBSTRING(purchase FROM 2 FOR 4) FROM $PAGES'
3
+ default_timezone: 'UTC'
@@ -1,2 +1,3 @@
1
1
  type: calcite
2
- query: 'SELECT * FROM $PAGES WHERE MOD(id, 2) = 0'
2
+ query: 'SELECT * FROM $PAGES WHERE MOD(id, 2) = 0'
3
+ default_timezone: 'UTC'
@@ -1,2 +1,3 @@
1
1
  type: calcite
2
2
  query: SELECT * FROM $PAGES WHERE purchase LIKE '%0127'
3
+ default_timezone: 'UTC'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-filter-calcite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Muga Nishizawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-17 00:00:00.000000000 Z
11
+ date: 2017-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -65,7 +65,7 @@ files:
65
65
  - src/main/java/org/embulk/filter/calcite/adapter/page/PageSchemaFactory.java
66
66
  - src/main/java/org/embulk/filter/calcite/adapter/page/PageTable.java
67
67
  - src/main/java/org/embulk/filter/calcite/getter/FilterColumnGetterFactory.java
68
- - src/main/java/org/embulk/filter/calcite/getter/UTCTimestampColumnGetter.java
68
+ - src/main/java/org/embulk/filter/calcite/getter/FilterTimestampColumnGetter.java
69
69
  - src/test/java/org/embulk/filter/calcite/TestCalciteFilterPlugin.java
70
70
  - src/test/resources/org/embulk/filter/calcite/test/test_int_ops_expected.csv
71
71
  - src/test/resources/org/embulk/filter/calcite/test/test_int_ops_filter.yml
@@ -99,7 +99,7 @@ files:
99
99
  - classpath/commons-lang3-3.2.jar
100
100
  - classpath/commons-logging-1.2.jar
101
101
  - classpath/commons-pool-1.5.4.jar
102
- - classpath/embulk-filter-calcite-0.1.0.jar
102
+ - classpath/embulk-filter-calcite-0.1.1.jar
103
103
  - classpath/embulk-input-jdbc-0.8.2.jar
104
104
  - classpath/httpclient-4.5.2.jar
105
105
  - classpath/httpcore-4.4.4.jar