This is an automated email from the ASF dual-hosted git repository.
hutran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-gobblin.git
The following commit(s) were added to refs/heads/master by this push:
new 0523939 [GOBBLIN-890] Makeing ExtractID timeZone Configurable
0523939 is described below
commit 052393982332781a3118bfa0e69aa935cb4c0c08
Author: autumnust <[email protected]>
AuthorDate: Tue Oct 1 11:25:59 2019 -0700
[GOBBLIN-890] Makeing ExtractID timeZone Configurable
Closes #2745 from autumnust/configurableTimeZone
---
.../apache/gobblin/source/workunit/Extract.java | 15 +++++++-
.../gobblin/source/workunit/TimeZoneUtilsTest.java | 45 ++++++++++++++++++++++
2 files changed, 58 insertions(+), 2 deletions(-)
diff --git
a/gobblin-api/src/main/java/org/apache/gobblin/source/workunit/Extract.java
b/gobblin-api/src/main/java/org/apache/gobblin/source/workunit/Extract.java
index 7a3735b..a15a9ff 100644
--- a/gobblin-api/src/main/java/org/apache/gobblin/source/workunit/Extract.java
+++ b/gobblin-api/src/main/java/org/apache/gobblin/source/workunit/Extract.java
@@ -50,14 +50,15 @@ import org.apache.gobblin.configuration.WorkUnitState;
*/
public class Extract extends State {
+ static final String EXTRACT_ID_TIME_ZONE = "extract.extractIdTimeZone";
+ static final DateTimeZone DEFAULT_EXTRACT_ID_TIME_ZONE = DateTimeZone.UTC;
+
public enum TableType {
SNAPSHOT_ONLY,
SNAPSHOT_APPEND,
APPEND_ONLY
}
- private static final DateTimeFormatter DTF =
-
DateTimeFormat.forPattern("yyyyMMddHHmmss").withLocale(Locale.US).withZone(DateTimeZone.UTC);
private final State previousTableState = new State();
/**
@@ -75,6 +76,11 @@ public class Extract extends State {
public Extract(SourceState state, TableType type, String namespace, String
table) {
// Values should only be null for deserialization
if (state != null && type != null && !Strings.isNullOrEmpty(namespace) &&
!Strings.isNullOrEmpty(table)) {
+ // Constructing DTF
+ DateTimeZone timeZone = getTimeZoneHelper(state);
+
+ DateTimeFormatter DTF =
DateTimeFormat.forPattern("yyyyMMddHHmmss").withLocale(Locale.US).withZone(timeZone);
+
String extractId = DTF.print(new DateTime());
super.addAll(state);
super.setProp(ConfigurationKeys.EXTRACT_TABLE_TYPE_KEY, type.toString());
@@ -97,6 +103,11 @@ public class Extract extends State {
}
}
+ DateTimeZone getTimeZoneHelper(SourceState state) {
+ return state.contains(EXTRACT_ID_TIME_ZONE) ?
DateTimeZone.forID(state.getProp(EXTRACT_ID_TIME_ZONE))
+ : DEFAULT_EXTRACT_ID_TIME_ZONE;
+ }
+
/**
* Constructor.
*
diff --git
a/gobblin-api/src/test/java/org/apache/gobblin/source/workunit/TimeZoneUtilsTest.java
b/gobblin-api/src/test/java/org/apache/gobblin/source/workunit/TimeZoneUtilsTest.java
new file mode 100644
index 0000000..92e6aae
--- /dev/null
+++
b/gobblin-api/src/test/java/org/apache/gobblin/source/workunit/TimeZoneUtilsTest.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gobblin.source.workunit;
+
+import java.time.ZoneId;
+import java.util.TimeZone;
+
+import org.apache.gobblin.configuration.SourceState;
+import org.joda.time.DateTimeZone;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import static org.apache.gobblin.source.workunit.Extract.EXTRACT_ID_TIME_ZONE;
+
+
+public class TimeZoneUtilsTest {
+ @Test
+ public void testConfigurableTimeZone()
+ throws Exception {
+ SourceState state = new SourceState();
+ state.setProp(EXTRACT_ID_TIME_ZONE, "America/Los_Angeles");
+ Extract extract = new Extract(state, Extract.TableType.APPEND_ONLY,
"random", "table");
+ Assert.assertEquals(extract.getTimeZoneHelper(state).toTimeZone(),
+ TimeZone.getTimeZone(ZoneId.of("America/Los_Angeles")));
+
+ state.removeProp(EXTRACT_ID_TIME_ZONE);
+ extract = new Extract(state, Extract.TableType.APPEND_ONLY, "random",
"table");
+ Assert.assertEquals(extract.getTimeZoneHelper(state), DateTimeZone.UTC);
+ }
+}