embulk-input-marketo 0.6.6 → 0.6.7.test.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: f1e72b282ed342b95e3930ef55e016638987e11e
4
- data.tar.gz: fdcf297f81251c20bbaa96ffa00234bb0713f4cf
3
+ metadata.gz: fa96517b794a4be81d0c96ee7d02965aeeefff06
4
+ data.tar.gz: 2f7b3bc43e55c8009c0a7177504db1fbf53406e4
5
5
  SHA512:
6
- metadata.gz: 82a613c895244d77442f9154799cd57e729ef1d41a2287a83db5faee2def0afbd6ec36f9580560b43fadf4d2b643f1280f4e44d6304af4b0cabb43744a79cf80
7
- data.tar.gz: e1e5a7918318f15fbbdf83d70d39f285bcb2df3e996d3b177c9f909478821cc5b7735800f4b323446bd61c91b5485e6480671d6775e257432d605a2f9a591803
6
+ metadata.gz: 88f03e659566b8dd879fa52e02102cb1de879cd56264474a106eedbceb7bdc4071b93fb8975f501728568ba01d3e65be9b316e7b6ff37c14056732b14d1d117a
7
+ data.tar.gz: fd9ca5fd78bd3b164796a25b8322390020d96a5edacd8469f230b4da2a111f8fd3b95a0eeb1b8fed9c5654687b56e37d73332e288b037e05bc90895acd69c7c4
data/build.gradle CHANGED
@@ -16,7 +16,7 @@ repositories {
16
16
  configurations {
17
17
  provided
18
18
  }
19
- version = "0.6.6"
19
+ version = "0.6.7.test.1"
20
20
  sourceCompatibility = 1.7
21
21
  targetCompatibility = 1.7
22
22
 
@@ -33,8 +33,6 @@ import org.embulk.spi.time.TimestampParser;
33
33
  import org.embulk.spi.util.InputStreamFileInput;
34
34
  import org.embulk.spi.util.LineDecoder;
35
35
  import org.joda.time.DateTime;
36
- import org.joda.time.format.DateTimeFormatter;
37
- import org.joda.time.format.ISODateTimeFormat;
38
36
  import org.msgpack.value.Value;
39
37
 
40
38
  import java.io.InputStream;
@@ -43,7 +41,6 @@ import java.text.SimpleDateFormat;
43
41
  import java.util.ArrayList;
44
42
  import java.util.Date;
45
43
  import java.util.HashMap;
46
- import java.util.HashSet;
47
44
  import java.util.Iterator;
48
45
  import java.util.List;
49
46
  import java.util.Map;
@@ -55,18 +52,10 @@ import java.util.Set;
55
52
  */
56
53
  public abstract class MarketoBaseBulkExtractInputPlugin<T extends MarketoBaseBulkExtractInputPlugin.PluginTask> extends MarketoBaseInputPluginDelegate<T>
57
54
  {
58
- private static final String LATEST_FETCH_TIME = "latest_fetch_time";
59
-
60
- private static final String LATEST_UID_LIST = "latest_uids";
61
-
62
- private static final DateTimeFormatter ISO_DATETIME_FORMAT = ISODateTimeFormat.dateTimeParser();
63
-
64
55
  private static final String FROM_DATE = "from_date";
65
56
 
66
57
  private static final int MARKETO_MAX_RANGE_EXTRACT = 30;
67
58
 
68
- private static final String IMPORTED = "imported";
69
-
70
59
  public interface PluginTask extends MarketoBaseInputPluginDelegate.PluginTask, CsvTokenizer.PluginTask
71
60
  {
72
61
  @Config("from_date")
@@ -95,10 +84,6 @@ public abstract class MarketoBaseBulkExtractInputPlugin<T extends MarketoBaseBul
95
84
  @ConfigDefault("true")
96
85
  Boolean getIncremental();
97
86
 
98
- @Config("latest_uids")
99
- @ConfigDefault("[]")
100
- Set<String> getPreviousUids();
101
-
102
87
  @Config("to_date")
103
88
  @ConfigDefault("null")
104
89
  Optional<Date> getToDate();
@@ -107,6 +92,8 @@ public abstract class MarketoBaseBulkExtractInputPlugin<T extends MarketoBaseBul
107
92
 
108
93
  @Config("incremental_column")
109
94
  @ConfigDefault("\"createdAt\"")
95
+ //Incremental column are only keep here since we don't want to introduce too much change to plugin
96
+ //Consider remove it in next release
110
97
  Optional<String> getIncrementalColumn();
111
98
 
112
99
  void setIncrementalColumn(Optional<String> incrementalColumn);
@@ -153,39 +140,12 @@ public abstract class MarketoBaseBulkExtractInputPlugin<T extends MarketoBaseBul
153
140
  public ConfigDiff buildConfigDiff(T task, Schema schema, int taskCount, List<TaskReport> taskReports)
154
141
  {
155
142
  ConfigDiff configDiff = super.buildConfigDiff(task, schema, taskCount, taskReports);
156
- Long currentLatestFetchTime = 0L;
157
- Set latestUIds = new HashSet();
158
143
  String incrementalColumn = task.getIncrementalColumn().orNull();
159
- int imported = 0;
160
144
  if (incrementalColumn != null && task.getIncremental()) {
161
145
  DateFormat df = new SimpleDateFormat(MarketoUtils.MARKETO_DATE_SIMPLE_DATE_FORMAT);
162
- for (TaskReport taskReport : taskReports) {
163
- Long latestFetchTime = taskReport.get(Long.class, LATEST_FETCH_TIME);
164
- if (latestFetchTime == null) {
165
- continue;
166
- }
167
- if (currentLatestFetchTime < latestFetchTime) {
168
- currentLatestFetchTime = latestFetchTime;
169
- latestUIds = taskReport.get(Set.class, LATEST_UID_LIST);
170
- }
171
- else if (currentLatestFetchTime.equals(latestFetchTime)) {
172
- latestUIds.addAll(taskReport.get(Set.class, LATEST_UID_LIST));
173
- }
174
- if (taskReport.has(IMPORTED)) {
175
- imported = imported + taskReport.get(Integer.class, IMPORTED);
176
- }
177
- }
178
- // in case of we didn't import anything but search range is entirely in the past. Then we should move the the range anyway.
179
- if (imported == 0) {
180
- Date toDate = task.getToDate().orNull();
181
- configDiff.set(FROM_DATE, df.format(toDate));
182
- }
183
- else {
184
- // Otherwise it's should start from the currentLastFetchTime plus 1 second.
185
- configDiff.set(FROM_DATE, df.format(new DateTime(currentLatestFetchTime).plusSeconds(1).toDate()));
186
- }
187
- configDiff.set(LATEST_FETCH_TIME, currentLatestFetchTime);
188
- configDiff.set(LATEST_UID_LIST, latestUIds);
146
+ // We will always move the range forward.
147
+ Date toDate = task.getToDate().orNull();
148
+ configDiff.set(FROM_DATE, df.format(toDate));
189
149
  }
190
150
  return configDiff;
191
151
  }
@@ -194,8 +154,6 @@ public abstract class MarketoBaseBulkExtractInputPlugin<T extends MarketoBaseBul
194
154
  public TaskReport ingestServiceData(final T task, RecordImporter recordImporter, int taskIndex, PageBuilder pageBuilder)
195
155
  {
196
156
  TaskReport taskReport = Exec.newTaskReport();
197
- String incrementalColumn = task.getIncrementalColumn().orNull();
198
- String uidColumn = task.getUidColumn().orNull();
199
157
  if (Exec.isPreview()) {
200
158
  return importMockPreviewData(pageBuilder);
201
159
  }
@@ -209,9 +167,6 @@ public abstract class MarketoBaseBulkExtractInputPlugin<T extends MarketoBaseBul
209
167
  return new CsvRecordIterator(input, task);
210
168
  }
211
169
  }));
