embulk-filter-add_time 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +3 -0
- data/COPYING +14 -0
- data/README.md +212 -0
- data/build.gradle +82 -0
- data/gradle/check.gradle +34 -0
- data/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/gradlew +164 -0
- data/gradlew.bat +90 -0
- data/lib/embulk/filter/add_time.rb +3 -0
- data/src/main/java/org/embulk/filter/add_time/AddTimeFilterPlugin.java +208 -0
- data/src/main/java/org/embulk/filter/add_time/converter/ColumnConverter.java +14 -0
- data/src/main/java/org/embulk/filter/add_time/converter/ColumnDuplicator.java +72 -0
- data/src/main/java/org/embulk/filter/add_time/converter/LongValueCastConverter.java +33 -0
- data/src/main/java/org/embulk/filter/add_time/converter/SchemaConverter.java +257 -0
- data/src/main/java/org/embulk/filter/add_time/converter/SimpleColumnConverter.java +62 -0
- data/src/main/java/org/embulk/filter/add_time/converter/StringValueCastConverter.java +33 -0
- data/src/main/java/org/embulk/filter/add_time/converter/TimestampValueCastConverter.java +23 -0
- data/src/main/java/org/embulk/filter/add_time/converter/ValueCastConverter.java +108 -0
- data/src/main/java/org/embulk/filter/add_time/converter/ValueConverter.java +22 -0
- data/src/main/java/org/embulk/filter/add_time/converter/ValueNoConverter.java +46 -0
- data/src/main/java/org/embulk/filter/add_time/reader/AbstractColumnReader.java +55 -0
- data/src/main/java/org/embulk/filter/add_time/reader/BooleanColumnReader.java +35 -0
- data/src/main/java/org/embulk/filter/add_time/reader/ColumnReader.java +14 -0
- data/src/main/java/org/embulk/filter/add_time/reader/DoubleColumnReader.java +35 -0
- data/src/main/java/org/embulk/filter/add_time/reader/LongColumnReader.java +35 -0
- data/src/main/java/org/embulk/filter/add_time/reader/StringColumnReader.java +35 -0
- data/src/main/java/org/embulk/filter/add_time/reader/TimeValueGenerator.java +177 -0
- data/src/main/java/org/embulk/filter/add_time/reader/TimestampColumnReader.java +36 -0
- data/src/test/java/org/embulk/filter/add_time/TestAddTimeFilterPlugin.java +416 -0
- data/src/test/java/org/embulk/filter/add_time/converter/TestSchemaConverter.java +338 -0
- metadata +107 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
package org.embulk.filter.add_time.converter;
|
2
|
+
|
3
|
+
import org.embulk.filter.add_time.reader.ColumnReader;
|
4
|
+
import org.embulk.spi.Column;
|
5
|
+
import org.embulk.spi.PageBuilder;
|
6
|
+
import org.embulk.spi.PageReader;
|
7
|
+
import org.embulk.spi.Schema;
|
8
|
+
|
9
|
+
public class SimpleColumnConverter
|
10
|
+
implements ColumnConverter
|
11
|
+
{
|
12
|
+
public static class Builder
|
13
|
+
{
|
14
|
+
private Column column;
|
15
|
+
private ColumnReader reader;
|
16
|
+
|
17
|
+
public Builder()
|
18
|
+
{
|
19
|
+
}
|
20
|
+
|
21
|
+
public Builder setColumn(Column column)
|
22
|
+
{
|
23
|
+
this.column = column;
|
24
|
+
return this;
|
25
|
+
}
|
26
|
+
|
27
|
+
public Builder setColumnReader(ColumnReader reader)
|
28
|
+
{
|
29
|
+
this.reader = reader;
|
30
|
+
return this;
|
31
|
+
}
|
32
|
+
|
33
|
+
public ColumnConverter build()
|
34
|
+
{
|
35
|
+
return new SimpleColumnConverter(column, reader);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
private final Column column;
|
40
|
+
private final ColumnReader columnReader;
|
41
|
+
|
42
|
+
private SimpleColumnConverter(Column column, ColumnReader columnReader)
|
43
|
+
{
|
44
|
+
this.column = column;
|
45
|
+
this.columnReader = columnReader;
|
46
|
+
}
|
47
|
+
|
48
|
+
public void update(PageReader pageReader)
|
49
|
+
{
|
50
|
+
columnReader.readValue(column, pageReader);
|
51
|
+
}
|
52
|
+
|
53
|
+
public void convert(PageBuilder pageBuilder)
|
54
|
+
{
|
55
|
+
columnReader.convertValue(column, pageBuilder);
|
56
|
+
}
|
57
|
+
|
58
|
+
public void addColumn(Schema.Builder schemaBuilder)
|
59
|
+
{
|
60
|
+
schemaBuilder.add(column.getName(), column.getType());
|
61
|
+
}
|
62
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
package org.embulk.filter.add_time.converter;
|
2
|
+
|
3
|
+
import org.embulk.filter.add_time.AddTimeFilterPlugin.FromColumnConfig;
|
4
|
+
import org.embulk.filter.add_time.AddTimeFilterPlugin.ToColumnConfig;
|
5
|
+
import org.embulk.spi.Column;
|
6
|
+
import org.embulk.spi.PageBuilder;
|
7
|
+
import org.embulk.spi.time.Timestamp;
|
8
|
+
import org.embulk.spi.time.TimestampParser;
|
9
|
+
|
10
|
+
public class StringValueCastConverter
|
11
|
+
extends ValueCastConverter
|
12
|
+
{
|
13
|
+
private final TimestampParser fromTimestampParser;
|
14
|
+
|
15
|
+
public StringValueCastConverter(FromColumnConfig fromColumnConfig, ToColumnConfig toColumnConfig)
|
16
|
+
{
|
17
|
+
super(toColumnConfig);
|
18
|
+
this.fromTimestampParser = new TimestampParser(fromColumnConfig, fromColumnConfig);
|
19
|
+
}
|
20
|
+
|
21
|
+
@Override
|
22
|
+
public void convertValue(final Column column, String value, final PageBuilder pageBuilder)
|
23
|
+
{
|
24
|
+
columnVisitor.setValue(stringToTimestamp(value));
|
25
|
+
columnVisitor.setPageBuilder(pageBuilder);
|
26
|
+
column.visit(columnVisitor);
|
27
|
+
}
|
28
|
+
|
29
|
+
private Timestamp stringToTimestamp(String value)
|
30
|
+
{
|
31
|
+
return fromTimestampParser.parse(value);
|
32
|
+
}
|
33
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
package org.embulk.filter.add_time.converter;
|
2
|
+
|
3
|
+
import org.embulk.filter.add_time.AddTimeFilterPlugin.ToColumnConfig;
|
4
|
+
import org.embulk.spi.Column;
|
5
|
+
import org.embulk.spi.PageBuilder;
|
6
|
+
import org.embulk.spi.time.Timestamp;
|
7
|
+
|
8
|
+
public class TimestampValueCastConverter
|
9
|
+
extends ValueCastConverter
|
10
|
+
{
|
11
|
+
public TimestampValueCastConverter(ToColumnConfig toColumnConfig)
|
12
|
+
{
|
13
|
+
super(toColumnConfig);
|
14
|
+
}
|
15
|
+
|
16
|
+
@Override
|
17
|
+
public void convertValue(Column column, final Timestamp value, final PageBuilder pageBuilder)
|
18
|
+
{
|
19
|
+
columnVisitor.setValue(value); // it can use the value directly.
|
20
|
+
columnVisitor.setPageBuilder(pageBuilder);
|
21
|
+
column.visit(columnVisitor);
|
22
|
+
}
|
23
|
+
}
|
@@ -0,0 +1,108 @@
|
|
1
|
+
package org.embulk.filter.add_time.converter;
|
2
|
+
|
3
|
+
import org.embulk.filter.add_time.AddTimeFilterPlugin.ToColumnConfig;
|
4
|
+
import org.embulk.filter.add_time.AddTimeFilterPlugin.UnixTimestampUnit;
|
5
|
+
import org.embulk.spi.Column;
|
6
|
+
import org.embulk.spi.ColumnVisitor;
|
7
|
+
import org.embulk.spi.PageBuilder;
|
8
|
+
import org.embulk.spi.time.Timestamp;
|
9
|
+
|
10
|
+
public abstract class ValueCastConverter
|
11
|
+
implements ValueConverter
|
12
|
+
{
|
13
|
+
protected final TimestampValueCastVisitor columnVisitor;
|
14
|
+
|
15
|
+
public ValueCastConverter(ToColumnConfig toColumnConfig)
|
16
|
+
{
|
17
|
+
this.columnVisitor = new TimestampValueCastVisitor(UnixTimestampUnit.of(toColumnConfig.getUnixTimestampUnit()));
|
18
|
+
}
|
19
|
+
|
20
|
+
@Override
|
21
|
+
public void convertNull(Column column, PageBuilder pageBuilder)
|
22
|
+
{
|
23
|
+
pageBuilder.setNull(column);
|
24
|
+
}
|
25
|
+
|
26
|
+
@Override
|
27
|
+
public void convertValue(Column column, boolean value, PageBuilder pageBuilder)
|
28
|
+
{
|
29
|
+
throw new AssertionError("Never call.");
|
30
|
+
}
|
31
|
+
|
32
|
+
@Override
|
33
|
+
public void convertValue(Column column, long value, PageBuilder pageBuilder)
|
34
|
+
{
|
35
|
+
throw new AssertionError("Should implement in subclass.");
|
36
|
+
}
|
37
|
+
|
38
|
+
@Override
|
39
|
+
public void convertValue(Column column, double value, PageBuilder pageBuilder)
|
40
|
+
{
|
41
|
+
throw new AssertionError("Never call.");
|
42
|
+
}
|
43
|
+
|
44
|
+
@Override
|
45
|
+
public void convertValue(final Column column, String value, final PageBuilder pageBuilder)
|
46
|
+
{
|
47
|
+
throw new AssertionError("Should implement in subclass.");
|
48
|
+
}
|
49
|
+
|
50
|
+
@Override
|
51
|
+
public void convertValue(Column column, final Timestamp value, final PageBuilder pageBuilder)
|
52
|
+
{
|
53
|
+
throw new AssertionError("Never call.");
|
54
|
+
}
|
55
|
+
|
56
|
+
static class TimestampValueCastVisitor
|
57
|
+
implements ColumnVisitor
|
58
|
+
{
|
59
|
+
private final UnixTimestampUnit toUnixTimestampUnit;
|
60
|
+
private PageBuilder currentPageBuilder;
|
61
|
+
private Timestamp currentValue;
|
62
|
+
|
63
|
+
TimestampValueCastVisitor(UnixTimestampUnit toUnixTimestampUnit)
|
64
|
+
{
|
65
|
+
this.toUnixTimestampUnit = toUnixTimestampUnit;
|
66
|
+
}
|
67
|
+
|
68
|
+
void setValue(Timestamp value)
|
69
|
+
{
|
70
|
+
this.currentValue = value;
|
71
|
+
}
|
72
|
+
|
73
|
+
void setPageBuilder(PageBuilder pageBuilder)
|
74
|
+
{
|
75
|
+
this.currentPageBuilder = pageBuilder;
|
76
|
+
}
|
77
|
+
|
78
|
+
@Override
|
79
|
+
public void booleanColumn(Column column)
|
80
|
+
{
|
81
|
+
throw new AssertionError("Never call.");
|
82
|
+
}
|
83
|
+
|
84
|
+
@Override
|
85
|
+
public void longColumn(Column column)
|
86
|
+
{
|
87
|
+
currentPageBuilder.setLong(column, toUnixTimestampUnit.toLong(currentValue));
|
88
|
+
}
|
89
|
+
|
90
|
+
@Override
|
91
|
+
public void doubleColumn(Column column)
|
92
|
+
{
|
93
|
+
throw new AssertionError("Never call.");
|
94
|
+
}
|
95
|
+
|
96
|
+
@Override
|
97
|
+
public void stringColumn(Column column)
|
98
|
+
{
|
99
|
+
throw new AssertionError("Never call.");
|
100
|
+
}
|
101
|
+
|
102
|
+
@Override
|
103
|
+
public void timestampColumn(Column column)
|
104
|
+
{
|
105
|
+
currentPageBuilder.setTimestamp(column, currentValue);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
package org.embulk.filter.add_time.converter;
|
2
|
+
|
3
|
+
import org.embulk.spi.Column;
|
4
|
+
import org.embulk.spi.PageBuilder;
|
5
|
+
import org.embulk.spi.time.Timestamp;
|
6
|
+
|
7
|
+
public interface ValueConverter
|
8
|
+
{
|
9
|
+
ValueConverter NO_CONV = new ValueNoConverter();
|
10
|
+
|
11
|
+
void convertNull(Column column, PageBuilder pageBuilder);
|
12
|
+
|
13
|
+
void convertValue(Column column, boolean value, PageBuilder pageBuilder);
|
14
|
+
|
15
|
+
void convertValue(Column column, long value, PageBuilder pageBuilder);
|
16
|
+
|
17
|
+
void convertValue(Column column, double value, PageBuilder pageBuilder);
|
18
|
+
|
19
|
+
void convertValue(Column column, String value, PageBuilder pageBuilder);
|
20
|
+
|
21
|
+
void convertValue(Column column, Timestamp value, PageBuilder pageBuilder);
|
22
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
package org.embulk.filter.add_time.converter;
|
2
|
+
|
3
|
+
import org.embulk.spi.Column;
|
4
|
+
import org.embulk.spi.PageBuilder;
|
5
|
+
import org.embulk.spi.time.Timestamp;
|
6
|
+
|
7
|
+
public class ValueNoConverter
|
8
|
+
implements ValueConverter
|
9
|
+
{
|
10
|
+
@Override
|
11
|
+
public void convertNull(Column column, PageBuilder pageBuilder)
|
12
|
+
{
|
13
|
+
pageBuilder.setNull(column);
|
14
|
+
}
|
15
|
+
|
16
|
+
@Override
|
17
|
+
public void convertValue(Column column, boolean value, PageBuilder pageBuilder)
|
18
|
+
{
|
19
|
+
pageBuilder.setBoolean(column, value);
|
20
|
+
}
|
21
|
+
|
22
|
+
@Override
|
23
|
+
public void convertValue(Column column, long value, PageBuilder pageBuilder)
|
24
|
+
{
|
25
|
+
pageBuilder.setLong(column, value);
|
26
|
+
}
|
27
|
+
|
28
|
+
@Override
|
29
|
+
public void convertValue(Column column, double value, PageBuilder pageBuilder)
|
30
|
+
{
|
31
|
+
pageBuilder.setDouble(column, value);
|
32
|
+
}
|
33
|
+
|
34
|
+
@Override
|
35
|
+
public void convertValue(Column column, String value, PageBuilder pageBuilder)
|
36
|
+
{
|
37
|
+
pageBuilder.setString(column, value);
|
38
|
+
}
|
39
|
+
|
40
|
+
@Override
|
41
|
+
public void convertValue(Column column, Timestamp value, PageBuilder pageBuilder)
|
42
|
+
{
|
43
|
+
pageBuilder.setTimestamp(column, value);
|
44
|
+
|
45
|
+
}
|
46
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
package org.embulk.filter.add_time.reader;
|
2
|
+
|
3
|
+
import org.embulk.filter.add_time.converter.ValueConverter;
|
4
|
+
import org.embulk.spi.Column;
|
5
|
+
import org.embulk.spi.PageBuilder;
|
6
|
+
import org.embulk.spi.PageReader;
|
7
|
+
|
8
|
+
public abstract class AbstractColumnReader<T extends AbstractColumnReader>
|
9
|
+
implements ColumnReader<T>
|
10
|
+
{
|
11
|
+
protected final ValueConverter valueConverter;
|
12
|
+
protected boolean isNull = false;
|
13
|
+
|
14
|
+
protected AbstractColumnReader(ValueConverter valueConverter)
|
15
|
+
{
|
16
|
+
this.valueConverter = valueConverter;
|
17
|
+
}
|
18
|
+
|
19
|
+
@Override
|
20
|
+
public void readValue(Column column, PageReader pageReader)
|
21
|
+
{
|
22
|
+
if (!(isNull = pageReader.isNull(column))) {
|
23
|
+
readNonNullValue(column, pageReader);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
protected abstract void readNonNullValue(Column column, PageReader pageReader);
|
28
|
+
|
29
|
+
@Override
|
30
|
+
public void convertValue(Column column, PageBuilder pageBuilder)
|
31
|
+
{
|
32
|
+
try {
|
33
|
+
if (isNull) {
|
34
|
+
valueConverter.convertNull(column, pageBuilder);
|
35
|
+
}
|
36
|
+
else {
|
37
|
+
convertNonNullValue(column, pageBuilder);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
finally {
|
41
|
+
isNull = false;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
protected abstract void convertNonNullValue(Column column, PageBuilder pageBuilder);
|
46
|
+
|
47
|
+
@Override
|
48
|
+
public void copyTo(T columnReader)
|
49
|
+
{
|
50
|
+
columnReader.isNull = this.isNull;
|
51
|
+
copyValueTo(columnReader);
|
52
|
+
}
|
53
|
+
|
54
|
+
protected abstract void copyValueTo(T columnReader);
|
55
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
package org.embulk.filter.add_time.reader;
|
2
|
+
|
3
|
+
import org.embulk.filter.add_time.converter.ValueConverter;
|
4
|
+
import org.embulk.spi.Column;
|
5
|
+
import org.embulk.spi.PageBuilder;
|
6
|
+
import org.embulk.spi.PageReader;
|
7
|
+
|
8
|
+
public class BooleanColumnReader
|
9
|
+
extends AbstractColumnReader<BooleanColumnReader>
|
10
|
+
{
|
11
|
+
protected boolean value;
|
12
|
+
|
13
|
+
public BooleanColumnReader(ValueConverter valueConverter)
|
14
|
+
{
|
15
|
+
super(valueConverter);
|
16
|
+
}
|
17
|
+
|
18
|
+
@Override
|
19
|
+
public void readNonNullValue(Column column, PageReader pageReader)
|
20
|
+
{
|
21
|
+
value = pageReader.getBoolean(column);
|
22
|
+
}
|
23
|
+
|
24
|
+
@Override
|
25
|
+
public void convertNonNullValue(Column column, PageBuilder pageBuilder)
|
26
|
+
{
|
27
|
+
valueConverter.convertValue(column, value, pageBuilder);
|
28
|
+
}
|
29
|
+
|
30
|
+
@Override
|
31
|
+
public void copyValueTo(BooleanColumnReader columnReader)
|
32
|
+
{
|
33
|
+
columnReader.value = this.value;
|
34
|
+
}
|
35
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
package org.embulk.filter.add_time.reader;
|
2
|
+
|
3
|
+
import org.embulk.spi.Column;
|
4
|
+
import org.embulk.spi.PageBuilder;
|
5
|
+
import org.embulk.spi.PageReader;
|
6
|
+
|
7
|
+
public interface ColumnReader<T extends ColumnReader>
|
8
|
+
{
|
9
|
+
void readValue(Column column, PageReader pageReader);
|
10
|
+
|
11
|
+
void convertValue(Column column, PageBuilder pageBuilder);
|
12
|
+
|
13
|
+
void copyTo(T columnReader);
|
14
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
package org.embulk.filter.add_time.reader;
|
2
|
+
|
3
|
+
import org.embulk.filter.add_time.converter.ValueConverter;
|
4
|
+
import org.embulk.spi.Column;
|
5
|
+
import org.embulk.spi.PageBuilder;
|
6
|
+
import org.embulk.spi.PageReader;
|
7
|
+
|
8
|
+
public class DoubleColumnReader
|
9
|
+
extends AbstractColumnReader<DoubleColumnReader>
|
10
|
+
{
|
11
|
+
protected double value;
|
12
|
+
|
13
|
+
public DoubleColumnReader(ValueConverter valueConverter)
|
14
|
+
{
|
15
|
+
super(valueConverter);
|
16
|
+
}
|
17
|
+
|
18
|
+
@Override
|
19
|
+
public void readNonNullValue(Column column, PageReader pageReader)
|
20
|
+
{
|
21
|
+
value = pageReader.getDouble(column);
|
22
|
+
}
|
23
|
+
|
24
|
+
@Override
|
25
|
+
public void convertNonNullValue(Column column, PageBuilder pageBuilder)
|
26
|
+
{
|
27
|
+
valueConverter.convertValue(column, value, pageBuilder);
|
28
|
+
}
|
29
|
+
|
30
|
+
@Override
|
31
|
+
public void copyValueTo(DoubleColumnReader columnReader)
|
32
|
+
{
|
33
|
+
columnReader.value = this.value;
|
34
|
+
}
|
35
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
package org.embulk.filter.add_time.reader;
|
2
|
+
|
3
|
+
import org.embulk.filter.add_time.converter.ValueConverter;
|
4
|
+
import org.embulk.spi.Column;
|
5
|
+
import org.embulk.spi.PageBuilder;
|
6
|
+
import org.embulk.spi.PageReader;
|
7
|
+
|
8
|
+
public class LongColumnReader
|
9
|
+
extends AbstractColumnReader<LongColumnReader>
|
10
|
+
{
|
11
|
+
protected long value;
|
12
|
+
|
13
|
+
public LongColumnReader(ValueConverter valueConverter)
|
14
|
+
{
|
15
|
+
super(valueConverter);
|
16
|
+
}
|
17
|
+
|
18
|
+
@Override
|
19
|
+
public void readNonNullValue(Column column, PageReader pageReader)
|
20
|
+
{
|
21
|
+
value = pageReader.getLong(column);
|
22
|
+
}
|
23
|
+
|
24
|
+
@Override
|
25
|
+
public void convertNonNullValue(Column column, PageBuilder pageBuilder)
|
26
|
+
{
|
27
|
+
valueConverter.convertValue(column, value, pageBuilder);
|
28
|
+
}
|
29
|
+
|
30
|
+
@Override
|
31
|
+
public void copyValueTo(LongColumnReader columnReader)
|
32
|
+
{
|
33
|
+
columnReader.value = this.value;
|
34
|
+
}
|
35
|
+
}
|