embulk-output-td 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/build.gradle +9 -8
  4. data/embulk-output-td.gemspec +1 -1
  5. data/src/main/java/org/embulk/output/td/MsgpackGZFileBuilder.java +11 -12
  6. data/src/main/java/org/embulk/output/td/RecordWriter.java +4 -7
  7. data/src/main/java/org/embulk/output/td/TdOutputPlugin.java +89 -84
  8. data/src/main/java/org/embulk/output/td/writer/FieldWriterSet.java +9 -0
  9. data/src/main/java/org/embulk/output/td/writer/JsonFieldWriter.java +23 -0
  10. data/src/test/java/org/embulk/output/td/TestRecordWriter.java +37 -38
  11. data/src/test/java/org/embulk/output/td/TestTdOutputPlugin.java +53 -49
  12. metadata +9 -30
  13. data/src/main/java/com/treasuredata/api/TdApiClient.java +0 -506
  14. data/src/main/java/com/treasuredata/api/TdApiClientConfig.java +0 -79
  15. data/src/main/java/com/treasuredata/api/TdApiConflictException.java +0 -10
  16. data/src/main/java/com/treasuredata/api/TdApiConstants.java +0 -10
  17. data/src/main/java/com/treasuredata/api/TdApiException.java +0 -20
  18. data/src/main/java/com/treasuredata/api/TdApiExecutionException.java +0 -10
  19. data/src/main/java/com/treasuredata/api/TdApiExecutionInterruptedException.java +0 -16
  20. data/src/main/java/com/treasuredata/api/TdApiExecutionTimeoutException.java +0 -18
  21. data/src/main/java/com/treasuredata/api/TdApiNotFoundException.java +0 -10
  22. data/src/main/java/com/treasuredata/api/TdApiResponseException.java +0 -32
  23. data/src/main/java/com/treasuredata/api/model/TDArrayColumnType.java +0 -80
  24. data/src/main/java/com/treasuredata/api/model/TDBulkImportSession.java +0 -157
  25. data/src/main/java/com/treasuredata/api/model/TDColumn.java +0 -129
  26. data/src/main/java/com/treasuredata/api/model/TDColumnType.java +0 -23
  27. data/src/main/java/com/treasuredata/api/model/TDColumnTypeDeserializer.java +0 -128
  28. data/src/main/java/com/treasuredata/api/model/TDDatabase.java +0 -49
  29. data/src/main/java/com/treasuredata/api/model/TDDatabaseList.java +0 -24
  30. data/src/main/java/com/treasuredata/api/model/TDMapColumnType.java +0 -88
  31. data/src/main/java/com/treasuredata/api/model/TDPrimitiveColumnType.java +0 -61
  32. data/src/main/java/com/treasuredata/api/model/TDTable.java +0 -64
  33. data/src/main/java/com/treasuredata/api/model/TDTableList.java +0 -33
  34. data/src/main/java/com/treasuredata/api/model/TDTablePermission.java +0 -50
  35. data/src/main/java/com/treasuredata/api/model/TDTableSchema.java +0 -44
  36. data/src/main/java/com/treasuredata/api/model/TDTableType.java +0 -37
  37. data/src/test/java/com/treasuredata/api/TestTdApiClient.java +0 -79
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e783c1c2be4214064efd3f5ad141710fc886bb9f
4
- data.tar.gz: f341aed71e1d97e92f9deec129291c44223a380c
3
+ metadata.gz: 1f6572b7067dbe90e8b8687e796cace68c784653
4
+ data.tar.gz: df2090ebd8861f183447b4800f4847f1c4a847e5
5
5
  SHA512:
