embulk-filter-hash 0.3.2 → 0.4.0

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: 8417b34528ba29a1f45b5504febb1f3d5d9dcfe2
4
- data.tar.gz: ded22e2054f384eae9d87afdd7ff72260132576c
3
+ metadata.gz: 681859abe9dc6462e1ca8bfc9d32da28b11be9d4
4
+ data.tar.gz: 364021a86b7841541741d68ad0dfa2c4a42e196a
5
5
  SHA512:
6
- metadata.gz: 4ea229bac3414280c489e57363dc632e537ee79e23e53985e34263dd798a5b00293eacf48772ef366419c7d714554d8cfb8130bb0485e322d38064963f9d99a4
7
- data.tar.gz: 0a2f6f872af45d354231ffa71ca0ff3953323e325f0125c628c772dca80e376eaa8bc5d8b959c8ac1e1a488d315d4f344f04a052adcef25e956c86bf51e6db06
6
+ metadata.gz: f0cb9f3e5b8fd629e6ab69940a605ff5c2631494d3b4f63968f602f66225c5596f3016c30bbf108017c83491b1421a28babb21509657efce9fe5696c522a1c09
7
+ data.tar.gz: 3229e2f0fdff0a6bd9617c8a977d2473c64a3d4e11f341d48ef41a8c69a13d6ae25bfe46b09cd1244675527517281dff74e7b03dc6132685e6d167380581188a
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Hash filter plugin for Embulk
4
4
 
5
- Embulk filter plugin to convert a input to hash.
5
+ Embulk filter plugin to convert an input to a hash value.
6
6
 
7
7
  ## Overview
8
8
 