212
- Long latestFetchTime = task.getLatestFetchTime().or(0L);
213
- long currentTimestamp = latestFetchTime;
214
- Set<String> latestUids = task.getPreviousUids();
215
170
  //Keep the preview code here when we can enable real preview
216
171
  if (Exec.isPreview()) {
217
172
  csvRecords = Iterators.limit(csvRecords, PREVIEW_RECORD_LIMIT);
@@ -219,43 +174,10 @@ public abstract class MarketoBaseBulkExtractInputPlugin<T extends MarketoBaseBul
219
174
  int imported = 0;
220
175
  while (csvRecords.hasNext()) {
221
176
  Map<String, String> csvRecord = csvRecords.next();
222
- if (task.getIncremental()) {
223
- String incrementalTimeStamp = csvRecord.get(incrementalColumn);
224
- long timestamp = ISO_DATETIME_FORMAT.parseDateTime(incrementalTimeStamp).getMillis();
225
- //Ignore records that have timestamp smaller or equal with latestFetchTime
226
- if (latestFetchTime >= timestamp) {
227
- continue;
228
- }
229
- if (!csvRecord.containsKey(incrementalColumn)) {
230
- throw new DataException("Extracted record doesn't have incremental column " + incrementalColumn);
231
- }
232
- if (uidColumn != null) {
233
- String uid = csvRecord.get(uidColumn);
234
- if (latestUids.contains(uid)) {
235
- //Duplicate value
236
- continue;
237
- }
238
- }
239
- if (currentTimestamp < timestamp) {
240
- currentTimestamp = timestamp;
241
- //switch timestamp
242
- latestUids.clear();
243
- }
244
- else if (currentTimestamp == timestamp) {
245
- //timestamp is equal
246
- if (uidColumn != null) {
247
- String uid = csvRecord.get(uidColumn);
248
- latestUids.add(uid);
249
- }
250
- }
251
- }
252
177
  ObjectNode objectNode = MarketoUtils.OBJECT_MAPPER.valueToTree(csvRecord);
253
178
  recordImporter.importRecord(new AllStringJacksonServiceRecord(objectNode), pageBuilder);
254
179
  imported = imported + 1;
255
180
  }
256
- taskReport.set(LATEST_FETCH_TIME, currentTimestamp);
257
- taskReport.set(LATEST_UID_LIST, latestUids);
258
- taskReport.set(IMPORTED, imported);
259
181
  return taskReport;
260
182
  }