6
- metadata.gz: 8f4ddb9be5f86ad7dc067d646d67cc96018c362d77f0409d8a3df8f8092efcbf66c928fb91ec4391f4d3852ed87e992246161170c10c3bb7f2f9bdba479617e4
7
- data.tar.gz: bd6d393b4cf7c980d423daba0d79e8b4d0e487dec9e30c942be975f08899cb4c90ea49e6928c444dec966f591ef9ee6ea67d1c15c2e714616f0106d22ed7e594
6
+ metadata.gz: f95ec8ff2e4a4bc6ea2ede82b92c0bd325421c848ddaa05ec1cd73c6f31a6e16357835bfb5a046202ad917c6a9ba047d44bc8a80b6cc9227c6d249c844b49e51
7
+ data.tar.gz: 4b97abbd2486cb0556c18257f6c5b9d922452798a80d68d9097bab9f9bdc03ce463c492a13109925c021ec6572a22d391f1cf876c4ee4f61a6ecaa5e7c1c70fc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.3.0 - 2016-03-03
2
+
3
+ * [maintenance] Upgrade embulk v08 [#37](https://github.com/treasure-data/embulk-output-td/pull/37)
4
+
1
5
  ## 0.2.2 - 2016-02-29
2
6
 
3
7
  * [maintenance] Update a table schema by Embulk's guessed columns if the # of the uploaded record is zero [#36](https://github.com/treasure-data/embulk-output-td/pull/36)
data/build.gradle CHANGED
@@ -16,23 +16,24 @@ configurations {
16
16
  provided
17
17
  }
18
18
 
19
- version = "0.2.2"
19
+ version = "0.3.0"
20
20
 
21
21
  compileJava.options.encoding = 'UTF-8' // source encoding
22
22
  sourceCompatibility = 1.7
23
23
  targetCompatibility = 1.7
24
24
 
25
25
  dependencies {
26
- compile "org.embulk:embulk-core:0.7.10"
27
- provided "org.embulk:embulk-core:0.7.10"
28
- compile "org.embulk:embulk-standards:0.7.10"
29
- provided "org.embulk:embulk-standards:0.7.10"
30
- compile "org.eclipse.jetty:jetty-client:9.2.2.v20140723"
31
- compile "org.msgpack:msgpack:0.6.11"
26
+ compile "org.embulk:embulk-core:0.8.+"
27
+ provided "org.embulk:embulk-core:0.8.+"
28
+ compile "org.embulk:embulk-standards:0.8.+"
29
+ provided "org.embulk:embulk-standards:0.8.+"
30
+ compile "org.msgpack:msgpack-core:0.8.+"
31
+ provided "org.msgpack:msgpack-core:0.8.+"
32
+ compile "com.treasuredata.client:td-client:0.7.8"
32
33
 
33
34
  testCompile "junit:junit:4.+"
34
35
  testCompile "org.bigtesting:fixd:1.0.0"
35
- testCompile "org.embulk:embulk-core:0.7.10:tests"
36
+ testCompile "org.embulk:embulk-core:0.8.+:tests"
36
37
  testCompile "org.mockito:mockito-core:1.9.5"
37
38
  }
38
39
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "embulk-output-td"
4
- spec.version = "0.2.2"
4
+ spec.version = "0.3.0"
5
5
  spec.authors = ["Muga Nishizawa"]
6
6
  spec.summary = %[TreasureData output plugin for Embulk]
7
7
  spec.description = %[TreasureData output plugin is an Embulk plugin that loads records to TreasureData read by any input plugins. Search the input plugins by 'embulk-output' keyword.]
@@ -1,7 +1,7 @@
1
1
  package org.embulk.output.td;
2
2
 
3
- import org.msgpack.MessagePack;
4
- import org.msgpack.packer.Packer;
3
+ import org.msgpack.core.MessagePack;
4
+ import org.msgpack.core.MessagePacker;
5
5
 
6
6
  import java.io.BufferedOutputStream;
7
7
  import java.io.Closeable;
@@ -60,16 +60,16 @@ public class MsgpackGZFileBuilder
60
60
  private final DataSizeFilter out;
61
61
  private final GZIPOutputStream gzout;
62
62
 
63
- private Packer packer;
63
+ private MessagePacker packer;
64
64
  private long recordCount;
65
65
 
66
- public MsgpackGZFileBuilder(MessagePack msgpack, File file)
66
+ public MsgpackGZFileBuilder(File file)
67
67
  throws IOException
68
68
  {
69
69
  this.file = checkNotNull(file);
70
70
  this.out = new DataSizeFilter(new BufferedOutputStream(new FileOutputStream(file)));
71
71
  this.gzout = new GZIPOutputStream(this.out);
72
- this.packer = msgpack.createPacker(this.gzout);
72
+ this.packer = MessagePack.newDefaultPacker(this.gzout);
73
73
 
74
74
  this.recordCount = 0;
75
75
  }
@@ -118,43 +118,42 @@ public class MsgpackGZFileBuilder
118
118
  public void writeNil()
119
119
  throws IOException
120
120
  {
121
- packer.writeNil();
121
+ packer.packNil();
122
122
  }
123
123
 
124
124
  public void writeMapBegin(int size)
125
125
  throws IOException
126
126
  {
127
- packer.writeMapBegin(size);
127
+ packer.packMapHeader(size);
128
128
  }
129
129
 
130
130
  public void writeMapEnd()
131
131
  throws IOException
132
132
  {
133
- packer.writeMapEnd();
134
133
  recordCount++;
135
134
  }
136
135
 
137
136
  public void writeString(String v)
138
137
  throws IOException
139
138
  {
140
- packer.write(v);
139
+ packer.packString(v);
141
140
  }
142
141
 
143
142
  public void writeBoolean(boolean v)
144
143
  throws IOException
145
144
  {
146
- packer.write(v);
145
+ packer.packBoolean(v);
147
146
  }
148
147
 
149
148
  public void writeLong(long v)
150
149
  throws IOException
151
150
  {
152
- packer.write(v);
151
+ packer.packLong(v);
153
152
  }
154
153
 
155
154
  public void writeDouble(double v)
156
155
  throws IOException
157
156
  {
158
- packer.write(v);
157
+ packer.packDouble(v);
159
158
  }
160
159
  }
