embulk 0.4.6 → 0.4.7
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 +4 -4
- data/README.md +2 -2
- data/build.gradle +1 -1
- data/embulk-core/src/main/java/org/embulk/command/PreviewPrinter.java +84 -0
- data/embulk-core/src/main/java/org/embulk/command/Runner.java +21 -34
- data/embulk-core/src/main/java/org/embulk/command/TablePreviewPrinter.java +108 -0
- data/embulk-core/src/main/java/org/embulk/command/VerticalPreviewPrinter.java +47 -0
- data/embulk-docs/src/release.rst +1 -0
- data/embulk-docs/src/release/release-0.4.7.rst +16 -0
- data/lib/embulk/command/embulk_run.rb +3 -0
- data/lib/embulk/java_plugin.rb +1 -1
- data/lib/embulk/version.rb +1 -1
- metadata +8 -7
- data/embulk-core/src/main/java/org/embulk/command/TablePrinter.java +0 -119
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2f4db59dbfae683eff9877c8794fab684f562224
|
|
4
|
+
data.tar.gz: 7969e968bae40633fb8c3d70a9ed2f80a0ee4a37
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 592576af399e8f184b1b28dfa32c298fb7ff236f9d956a37e5587e073ee64af0280e481a4a568e114b04391e0cea6977b364f4d9ac03f0a1a194a12b3a7cd19e
|
|
7
|
+
data.tar.gz: f2238b2e4c0bb06c1ad33754b86f9944845565c75ea0f36fb801fd2c1e5b1a87255a5ddbad763dc2f72b36724692cd11cd862cb05ee64827655a7ca797df408c
|
data/README.md
CHANGED
|
@@ -25,10 +25,10 @@ The single-file package is the simplest way to try Embulk. You can download the
|
|
|
25
25
|
|
|
26
26
|
### Linux & Mac & BSD
|
|
27
27
|
|
|
28
|
-
Following 4
|
|
28
|
+
Following 4 commands install embulk to your home directory:
|
|
29
29
|
|
|
30
30
|
```
|
|
31
|
-
curl --create-dirs -o ~/.embulk/bin/embulk -L https://bintray.com/artifact/download/embulk/maven/embulk-0.4.
|
|
31
|
+
curl --create-dirs -o ~/.embulk/bin/embulk -L https://bintray.com/artifact/download/embulk/maven/embulk-0.4.7.jar
|
|
32
32
|
chmod +x ~/.embulk/bin/embulk
|
|
33
33
|
echo 'export PATH="$HOME/.embulk/bin:$PATH"' >> ~/.bashrc
|
|
34
34
|
source ~/.bashrc
|
data/build.gradle
CHANGED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
package org.embulk.command;
|
|
2
|
+
|
|
3
|
+
import java.util.List;
|
|
4
|
+
import java.util.Locale;
|
|
5
|
+
import java.io.PrintStream;
|
|
6
|
+
import java.io.Closeable;
|
|
7
|
+
import java.io.IOException;
|
|
8
|
+
import java.text.NumberFormat;
|
|
9
|
+
import org.embulk.config.ModelManager;
|
|
10
|
+
import org.embulk.spi.Schema;
|
|
11
|
+
import org.embulk.spi.time.Timestamp;
|
|
12
|
+
import org.embulk.spi.Page;
|
|
13
|
+
import org.embulk.spi.util.Pages;
|
|
14
|
+
|
|
15
|
+
public abstract class PreviewPrinter
|
|
16
|
+
implements Closeable
|
|
17
|
+
{
|
|
18
|
+
protected final PrintStream out;
|
|
19
|
+
protected final ModelManager modelManager;
|
|
20
|
+
protected final Schema schema;
|
|
21
|
+
private final String[] stringValues;
|
|
22
|
+
|
|
23
|
+
private final NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.ENGLISH);
|
|
24
|
+
|
|
25
|
+
public PreviewPrinter(PrintStream out, ModelManager modelManager, Schema schema)
|
|
26
|
+
{
|
|
27
|
+
this.out = out;
|
|
28
|
+
this.modelManager = modelManager;
|
|
29
|
+
this.schema = schema;
|
|
30
|
+
this.stringValues = new String[schema.getColumnCount()];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public void printAllPages(List<Page> pages) throws IOException
|
|
34
|
+
{
|
|
35
|
+
List<Object[]> records = Pages.toObjects(schema, pages);
|
|
36
|
+
for (Object[] record : records) {
|
|
37
|
+
printRecord(record);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public void printRecord(Object... values) throws IOException
|
|
42
|
+
{
|
|
43
|
+
int min = Math.min(schema.getColumnCount(), values.length);
|
|
44
|
+
for (int i=0; i < min; i++) {
|
|
45
|
+
stringValues[i] = valueToString(values[i]);
|
|
46
|
+
}
|
|
47
|
+
for (int i=min; i < schema.getColumnCount(); i++) {
|
|
48
|
+
stringValues[i] = valueToString(null);
|
|
49
|
+
}
|
|
50
|
+
printRecord(stringValues);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
protected abstract void printRecord(String[] values) throws IOException;
|
|
54
|
+
|
|
55
|
+
protected String valueToString(Object obj)
|
|
56
|
+
{
|
|
57
|
+
if (obj == null) {
|
|
58
|
+
return "";
|
|
59
|
+
} else if (obj instanceof String) {
|
|
60
|
+
return (String) obj;
|
|
61
|
+
} else if (obj instanceof Number) {
|
|
62
|
+
if (obj instanceof Integer) {
|
|
63
|
+
return numberFormat.format(((Integer) obj).longValue());
|
|
64
|
+
}
|
|
65
|
+
if (obj instanceof Long) {
|
|
66
|
+
return numberFormat.format(((Long) obj).longValue());
|
|
67
|
+
}
|
|
68
|
+
return obj.toString();
|
|
69
|
+
} else if (obj instanceof Timestamp) {
|
|
70
|
+
return obj.toString();
|
|
71
|
+
} else {
|
|
72
|
+
return modelManager.writeObject(obj);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public void finish() throws IOException
|
|
77
|
+
{ }
|
|
78
|
+
|
|
79
|
+
@Override
|
|
80
|
+
public void close() throws IOException
|
|
81
|
+
{
|
|
82
|
+
out.close();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -3,16 +3,15 @@ package org.embulk.command;
|
|
|
3
3
|
import java.util.List;
|
|
4
4
|
import java.util.Map;
|
|
5
5
|
import java.util.HashMap;
|
|
6
|
-
import java.util.Locale;
|
|
7
6
|
import java.io.File;
|
|
8
7
|
import java.io.IOException;
|
|
9
8
|
import java.io.FileOutputStream;
|
|
10
9
|
import java.io.BufferedWriter;
|
|
11
10
|
import java.io.OutputStreamWriter;
|
|
12
11
|
import java.io.Writer;
|
|
13
|
-
import java.text.NumberFormat;
|
|
14
12
|
import org.yaml.snakeyaml.Yaml;
|
|
15
13
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
14
|
+
import com.google.common.base.Function;
|
|
16
15
|
import com.google.inject.Injector;
|
|
17
16
|
import org.embulk.config.ConfigSource;
|
|
18
17
|
import org.embulk.config.DataSource;
|
|
@@ -29,7 +28,6 @@ import org.embulk.exec.ResumeState;
|
|
|
29
28
|
import org.embulk.exec.PartialExecutionException;
|
|
30
29
|
import org.embulk.spi.time.Timestamp;
|
|
31
30
|
import org.embulk.spi.ExecSession;
|
|
32
|
-
import org.embulk.spi.util.Pages;
|
|
33
31
|
import org.embulk.EmbulkService;
|
|
34
32
|
|
|
35
33
|
public class Runner
|
|
@@ -44,6 +42,9 @@ public class Runner
|
|
|
44
42
|
|
|
45
43
|
private String logLevel;
|
|
46
44
|
public String getLogLevel() { return logLevel; }
|
|
45
|
+
|
|
46
|
+
private String previewOutputFormat;
|
|
47
|
+
public String getPreviewOutputFormat() { return previewOutputFormat; };
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
private final Options options;
|
|
@@ -218,41 +219,27 @@ public class Runner
|
|
|
218
219
|
ExecSession exec = newExecSession(config);
|
|
219
220
|
PreviewExecutor preview = injector.getInstance(PreviewExecutor.class);
|
|
220
221
|
PreviewResult result = preview.preview(exec, config);
|
|
221
|
-
|
|
222
|
-
final ModelManager model = injector.getInstance(ModelManager.class);
|
|
223
|
-
|
|
224
|
-
String[] header = new String[result.getSchema().getColumnCount()];
|
|
225
|
-
for (int i=0; i < header.length; i++) {
|
|
226
|
-
header[i] = result.getSchema().getColumnName(i) + ":" + result.getSchema().getColumnType(i);
|
|
227
|
-
}
|
|
222
|
+
ModelManager modelManager = injector.getInstance(ModelManager.class);
|
|
228
223
|
|
|
229
|
-
|
|
230
|
-
private NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.ENGLISH);
|
|
224
|
+
PreviewPrinter printer;
|
|
231
225
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
} else {
|
|
247
|
-
return model.writeObject(obj);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
};
|
|
226
|
+
String format = options.getPreviewOutputFormat();
|
|
227
|
+
if (format == null) {
|
|
228
|
+
format = "table";
|
|
229
|
+
}
|
|
230
|
+
switch (format) {
|
|
231
|
+
case "table":
|
|
232
|
+
printer = new TablePreviewPrinter(System.out, modelManager, result.getSchema());
|
|
233
|
+
break;
|
|
234
|
+
case "vertical":
|
|
235
|
+
printer = new VerticalPreviewPrinter(System.out, modelManager, result.getSchema());
|
|
236
|
+
break;
|
|
237
|
+
default:
|
|
238
|
+
throw new IllegalArgumentException(String.format("Unknown preview output format '%s'. Supported formats: table, vertical", format));
|
|
239
|
+
}
|
|
251
240
|
|
|
252
241
|
try {
|
|
253
|
-
|
|
254
|
-
printer.add(record);
|
|
255
|
-
}
|
|
242
|
+
printer.printAllPages(result.getPages());
|
|
256
243
|
printer.finish();
|
|
257
244
|
} catch (IOException ex) {
|
|
258
245
|
throw new RuntimeException(ex);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
package org.embulk.command;
|
|
2
|
+
|
|
3
|
+
import java.util.List;
|
|
4
|
+
import java.util.Arrays;
|
|
5
|
+
import java.util.ArrayList;
|
|
6
|
+
import java.io.PrintStream;
|
|
7
|
+
import java.io.IOException;
|
|
8
|
+
import com.google.common.base.Function;
|
|
9
|
+
import org.embulk.config.ModelManager;
|
|
10
|
+
import org.embulk.spi.Schema;
|
|
11
|
+
|
|
12
|
+
public class TablePreviewPrinter
|
|
13
|
+
extends PreviewPrinter
|
|
14
|
+
{
|
|
15
|
+
private static final int MAX_SAMPLE_SIZE = 32000;
|
|
16
|
+
|
|
17
|
+
private List<String[]> samples;
|
|
18
|
+
private int sampleSize;
|
|
19
|
+
private String format = null;
|
|
20
|
+
private String border = null;
|
|
21
|
+
|
|
22
|
+
public TablePreviewPrinter(PrintStream out, ModelManager modelManager, Schema schema)
|
|
23
|
+
{
|
|
24
|
+
super(out, modelManager, schema);
|
|
25
|
+
this.samples = new ArrayList<String[]>();
|
|
26
|
+
String[] header = new String[schema.getColumnCount()];
|
|
27
|
+
for (int i=0; i < header.length; i++) {
|
|
28
|
+
header[i] = schema.getColumnName(i) + ":" + schema.getColumnType(i);
|
|
29
|
+
}
|
|
30
|
+
samples.add(header);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Override
|
|
34
|
+
protected void printRecord(String[] values) throws IOException
|
|
35
|
+
{
|
|
36
|
+
if (samples == null) {
|
|
37
|
+
// header is already written
|
|
38
|
+
out.format(format, Arrays.copyOf(values, values.length, Object[].class));
|
|
39
|
+
} else {
|
|
40
|
+
// estimating size of columns
|
|
41
|
+
samples.add(Arrays.copyOf(values, values.length));
|
|
42
|
+
for (String v : values) {
|
|
43
|
+
sampleSize += v.length();
|
|
44
|
+
}
|
|
45
|
+
if (sampleSize > MAX_SAMPLE_SIZE) {
|
|
46
|
+
// enough number of rows to estimate size of the columns.
|
|
47
|
+
flushSamples();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private void flushSamples()
|
|
53
|
+
{
|
|
54
|
+
StringBuilder borderBuilder = new StringBuilder();
|
|
55
|
+
|
|
56
|
+
StringBuilder sb = new StringBuilder();
|
|
57
|
+
sb.append("| ");
|
|
58
|
+
borderBuilder.append("+-");
|
|
59
|
+
for (int i=0; i < schema.getColumnCount(); i++) {
|
|
60
|
+
if (i != 0) {
|
|
61
|
+
sb.append(" | ");
|
|
62
|
+
borderBuilder.append("-+-");
|
|
63
|
+
}
|
|
64
|
+
int colLen = maxLengthInColumn(i);
|
|
65
|
+
sb.append("%"+colLen+"s");
|
|
66
|
+
for (int b=0; b < colLen; b++) {
|
|
67
|
+
borderBuilder.append("-");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
sb.append(" |");
|
|
71
|
+
borderBuilder.append("-+");
|
|
72
|
+
sb.append("\n");
|
|
73
|
+
|
|
74
|
+
this.format = sb.toString();
|
|
75
|
+
this.border = borderBuilder.toString();
|
|
76
|
+
|
|
77
|
+
out.println(border);
|
|
78
|
+
|
|
79
|
+
for (int i=0; i < samples.size(); i++) {
|
|
80
|
+
String[] values = samples.get(i);
|
|
81
|
+
out.format(format, Arrays.copyOf(values, values.length, Object[].class));
|
|
82
|
+
if (i == 0) {
|
|
83
|
+
// i == 0 is header. write border after the header
|
|
84
|
+
out.println(border);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
this.samples = null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private int maxLengthInColumn(int i)
|
|
92
|
+
{
|
|
93
|
+
int max = 0;
|
|
94
|
+
for (String[] values : samples) {
|
|
95
|
+
max = Math.max(max, values[i].length());
|
|
96
|
+
}
|
|
97
|
+
return max;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@Override
|
|
101
|
+
public void finish() throws IOException
|
|
102
|
+
{
|
|
103
|
+
if (samples != null) {
|
|
104
|
+
flushSamples();
|
|
105
|
+
}
|
|
106
|
+
out.println(border);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
package org.embulk.command;
|
|
2
|
+
|
|
3
|
+
import java.io.PrintStream;
|
|
4
|
+
import java.io.IOException;
|
|
5
|
+
import org.embulk.config.ModelManager;
|
|
6
|
+
import org.embulk.spi.Schema;
|
|
7
|
+
|
|
8
|
+
public class VerticalPreviewPrinter
|
|
9
|
+
extends PreviewPrinter
|
|
10
|
+
{
|
|
11
|
+
private final String format;
|
|
12
|
+
private int count = 0;
|
|
13
|
+
|
|
14
|
+
public VerticalPreviewPrinter(PrintStream out, ModelManager modelManager, Schema schema)
|
|
15
|
+
{
|
|
16
|
+
super(out, modelManager, schema);
|
|
17
|
+
this.format = "%" + maxColumnNameLength(schema) + "s (%" + maxColumnTypeNameLength(schema)+ "s) : %s\n";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private static int maxColumnNameLength(Schema schema)
|
|
21
|
+
{
|
|
22
|
+
int max = 0;
|
|
23
|
+
for (int i=0; i < schema.getColumnCount(); i++) {
|
|
24
|
+
max = Math.max(max, schema.getColumnName(i).length());
|
|
25
|
+
}
|
|
26
|
+
return max;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private static int maxColumnTypeNameLength(Schema schema)
|
|
30
|
+
{
|
|
31
|
+
int max = 0;
|
|
32
|
+
for (int i=0; i < schema.getColumnCount(); i++) {
|
|
33
|
+
max = Math.max(max, schema.getColumnType(i).toString().length());
|
|
34
|
+
}
|
|
35
|
+
return max;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Override
|
|
39
|
+
protected void printRecord(String[] values) throws IOException
|
|
40
|
+
{
|
|
41
|
+
count++;
|
|
42
|
+
out.format("*************************** %d ***************************\n", count);
|
|
43
|
+
for (int i=0; i < schema.getColumnCount(); i++) {
|
|
44
|
+
out.format(format, schema.getColumnName(i), schema.getColumnType(i), values[i]);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
data/embulk-docs/src/release.rst
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Release 0.4.7
|
|
2
|
+
==================================
|
|
3
|
+
|
|
4
|
+
CLI
|
|
5
|
+
------------------
|
|
6
|
+
|
|
7
|
+
* Added ``-G, --vertical`` option to ``preview`` subcommand. It shows records in vertical style like MySQL's ``\G`` or PostgreSQL's ``\x`` (@yaggytter++).
|
|
8
|
+
|
|
9
|
+
General Changes
|
|
10
|
+
------------------
|
|
11
|
+
|
|
12
|
+
* Fixed a problem on Windows where classloader raises (@hito4_t++)
|
|
13
|
+
|
|
14
|
+
Release Date
|
|
15
|
+
------------------
|
|
16
|
+
2015-02-23
|
|
@@ -102,6 +102,9 @@ module Embulk
|
|
|
102
102
|
op.on('-C', '--classpath PATH', "Add java classpath separated by #{classpath_separator} (CLASSPATH)") do |classpath|
|
|
103
103
|
classpaths.concat classpath.split(classpath_separator)
|
|
104
104
|
end
|
|
105
|
+
op.on('-G', '--vertical', "Use vertical output format", TrueClass) do |b|
|
|
106
|
+
options[:previewOutputFormat] = "vertical"
|
|
107
|
+
end
|
|
105
108
|
args = 1..1
|
|
106
109
|
|
|
107
110
|
when :guess
|
data/lib/embulk/java_plugin.rb
CHANGED
|
@@ -5,7 +5,7 @@ module Embulk
|
|
|
5
5
|
class JavaPlugin
|
|
6
6
|
def self.classloader(dir)
|
|
7
7
|
jars = Dir["#{dir}/**/*.jar"]
|
|
8
|
-
urls = jars.map {|jar| java.
|
|
8
|
+
urls = jars.map {|jar| java.io.File.new(File.expand_path(jar)).toURI.toURL }
|
|
9
9
|
classloader = Java::PluginClassLoader.new(JRuby.runtime, urls)
|
|
10
10
|
end
|
|
11
11
|
|
data/lib/embulk/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: embulk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sadayuki Furuhashi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-02-
|
|
11
|
+
date: 2015-02-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -102,8 +102,10 @@ files:
|
|
|
102
102
|
- embulk-cli/src/main/sh/selfrun.sh
|
|
103
103
|
- embulk-core/build.gradle
|
|
104
104
|
- embulk-core/src/main/java/org/embulk/EmbulkService.java
|
|
105
|
+
- embulk-core/src/main/java/org/embulk/command/PreviewPrinter.java
|
|
105
106
|
- embulk-core/src/main/java/org/embulk/command/Runner.java
|
|
106
|
-
- embulk-core/src/main/java/org/embulk/command/
|
|
107
|
+
- embulk-core/src/main/java/org/embulk/command/TablePreviewPrinter.java
|
|
108
|
+
- embulk-core/src/main/java/org/embulk/command/VerticalPreviewPrinter.java
|
|
107
109
|
- embulk-core/src/main/java/org/embulk/config/CommitReport.java
|
|
108
110
|
- embulk-core/src/main/java/org/embulk/config/Config.java
|
|
109
111
|
- embulk-core/src/main/java/org/embulk/config/ConfigDefault.java
|
|
@@ -260,6 +262,7 @@ files:
|
|
|
260
262
|
- embulk-docs/src/release/release-0.4.4.rst
|
|
261
263
|
- embulk-docs/src/release/release-0.4.5.rst
|
|
262
264
|
- embulk-docs/src/release/release-0.4.6.rst
|
|
265
|
+
- embulk-docs/src/release/release-0.4.7.rst
|
|
263
266
|
- embulk-standards/build.gradle
|
|
264
267
|
- embulk-standards/src/main/java/org/embulk/standards/CsvFormatterPlugin.java
|
|
265
268
|
- embulk-standards/src/main/java/org/embulk/standards/CsvParserPlugin.java
|
|
@@ -360,10 +363,8 @@ files:
|
|
|
360
363
|
- classpath/bval-jsr303-0.5.jar
|
|
361
364
|
- classpath/commons-beanutils-core-1.8.3.jar
|
|
362
365
|
- classpath/commons-lang3-3.1.jar
|
|
363
|
-
- classpath/embulk-core-0.4.
|
|
364
|
-
- classpath/embulk-
|
|
365
|
-
- classpath/embulk-standards-0.4.5.jar
|
|
366
|
-
- classpath/embulk-standards-0.4.6.jar
|
|
366
|
+
- classpath/embulk-core-0.4.7.jar
|
|
367
|
+
- classpath/embulk-standards-0.4.7.jar
|
|
367
368
|
- classpath/guava-18.0.jar
|
|
368
369
|
- classpath/guice-3.0.jar
|
|
369
370
|
- classpath/guice-multibindings-3.0.jar
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
package org.embulk.command;
|
|
2
|
-
|
|
3
|
-
import java.util.List;
|
|
4
|
-
import java.util.ArrayList;
|
|
5
|
-
import java.util.Locale;
|
|
6
|
-
import java.io.PrintStream;
|
|
7
|
-
import java.io.Flushable;
|
|
8
|
-
import java.io.IOException;
|
|
9
|
-
|
|
10
|
-
class TablePrinter
|
|
11
|
-
{
|
|
12
|
-
private static final int SAMPLES = 10;
|
|
13
|
-
|
|
14
|
-
private PrintStream out;
|
|
15
|
-
|
|
16
|
-
private String[] header;
|
|
17
|
-
|
|
18
|
-
private List<Object[]> samples;
|
|
19
|
-
private String format;
|
|
20
|
-
private String border;
|
|
21
|
-
|
|
22
|
-
public TablePrinter(PrintStream out, String... header)
|
|
23
|
-
{
|
|
24
|
-
this.out = out;
|
|
25
|
-
this.header = header;
|
|
26
|
-
this.samples = new ArrayList<Object[]>(SAMPLES);
|
|
27
|
-
samples.add(header);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public void add(Object... values) throws IOException
|
|
31
|
-
{
|
|
32
|
-
int min = header.length < values.length ? header.length : values.length;
|
|
33
|
-
Object[] cols = new Object[header.length];
|
|
34
|
-
for(int i=0; i < min; i++) {
|
|
35
|
-
if(values[i] == null) {
|
|
36
|
-
cols[i] = "";
|
|
37
|
-
} else {
|
|
38
|
-
cols[i] = valueToString(values[i]);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
for(int i=min; i < header.length; i++) {
|
|
42
|
-
cols[i] = "";
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if(samples == null) {
|
|
46
|
-
out.format(format, cols);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
samples.add(cols);
|
|
51
|
-
if(samples.size() < SAMPLES) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
protected String valueToString(Object obj)
|
|
57
|
-
{
|
|
58
|
-
return obj.toString();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private void flushSamples()
|
|
62
|
-
{
|
|
63
|
-
StringBuilder borderBuilder = new StringBuilder();
|
|
64
|
-
|
|
65
|
-
StringBuilder sb = new StringBuilder();
|
|
66
|
-
sb.append("| ");
|
|
67
|
-
borderBuilder.append("+-");
|
|
68
|
-
for(int i=0; i < header.length; i++) {
|
|
69
|
-
if(i != 0) {
|
|
70
|
-
sb.append(" | ");
|
|
71
|
-
borderBuilder.append("-+-");
|
|
72
|
-
}
|
|
73
|
-
int colLen = maxLengthInColumn(i);
|
|
74
|
-
sb.append("%"+colLen+"s");
|
|
75
|
-
for(int b=0; b < colLen; b++) {
|
|
76
|
-
borderBuilder.append("-");
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
sb.append(" |");
|
|
80
|
-
borderBuilder.append("-+");
|
|
81
|
-
sb.append("\n");
|
|
82
|
-
|
|
83
|
-
this.format = sb.toString();
|
|
84
|
-
this.border = borderBuilder.toString();
|
|
85
|
-
|
|
86
|
-
out.println(border);
|
|
87
|
-
|
|
88
|
-
for(int i=0; i < samples.size(); i++) {
|
|
89
|
-
out.format(format, samples.get(i));
|
|
90
|
-
if(i == 0) {
|
|
91
|
-
out.println(border);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
this.samples = null;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
private int maxLengthInColumn(int i)
|
|
99
|
-
{
|
|
100
|
-
int max = 0;
|
|
101
|
-
for(Object[] cols : samples) {
|
|
102
|
-
String s = (String) cols[i];
|
|
103
|
-
int len = (s == null) ? 0 : s.length();
|
|
104
|
-
if(max < len) {
|
|
105
|
-
max = len;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return max;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public void finish() throws IOException
|
|
112
|
-
{
|
|
113
|
-
if(!samples.isEmpty()) {
|
|
114
|
-
flushSamples();
|
|
115
|
-
}
|
|
116
|
-
out.println(border);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|