261
183
  }
@@ -3,14 +3,18 @@ package org.embulk.input.marketo.delegate;
3
3
  import org.embulk.EmbulkTestRuntime;
4
4
  import org.embulk.base.restclient.ServiceResponseMapper;
5
5
  import org.embulk.base.restclient.record.ValueLocator;
6
+ import org.embulk.config.ConfigDiff;
6
7
  import org.embulk.config.ConfigLoader;
7
8
  import org.embulk.config.ConfigSource;
8
9
  import org.embulk.config.TaskReport;
10
+ import org.embulk.input.marketo.MarketoUtils;
9
11
  import org.embulk.input.marketo.model.BulkExtractRangeHeader;
10
12
  import org.embulk.input.marketo.rest.MarketoRestClient;
11
13
  import org.embulk.spi.Column;
12
14
  import org.embulk.spi.PageBuilder;
15
+ import org.embulk.spi.Schema;
13
16
  import org.joda.time.DateTime;
17
+ import org.junit.Assert;
14
18
  import org.junit.Before;
15
19
  import org.junit.Rule;
16
20
  import org.junit.Test;
@@ -18,6 +22,8 @@ import org.mockito.ArgumentCaptor;
18
22
  import org.mockito.Mockito;
19
23
 
20
24
  import java.io.IOException;
25
+ import java.text.DateFormat;
26
+ import java.text.SimpleDateFormat;
21
27
  import java.util.Arrays;
22
28
  import java.util.Date;
23
29
  import java.util.List;
@@ -74,12 +80,8 @@ public class ActivityBulkExtractInputPluginTest
74
80
  Mockito.verify(mockMarketoRestclient, Mockito.times(1)).createActivityExtract(startDate.toDate(), startDate.plusDays(30).toDate());
75
81
  DateTime startDate2 = startDate.plusDays(30).plusSeconds(1);