@@ -3,7 +3,7 @@ package org.embulk.output.td;
3
3
  import com.google.common.annotations.VisibleForTesting;
4
4
  import com.google.common.base.Stopwatch;
5
5
  import com.google.common.base.Throwables;
6
- import com.treasuredata.api.TdApiClient;
6
+ import com.treasuredata.client.TDClient;
7
7
  import org.embulk.config.TaskReport;
8
8
  import org.embulk.output.td.writer.FieldWriterSet;
9
9
  import org.embulk.spi.Exec;
@@ -11,7 +11,6 @@ import org.embulk.spi.Page;
11
11
  import org.embulk.spi.PageReader;
12
12
  import org.embulk.spi.Schema;
13
13
  import org.embulk.spi.TransactionalPageOutput;
14
- import org.msgpack.MessagePack;
15
14
  import org.slf4j.Logger;
16
15
 
17
16
  import java.io.File;
@@ -28,11 +27,10 @@ public class RecordWriter
28
27
  implements TransactionalPageOutput
29
28
  {
30
29
  private final Logger log;
31
- private final TdApiClient client;
30
+ private final TDClient client;
32
31
  private final String sessionName;
33
32
  private final int taskIndex;
34
33
 
35
- private final MessagePack msgpack;
36
34
  private final FieldWriterSet fieldWriters;
37
35
  private final File tempDir;
38
36
 
@@ -44,14 +42,13 @@ public class RecordWriter
44
42
  private final int uploadConcurrency;
45
43
  private final long fileSplitSize; // unit: kb
46
44
 
47
- public RecordWriter(TdOutputPlugin.PluginTask task, int taskIndex, TdApiClient client, FieldWriterSet fieldWriters)
45
+ public RecordWriter(TdOutputPlugin.PluginTask task, int taskIndex, TDClient client, FieldWriterSet fieldWriters)
48
46
  {
49
47
  this.log = Exec.getLogger(getClass());
50
48
  this.client = checkNotNull(client);
51
49
  this.sessionName = task.getSessionName();
52
50
  this.taskIndex = taskIndex;
53
51
 
54
- this.msgpack = new MessagePack();
55
52
  this.fieldWriters = fieldWriters;
56
53
  this.tempDir = new File(task.getTempDir());
57
54
  this.executor = new FinalizableExecutorService();
@@ -77,7 +74,7 @@ public class RecordWriter
77
74
  {
78
75
  String prefix = String.format("%s-", sessionName);
79
76
  File tempFile = File.createTempFile(prefix, ".msgpack.gz", tempDir);
80
- this.builder = new MsgpackGZFileBuilder(msgpack, tempFile);
77
+ this.builder = new MsgpackGZFileBuilder(tempFile);
81
78
  }
82
79
 
83
80
  @VisibleForTesting
@@ -14,23 +14,23 @@ import javax.validation.constraints.Min;
14
14
  import javax.validation.constraints.Max;
15
15
 
16
16
  import com.google.common.annotations.VisibleForTesting;
17
+ import com.google.common.base.Function;
17
18
  import com.google.common.base.Optional;
18
19
  import com.google.common.base.Throwables;
19
20
  import com.fasterxml.jackson.annotation.JsonCreator;
20
21
  import com.fasterxml.jackson.annotation.JsonValue;
21
22
  import com.google.common.collect.ImmutableMap;
22
23
  import com.google.common.collect.Lists;
23
- import com.treasuredata.api.TdApiClient;
24
- import com.treasuredata.api.TdApiClientConfig;
25
- import com.treasuredata.api.TdApiClientConfig.HttpProxyConfig;
26
- import com.treasuredata.api.TdApiConflictException;
27
- import com.treasuredata.api.TdApiNotFoundException;
28
- import com.treasuredata.api.model.TDBulkImportSession;
29
- import com.treasuredata.api.model.TDBulkImportSession.ImportStatus;
30
- import com.treasuredata.api.model.TDTable;
31
- import com.treasuredata.api.model.TDColumn;
32
- import com.treasuredata.api.model.TDColumnType;
33
- import com.treasuredata.api.model.TDPrimitiveColumnType;
24
+ import com.treasuredata.client.ProxyConfig;
25
+ import com.treasuredata.client.TDClient;
26
+ import com.treasuredata.client.TDClientBuilder;
27
+ import com.treasuredata.client.TDClientHttpConflictException;
28
+ import com.treasuredata.client.TDClientHttpNotFoundException;
29
+ import com.treasuredata.client.model.TDBulkImportSession;
30
+ import com.treasuredata.client.model.TDBulkImportSession.ImportStatus;
31
+ import com.treasuredata.client.model.TDColumn;
32
+ import com.treasuredata.client.model.TDColumnType;
33
+ import com.treasuredata.client.model.TDTable;
34
34
  import org.embulk.config.TaskReport;
35
35
  import org.embulk.config.Config;
36
36
  import org.embulk.config.ConfigDefault;
@@ -51,9 +51,9 @@ import org.embulk.spi.TransactionalPageOutput;
51
51
  import org.embulk.spi.time.Timestamp;
52
52
  import org.embulk.spi.time.TimestampFormatter;
53
53
  import org.joda.time.format.DateTimeFormat;
54
- import org.msgpack.MessagePack;
55
- import org.msgpack.unpacker.Unpacker;
56
- import org.msgpack.unpacker.UnpackerIterator;
54
+ import org.msgpack.core.MessagePack;
55
+ import org.msgpack.core.MessageUnpacker;
56
+ import org.msgpack.value.Value;
57
57
  import org.slf4j.Logger;
58
58
 
59
59
  public class TdOutputPlugin
@@ -324,7 +324,7 @@ public class TdOutputPlugin
324
324
  // generate session name
325
325
  task.setSessionName(buildBulkImportSessionName(task, Exec.session()));
326
326
 
327
- try (TdApiClient client = newTdApiClient(task)) {
327
+ try (TDClient client = newTDClient(task)) {
328
328
  String databaseName = task.getDatabase();
329
329
  String tableName = task.getTable();
330
330
 
@@ -361,13 +361,13 @@ public class TdOutputPlugin
361
361
  OutputPlugin.Control control)
362
362
  {
363
363
  PluginTask task = taskSource.loadTask(PluginTask.class);
364
- try (TdApiClient client = newTdApiClient(task)) {
364
+ try (TDClient client = newTDClient(task)) {
365
365
  return doRun(client, schema, task, control);
366
366
  }
367
367
  }
368
368
 
369
369
  @VisibleForTesting
370
- ConfigDiff doRun(TdApiClient client, Schema schema, PluginTask task, OutputPlugin.Control control)
370
+ ConfigDiff doRun(TDClient client, Schema schema, PluginTask task, OutputPlugin.Control control)
371
371
  {
372
372
  boolean doUpload = startBulkImportSession(client, task.getSessionName(), task.getDatabase(), task.getLoadTargetTableName());
373
373
  task.setDoUpload(doUpload);
@@ -395,7 +395,7 @@ public class TdOutputPlugin
395
395
  List<TaskReport> successTaskReports)
396
396
  {
397
397
  PluginTask task = taskSource.loadTask(PluginTask.class);
398
- try (TdApiClient client = newTdApiClient(task)) {
398
+ try (TDClient client = newTDClient(task)) {
399
399
  String sessionName = task.getSessionName();
400
400
  log.info("Deleting bulk import session '{}'", sessionName);
401
401
  client.deleteBulkImportSession(sessionName);
@@ -416,65 +416,52 @@ public class TdOutputPlugin
416
416
  }
417
417
 
418
418
  @VisibleForTesting
419
- public TdApiClient newTdApiClient(final PluginTask task)
419
+ public TDClient newTDClient(final PluginTask task)
420
420
  {
421
- Optional<HttpProxyConfig> httpProxyConfig = newHttpProxyConfig(task.getHttpProxy());
422
- TdApiClientConfig config = new TdApiClientConfig(task.getEndpoint(), task.getUseSsl(), httpProxyConfig);
423
- TdApiClient client = new TdApiClient(task.getApiKey(), config);
424
- try {
425
- client.start();
426
- }
427
- catch (IOException e) {
428
- throw Throwables.propagate(e);
429
- }
430
- return client;
431
- }
432
-
433
- private Optional<HttpProxyConfig> newHttpProxyConfig(Optional<HttpProxyTask> task)
434
- {
435
- Optional<HttpProxyConfig> httpProxyConfig;
436
- if (task.isPresent()) {
437
- HttpProxyTask pt = task.get();
438
- httpProxyConfig = Optional.of(new HttpProxyConfig(pt.getHost(), pt.getPort(), pt.getUseSsl()));
439
- }
440
- else {
441
- httpProxyConfig = Optional.absent();
442
- }
443
- return httpProxyConfig;
421
+ TDClientBuilder builder = TDClient.newBuilder();
422
+ builder.setApiKey(task.getApiKey());
423
+ builder.setEndpoint(task.getEndpoint());
424
+ builder.setUseSSL(task.getUseSsl());
425
+ if (task.getHttpProxy().isPresent()) {
426
+ HttpProxyTask proxyTask = task.getHttpProxy().get();
427
+ builder.setProxy(new ProxyConfig(proxyTask.getHost(), proxyTask.getPort(), proxyTask.getUseSsl(),
428
+ Optional.<String>absent(), Optional.<String>absent()));
429
+ }
430
+ return builder.build();
444
431
  }
445
432
 
446
433
  @VisibleForTesting
447
- void createTableIfNotExists(TdApiClient client, String databaseName, String tableName)
434
+ void createTableIfNotExists(TDClient client, String databaseName, String tableName)
448
435
  {
449
436
  log.debug("Creating table \"{}\".\"{}\" if not exists", databaseName, tableName);
450
437
  try {
451
438
  client.createTable(databaseName, tableName);
452
439
  log.debug("Created table \"{}\".\"{}\"", databaseName, tableName);
453
440
  }
454
- catch (TdApiNotFoundException e) {
441
+ catch (TDClientHttpNotFoundException e) {
455
442
  try {
456
443
  client.createDatabase(databaseName);
457
444
  log.debug("Created database \"{}\"", databaseName);
458
445
  }
459
- catch (TdApiConflictException ex) {
446
+ catch (TDClientHttpConflictException ex) {
460
447
  // ignorable error
461
448
  }
462
449
  try {
463
450
  client.createTable(databaseName, tableName);
464
451
  log.debug("Created table \"{}\".\"{}\"", databaseName, tableName);
465
452
  }
466
- catch (TdApiConflictException exe) {
453
+ catch (TDClientHttpConflictException exe) {
467
454
  // ignorable error
468
455
  }
469
456
  }
470
- catch (TdApiConflictException e) {
457
+ catch (TDClientHttpConflictException e) {
471
458
  // ignorable error
472
459
  }
473
460
  }
474
461
 
475
462
  @VisibleForTesting
476
- String createTemporaryTableWithPrefix(TdApiClient client, String databaseName, String tablePrefix)
477
- throws TdApiConflictException
463
+ String createTemporaryTableWithPrefix(TDClient client, String databaseName, String tablePrefix)
464
+ throws TDClientHttpConflictException
478
465
  {
479
466
  String tableName = tablePrefix;
480
467
  while (true) {
@@ -484,7 +471,7 @@ public class TdOutputPlugin
484
471
  log.debug("Created temporal table \"{}\".\"{}\"", databaseName, tableName);
485
472
  return tableName;
486
473
  }
487
- catch (TdApiConflictException e) {
474
+ catch (TDClientHttpConflictException e) {
488
475
  log.debug("\"{}\".\"{}\" table already exists. Renaming temporal table.", databaseName, tableName);
489
476
  tableName += "_";
490
477
  }
@@ -492,17 +479,17 @@ public class TdOutputPlugin
492
479
  }
493
480
 
494
481
  @VisibleForTesting
495
- void validateTableExists(TdApiClient client, String databaseName, String tableName)
482
+ void validateTableExists(TDClient client, String databaseName, String tableName)
496
483
  {
497
484
  try {
498
- for (TDTable table : client.getTables(databaseName)) {
485
+ for (TDTable table : client.listTables(databaseName)) {
499
486
  if (table.getName().equals(tableName)) {
500
487
  return;
501
488
  }
502
489
  }
503
490
  throw new ConfigException(String.format("Table \"%s\".\"%s\" doesn't exist", databaseName, tableName));
504
491
  }
505
- catch (TdApiNotFoundException ex) {
492
+ catch (TDClientHttpNotFoundException ex) {
506
493
  throw new ConfigException(String.format("Database \"%s\" doesn't exist", databaseName), ex);
507
494
  }
508
495
  }
@@ -523,7 +510,7 @@ public class TdOutputPlugin
523
510
 
524
511
  // return false if all files are already uploaded
525
512
  @VisibleForTesting
526
- boolean startBulkImportSession(TdApiClient client,
513
+ boolean startBulkImportSession(TDClient client,
527
514
  String sessionName, String databaseName, String tableName)
528
515
  {
529
516
  log.info("Create bulk_import session {}", sessionName);
@@ -531,7 +518,7 @@ public class TdOutputPlugin
531
518
  try {
532
519
  client.createBulkImportSession(sessionName, databaseName, tableName);
533
520
  }
534
- catch (TdApiConflictException ex) {
521
+ catch (TDClientHttpConflictException ex) {
535
522
  // ignorable error
536
523
  }
537
524
  session = client.getBulkImportSession(sessionName);
@@ -539,7 +526,7 @@ public class TdOutputPlugin
539
526
 
540
527
  switch (session.getStatus()) {
541
528
  case UPLOADING:
542
- if (session.getUploadFrozen()) {
529
+ if (session.isUploadFrozen()) {
543
530
  return false;
544
531
  }
545
532
  return true;
@@ -558,24 +545,24 @@ public class TdOutputPlugin
558
545
  }
559
546
 
560
547
  @VisibleForTesting
561
- void completeBulkImportSession(TdApiClient client, Schema schema, PluginTask task, int priority)
548
+ void completeBulkImportSession(TDClient client, Schema schema, PluginTask task, int priority)
562
549
  {
563
550
  String sessionName = task.getSessionName();
564
551
  TDBulkImportSession session = client.getBulkImportSession(sessionName);
565
552
 
566
553
  switch (session.getStatus()) {
567
554
  case UPLOADING:
568
- if (!session.getUploadFrozen()) {
555
+ if (!session.isUploadFrozen()) {
569
556
  // freeze
570
557
  try {
571
558
  client.freezeBulkImportSession(sessionName);
572
559
  }
573
- catch (TdApiConflictException e) {
560
+ catch (TDClientHttpConflictException e) {
574
561
  // ignorable error
575
562
  }
576
563
  }
577
564
  // perform
578
- client.performBulkImportSession(sessionName, priority);
565
+ client.performBulkImportSession(sessionName); // TODO use priority
579
566
 
580
567
  // pass
581
568
  case PERFORMING:
@@ -629,7 +616,7 @@ public class TdOutputPlugin
629
616
  }
630
617
  }
631
618
 
632
- Map<String, TDColumnType> updateSchema(TdApiClient client, Schema inputSchema, PluginTask task)
619
+ Map<String, TDColumnType> updateSchema(TDClient client, Schema inputSchema, PluginTask task)
633
620
  {
634
621
  String databaseName = task.getDatabase();
635
622
  TDTable table = findTable(client, databaseName, task.getTable());
@@ -638,27 +625,32 @@ public class TdOutputPlugin
638
625
  inputSchema.visitColumns(new ColumnVisitor() {
639
626
  public void booleanColumn(Column column)
640
627
  {
641
- guessedSchema.put(column.getName(), TDPrimitiveColumnType.LONG);
628
+ guessedSchema.put(column.getName(), TDColumnType.LONG);
642
629
  }
643
630
 
644
631
  public void longColumn(Column column)
645
632
  {
646
- guessedSchema.put(column.getName(), TDPrimitiveColumnType.LONG);;
633
+ guessedSchema.put(column.getName(), TDColumnType.LONG);;
647
634
  }
648
635
 
649
636
  public void doubleColumn(Column column)
650
637
  {
651
- guessedSchema.put(column.getName(), TDPrimitiveColumnType.DOUBLE);
638
+ guessedSchema.put(column.getName(), TDColumnType.DOUBLE);
652
639
  }
653
640
 
654
641
  public void stringColumn(Column column)
655
642
  {
656
- guessedSchema.put(column.getName(), TDPrimitiveColumnType.STRING);
643
+ guessedSchema.put(column.getName(), TDColumnType.STRING);
657
644
  }
658
645
 
659
646
  public void timestampColumn(Column column)
660
647
  {
661
- guessedSchema.put(column.getName(), TDPrimitiveColumnType.STRING);
648
+ guessedSchema.put(column.getName(), TDColumnType.STRING);
649
+ }
650
+
651
+ public void jsonColumn(Column column)
652
+ {
653
+ guessedSchema.put(column.getName(), TDColumnType.STRING);
662
654
  }
663
655
  });
664
656
 
@@ -693,13 +685,13 @@ public class TdOutputPlugin
693
685
  newSchema.add(new TDColumn(pair.getKey(), pair.getValue(), key.getBytes(StandardCharsets.UTF_8)));
694
686
  }
695
687
 
696
- client.updateSchema(databaseName, task.getLoadTargetTableName(), newSchema);
688
+ client.updateTableSchema(databaseName, task.getLoadTargetTableName(), newSchema);
697
689
  return guessedSchema;
698
690
  }
699
691
 
700
- private static TDTable findTable(TdApiClient client, String databaseName, String tableName)
692
+ private static TDTable findTable(TDClient client, String databaseName, String tableName)
701
693
  {
702
- for (TDTable table : client.getTables(databaseName)) {
694
+ for (TDTable table : client.listTables(databaseName)) {
703
695
  if (table.getName().equals(tableName)) {
704
696
  return table;
705
697
  }
@@ -718,34 +710,47 @@ public class TdOutputPlugin
718
710
  return COLUMN_NAME_SQUASH_PATTERN.matcher(origName).replaceAll("_").toLowerCase();
719
711
  }
720
712
 
721
- void showBulkImportErrorRecords(TdApiClient client, String sessionName, int recordCountLimit)
713
+ void showBulkImportErrorRecords(TDClient client, String sessionName, final int recordCountLimit)
722
714
  {
723
715
  log.info("Show {} error records", recordCountLimit);
724
- try (InputStream in = client.getBulkImportErrorRecords(sessionName)) {
725
- Unpacker unpacker = new MessagePack().createUnpacker(new GZIPInputStream(in));
726
- UnpackerIterator records = unpacker.iterator();
727
- for (int i = 0; i < recordCountLimit; i++) {
728
- log.info(" {}", records.next());
716
+ client.getBulkImportErrorRecords(sessionName, new Function<InputStream, Void>()
717
+ {
718
+ @Override
719
+ public Void apply(InputStream input)
720
+ {
721
+ int errorRecordCount = 0;
722
+ try (MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(new GZIPInputStream(input))) {
723
+ while (unpacker.hasNext()) {
724
+ Value v = unpacker.unpackValue();
725
+ log.info(" {}", v.toJson());
726
+ errorRecordCount += 1;
727
+
728
+ if (errorRecordCount >= recordCountLimit) {
729
+ break;
730
+ }
731
+ }
732
+ }
733
+ catch (IOException ignored) {
734
+ log.info("Stop downloading error records");
735
+ }
736
+ return null;
729
737
  }
730
- }
731
- catch (Exception ignored) {
732
- log.info("Stop downloading error records", ignored);
733
- }
738
+ });
734
739
  }
735
740
 
736
741
  @VisibleForTesting
737
- TDBulkImportSession waitForStatusChange(TdApiClient client, String sessionName,
742
+ TDBulkImportSession waitForStatusChange(TDClient client, String sessionName,
738
743
  ImportStatus current, ImportStatus expecting, String operation)
739
744
  {
740
745
  TDBulkImportSession importSession;
741
746
  while (true) {
742
747
  importSession = client.getBulkImportSession(sessionName);
743
748
 
744
- if (importSession.is(expecting)) {
749
+ if (importSession.getStatus() == expecting) {
745
750
  return importSession;
746
751
 
747
752
  }
748
- else if (importSession.is(current)) {
753
+ else if (importSession.getStatus() == current) {
749
754
  // in progress
750
755
 
751
756
  }
@@ -763,7 +768,7 @@ public class TdOutputPlugin
763
768
  }
764
769
 
765
770
  @VisibleForTesting
766
- void renameTable(TdApiClient client, String databaseName, String oldName, String newName)
771
+ void renameTable(TDClient client, String databaseName, String oldName, String newName)
767
772
  {
768
773
  log.debug("Renaming table \"{}\".\"{}\" to \"{}\"", databaseName, oldName, newName);
769
774
  client.renameTable(databaseName, oldName, newName, true);
@@ -777,7 +782,7 @@ public class TdOutputPlugin
777
782
  RecordWriter closeLater = null;
778
783
  try {
779
784
  FieldWriterSet fieldWriters = new FieldWriterSet(log, task, schema);
780
- closeLater = new RecordWriter(task, taskIndex, newTdApiClient(task), fieldWriters);
785
+ closeLater = new RecordWriter(task, taskIndex, newTDClient(task), fieldWriters);
781
786
  RecordWriter recordWriter = closeLater;
782
787
  recordWriter.open(schema);
783
788
  closeLater = null;