@@ -1,5 +1,5 @@
1
1
  buildscript {
2
- ext.kotlinVersion = '1.1.1'
2
+ ext.kotlinVersion = '1.2.31'
3
3
  repositories {
4
4
  mavenCentral()
5
5
  jcenter()
@@ -22,21 +22,21 @@ repositories {
22
22
  maven { url 'http://kamatama41.github.com/maven-repository/repository' }
23
23
  }
24
24
 
25
- sourceCompatibility = 1.7
26
- targetCompatibility = 1.7
25
+ sourceCompatibility = 1.8
26
+ targetCompatibility = 1.8
27
27
 
28
28
  dependencies {
29
29
  compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
30
- testCompile "com.github.kamatama41:embulk-test-helpers:0.3.2"
30
+ testCompile "com.github.kamatama41:embulk-test-helpers:0.4.0"
31
31
  }
32
32
 
33
33
  embulk {
34
- version = "0.8.18"
34
+ version = "0.9.7"
35
35
  category = "filter"
36
36
  name = "hash"
37
37
  authors = ["Shinichi Ishimura"]
38
38
  email = "shiketaudonko41@gmail.com"
39
- description = "Embulk filter plugin to convert a input to hash."
39
+ description = "Embulk filter plugin to convert an input to a hash value."
40
40
  licenses = ["MIT"]
41
41
  homepage = "https://github.com/kamatama41/embulk-filter-hash"
42
42
  }
@@ -1 +1 @@
1
- version=0.3.2
1
+ version=0.4.0
@@ -66,49 +66,59 @@ class HashFilterPlugin : FilterPlugin {
66
66
  override fun add(page: Page) {
67
67
  reader.setPage(page)
68
68
  while (reader.nextRecord()) {
69
- setValue()
69
+ setRowValue()
70
70
  builder.addRecord()
71
71
  }
72
72
  }
73
73
 
74
- private fun setValue() {
74
+ private fun setRowValue() {
75
75
  for (inputColumn in inputSchema.columns) {
76
76
  if (reader.isNull(inputColumn)) {
77
77
  builder.setNull(inputColumn)
78
78
  continue
79
79
  }
80
80
 
81
- // Write the original data
82
- val inputValue: Any = when (inputColumn.type) {
81
+ when (inputColumn.type) {
83
82
  Types.STRING -> {
84
- reader.getString(inputColumn).apply { builder.setString(inputColumn, this) }
83
+ setColumnValue(inputColumn, reader::getString, builder::setString)
85
84
  }
86
85
  Types.BOOLEAN -> {
87
- reader.getBoolean(inputColumn).apply { builder.setBoolean(inputColumn, this) }
86
+ setColumnValue(inputColumn, reader::getBoolean, builder::setBoolean)
88
87
  }
89
88
  Types.DOUBLE -> {
90
- reader.getDouble(inputColumn).apply { builder.setDouble(inputColumn, this) }
89
+ setColumnValue(inputColumn, reader::getDouble, builder::setDouble)
91
90
  }
92
91
  Types.LONG -> {
93
- reader.getLong(inputColumn).apply { builder.setLong(inputColumn, this) }
92
+ setColumnValue(inputColumn, reader::getLong, builder::setLong)
94
93
  }
95
94
  Types.TIMESTAMP -> {
96
- reader.getTimestamp(inputColumn).apply { builder.setTimestamp(inputColumn, this) }
95
+ setColumnValue(inputColumn, reader::getTimestamp, builder::setTimestamp)
97
96
  }
98
97
  Types.JSON -> {
99
- reader.getJson(inputColumn).apply { builder.setJson(inputColumn, this) }
98
+ setColumnValue(inputColumn, reader::getJson, builder::setJson)
100
99
  }
101
100
  else -> {
102
101
  throw DataException("Unexpected type:" + inputColumn.type)
103
102
  }
104
103
  }
104
+ }
105
+ }
105
106
 
106
- // Overwrite the column if it's hash column.
107
- hashColumnMap[inputColumn.name]?.let { hashColumn ->
108
- val outputColumn = outputColumnMap[hashColumn.newName.or(inputColumn.name)]
109
- val hashedValue = generateHash(inputValue.toString(), hashColumn.algorithm.get())
110
- builder.setString(outputColumn, hashedValue)
111
- }
107
+ private fun <T> setColumnValue(
108
+ inputColumn: Column,
109
+ getter: (inputColumn: Column) -> T,
110
+ setter: (inputColumn: Column, value: T) -> Unit
111
+ ) {
112
+ val inputValue = getter(inputColumn)
113
+
114
+ hashColumnMap[inputColumn.name]?.let { hashColumn ->
115
+ // Write hashed value if it's hash column.
116
+ val outputColumn = outputColumnMap[hashColumn.newName.or(inputColumn.name)]
117
+ val hashedValue = generateHash(inputValue.toString(), hashColumn.algorithm.get())
118
+ builder.setString(outputColumn, hashedValue)
119
+ } ?: run {
120
+ // Write the original data
121
+ setter(inputColumn, inputValue)
112
122
  }
113
123
  }
114
124
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-filter-hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shinichi Ishimura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-19 00:00:00.000000000 Z
11
+ date: 2018-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
- description: Embulk filter plugin to convert a input to hash.
41
+ description: Embulk filter plugin to convert an input to a hash value.
42
42
  email:
43
43
  - shiketaudonko41@gmail.com
44
44
  executables: []
@@ -62,9 +62,9 @@ files:
62
62
  - src/test/resources/yaml/input_basic.yml
63
63
  - src/test/resources/yaml/input_column_types.yml
64
64
  - src/test/resources/yaml/input_null_column.yml
65
- - classpath/kotlin-stdlib-1.1.1.jar
65
+ - classpath/kotlin-stdlib-1.2.31.jar
66
66
  - classpath/annotations-13.0.jar
67
- - classpath/embulk-filter-hash-0.3.2.jar
67
+ - classpath/embulk-filter-hash-0.4.0.jar
68
68
  homepage: https://github.com/kamatama41/embulk-filter-hash
69
69
  licenses:
70
70
  - MIT