76
82
  Mockito.verify(mockMarketoRestclient, Mockito.times(1)).createActivityExtract(startDate2.toDate(), startDate.plusDays(task.getFetchDays()).toDate());
77
- List<String> marketoUids = argumentCaptor.getAllValues();
78
- assertEquals(55, marketoUids.size());
79
- long latestFetchTime = taskReport.get(Long.class, "latest_fetch_time");
80
- Set latestUids = taskReport.get(Set.class, "latest_uids");
81
- assertEquals(1504888754000L, latestFetchTime);
82
- assertEquals(Arrays.asList("558681", "558682", "558683", "558684", "558685", "558686", "558687", "558688", "558689", "558690", "558691", "558692", "558693", "558694", "558695", "558696", "558697", "558698", "558699", "558700", "558701", "558702", "558703", "558704", "558705", "558706", "558707", "558708", "558709", "558710", "558711", "558712", "558713", "558714", "558716", "558717", "558718", "558719", "558720", "558721", "558722", "558723", "558724", "558725", "558726", "558727", "558728", "558729", "558730", "558731", "558732", "558733", "558734", "558735", "558736"), marketoUids);
83
- assertEquals(36, latestUids.size());
83
+ ConfigDiff configDiff = activityBulkExtractInputPlugin.buildConfigDiff(task, Mockito.mock(Schema.class), 1, Arrays.asList(taskReport));
84
+ DateFormat df = new SimpleDateFormat(MarketoUtils.MARKETO_DATE_SIMPLE_DATE_FORMAT);
85
+ Assert.assertEquals(df.format(startDate.plusDays(task.getFetchDays()).toDate()), configDiff.get(String.class, "from_date"));
84
86
  }
85
87
  }
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
5
5
  import org.embulk.EmbulkTestRuntime;
6
6
  import org.embulk.base.restclient.ServiceResponseMapper;
7
7
  import org.embulk.base.restclient.record.ValueLocator;
8
+ import org.embulk.config.ConfigDiff;
8
9
  import org.embulk.config.ConfigLoader;
9
10
  import org.embulk.config.ConfigSource;
10
11
  import org.embulk.config.TaskReport;
@@ -14,6 +15,7 @@ import org.embulk.input.marketo.model.MarketoField;
14
15
  import org.embulk.input.marketo.rest.MarketoRestClient;
15
16
  import org.embulk.spi.Column;
16
17
  import org.embulk.spi.PageBuilder;
18
+ import org.embulk.spi.Schema;
17
19
  import org.joda.time.DateTime;
18
20
  import org.junit.Assert;
19
21
  import org.junit.Before;
@@ -23,9 +25,11 @@ import org.mockito.ArgumentCaptor;
23
25
  import org.mockito.Mockito;
24
26
 
25
27
  import java.io.IOException;
28
+ import java.text.DateFormat;
29
+ import java.text.SimpleDateFormat;
30
+ import java.util.Arrays;
26
31
  import java.util.Date;
27
32
  import java.util.List;
28
- import java.util.Set;
29
33
 
30
34
  import static org.mockito.ArgumentMatchers.any;
31
35
  import static org.mockito.ArgumentMatchers.eq;
@@ -87,9 +91,9 @@ public class LeadBulkExtractInputPluginTest
87
91
  Mockito.verify(mockMarketoRestclient, Mockito.times(1)).createLeadBulkExtract(startDate2.toDate(), startDate.plusDays(task.getFetchDays()).toDate(), fieldNameFromMarketoFields, filterField);
88
92
  List<Long> leadIds = argumentCaptor.getAllValues();
89
93
  Assert.assertEquals(19, leadIds.size());
90
- long latestFetchTime = taskReport.get(Long.class, "latest_fetch_time");
91
- Assert.assertTrue(taskReport.get(Set.class, "latest_uids").isEmpty());
92
- Assert.assertEquals(1504888754000L, latestFetchTime);
94
+ ConfigDiff configDiff = bulkExtractInputPlugin.buildConfigDiff(task, Mockito.mock(Schema.class), 1, Arrays.asList(taskReport));
95
+ DateFormat df = new SimpleDateFormat(MarketoUtils.MARKETO_DATE_SIMPLE_DATE_FORMAT);
96
+ Assert.assertEquals(df.format(startDate.plusDays(task.getFetchDays()).toDate()), configDiff.get(String.class, "from_date"));
93
97
  Assert.assertArrayEquals(new Long[]{102488L, 102456L, 102445L, 102439L, 102471L, 102503L, 102424L, 102473L, 102505L, 102492L, 102495L, 102452L, 102435L, 102467L, 102420L, 102496L, 102448L, 102499L, 102431L}, leadIds.toArray());
94
98
  }
95
99
  }
@@ -158,20 +158,12 @@ public class MarketoBaseBulkExtractInputPluginTest
158
158
  public void buildConfigDiff() throws Exception
159
159
  {
160
160
  TaskReport taskReport1 = Mockito.mock(TaskReport.class);
161
- TaskReport taskReport2 = Mockito.mock(TaskReport.class);
162
- Mockito.when(taskReport1.get(Set.class, "latest_uids")).thenReturn(Sets.newHashSet("id1", "id2"));
163
- Mockito.when(taskReport2.get(Set.class, "latest_uids")).thenReturn(Sets.newHashSet("id3", "id4"));
164
- Mockito.when(taskReport1.get(Long.class, "latest_fetch_time")).thenReturn(1507539328000L);
165
- Mockito.when(taskReport2.get(Long.class, "latest_fetch_time")).thenReturn(1507625728000L);
166
161
  MarketoInputPluginDelegate.PluginTask task = Mockito.mock(MarketoInputPluginDelegate.PluginTask.class);
167
162
  Mockito.when(task.getIncremental()).thenReturn(true);
168
163
  Mockito.when(task.getIncrementalColumn()).thenReturn(Optional.of("createdAt"));
169
164
  Date toDate = new Date(1507625728000L);
170
165
  Mockito.when(task.getToDate()).thenReturn(Optional.of(toDate));
171
- ConfigDiff configDiff = baseBulkExtractInputPlugin.buildConfigDiff(task, Mockito.mock(Schema.class), 1, Arrays.asList(taskReport1, taskReport2));
172
- long latestFetchTime = configDiff.get(Long.class, "latest_fetch_time");
173
- assertEquals(1507625728000L, latestFetchTime);
174
- assertEquals(Sets.newHashSet("id3", "id4"), configDiff.get(Set.class, "latest_uids"));
166
+ ConfigDiff configDiff = baseBulkExtractInputPlugin.buildConfigDiff(task, Mockito.mock(Schema.class), 1, Arrays.asList(taskReport1));
175
167
  DateFormat df = new SimpleDateFormat(MarketoUtils.MARKETO_DATE_SIMPLE_DATE_FORMAT);
176
168
  assertEquals(df.format(toDate), configDiff.get(String.class, "from_date"));
177
169
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-marketo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.6.7.test.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - uu59
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-01-30 00:00:00.000000000 Z
13
+ date: 2018-02-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  requirement: !ruby/object:Gem::Requirement
@@ -127,9 +127,9 @@ files:
127
127
  - classpath/embulk-base-restclient-0.5.3.jar
128
128
  - classpath/jetty-client-9.2.14.v20151106.jar
129
129
  - classpath/jetty-util-9.2.14.v20151106.jar
130
+ - classpath/embulk-input-marketo-0.6.7.test.1.jar
130
131
  - classpath/embulk-util-retryhelper-jetty92-0.5.3.jar
131
132
  - classpath/jetty-io-9.2.14.v20151106.jar
132
- - classpath/embulk-input-marketo-0.6.6.jar
133
133
  homepage: https://github.com/treasure-data/embulk-input-marketo
134
134
  licenses:
135
135
  - Apache2
@@ -145,9 +145,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
145
  version: '0'
146
146
  required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  requirements:
148
- - - '>='
148
+ - - '>'
149
149
  - !ruby/object:Gem::Version
150
- version: '0'
150
+ version: 1.3.1
151
151
  requirements: []
152
152
  rubyforge_project:
153
153
  rubygems_version: 2.1.9