You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2020/01/06 03:32:43 UTC

[GitHub] [incubator-hudi] OpenOpened opened a new pull request #1188: provide a custom time zone definition

OpenOpened opened a new pull request #1188: provide a custom time zone definition
URL: https://github.com/apache/incubator-hudi/pull/1188
 
 
   ## *Tips*
   - *Thank you very much for contributing to Apache Hudi.*
   - *Please review https://hudi.apache.org/contributing.html before opening a pull request.*
   
   ## What is the purpose of the pull request
   provide a custom time zone definition, such as GMT+8:00 **Instead of default "GMT"**
   
   ## Verify this pull request
   
   exists test units

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] leesf commented on issue #1188: provide a custom time zone definition

Posted by GitBox <gi...@apache.org>.
leesf commented on issue #1188: provide a custom time zone definition
URL: https://github.com/apache/incubator-hudi/pull/1188#issuecomment-571002293
 
 
   @OpenOpened Thanks for opening this PR, would you please change the title? and please refer to the guide http://hudi.apache.org/contributing.html#life-of-a-contributor.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r365052896
 
 

 ##########
 File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/TestTimestampBasedKeyGenerator.java
 ##########
 @@ -0,0 +1,89 @@
+/*
+ * 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.hudi.utilities;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.hudi.DataSourceWriteOptions;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.common.util.TypedProperties;
+import org.apache.hudi.utilities.keygen.TimestampBasedKeyGenerator;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestTimestampBasedKeyGenerator {
+  private Schema schema = SchemaTestUtil.getTimestampEvolvedSchema();
+  private GenericRecord baseRecord = null;
+
+  public TestTimestampBasedKeyGenerator() throws IOException {
+  }
+
+  @Before
+  public void initialize() throws IOException {
+    baseRecord = SchemaTestUtil
+        .generateAvroRecordFromJson(schema, 1, "001", "f1");
+  }
+
+  private TypedProperties getKeyConfig(String recordKeyFieldName, String partitionPathField, String hiveStylePartitioning) {
+    TypedProperties props = new TypedProperties();
+    props.setProperty(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY(), recordKeyFieldName);
+    props.setProperty(DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY(), partitionPathField);
+    props.setProperty(DataSourceWriteOptions.HIVE_STYLE_PARTITIONING_OPT_KEY(), hiveStylePartitioning);
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "EPOCHMILLISECONDS");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.output.dateformat", "yyyy-MM-dd hh");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    return props;
+  }
+
+  private TypedProperties getKeyConfig2(String recordKeyFieldName, String partitionPathField, String hiveStylePartitioning) {
+    TypedProperties props = getKeyConfig(recordKeyFieldName, partitionPathField, hiveStylePartitioning);
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT");
+    return props;
+  }
+
+  private TypedProperties getKeyConfig3(String recordKeyFieldName, String partitionPathField, String hiveStylePartitioning) {
+    TypedProperties props = getKeyConfig(recordKeyFieldName, partitionPathField, hiveStylePartitioning);
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "DATE_STRING");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.input.dateformat", "yyyy-MM-dd hh:mm:ss");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    return props;
+  }
 
 Review comment:
   thank's reply, i will fix it. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r365228893
 
 

 ##########
 File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/TestTimestampBasedKeyGenerator.java
 ##########
 @@ -0,0 +1,80 @@
+/*
+ * 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.hudi.utilities;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.hudi.DataSourceWriteOptions;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.common.util.TypedProperties;
+import org.apache.hudi.utilities.keygen.TimestampBasedKeyGenerator;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestTimestampBasedKeyGenerator {
+  private Schema schema = SchemaTestUtil.getTimestampEvolvedSchema();
+  private GenericRecord baseRecord = null;
+
+  public TestTimestampBasedKeyGenerator() throws IOException {
+  }
+
+  @Before
+  public void initialize() throws IOException {
+    baseRecord = SchemaTestUtil
+        .generateAvroRecordFromJson(schema, 1, "001", "f1");
+  }
+
+  private TypedProperties getBaseKeyConfig(String recordKeyFieldName, String partitionPathField, String hiveStylePartitioning) {
+    TypedProperties props = new TypedProperties();
+    props.setProperty(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY(), recordKeyFieldName);
+    props.setProperty(DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY(), partitionPathField);
+    props.setProperty(DataSourceWriteOptions.HIVE_STYLE_PARTITIONING_OPT_KEY(), hiveStylePartitioning);
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "EPOCHMILLISECONDS");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.output.dateformat", "yyyy-MM-dd hh");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    return props;
+  }
+
+  @Test
+  public void testTimestampBasedKeyGenerator() {
+    // if timezone is GMT+8:00
+    baseRecord.put("createTime", 1578283932000L);
+    TypedProperties props = getBaseKeyConfig("field1", "createTime", "false");
+    HoodieKey hk1 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk1.getPartitionPath(), "2020-01-06 12");
+
+    // if timezone is GMT
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT");
+    HoodieKey hk2 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk2.getPartitionPath(), "2020-01-06 04");
+
+    // if timestamp is DATE_STRING, and timestamp type is DATE_STRING
+    baseRecord.put("createTime", "2020-01-06 12:12:12");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "DATE_STRING");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.input.dateformat", "yyyy-MM-dd hh:mm:ss");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    HoodieKey hk3 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk3.getPartitionPath(), "2020-01-06 12");
+  }
+}
 
 Review comment:
   Then what do I need to do? addition more test unites?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] sev7e0 commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
sev7e0 commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r363577501
 
 

 ##########
 File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/TimestampBasedKeyGenerator.java
 ##########
 @@ -70,20 +74,22 @@ public TimestampBasedKeyGenerator(TypedProperties config) {
         Arrays.asList(Config.TIMESTAMP_TYPE_FIELD_PROP, Config.TIMESTAMP_OUTPUT_DATE_FORMAT_PROP));
     this.timestampType = TimestampType.valueOf(config.getString(Config.TIMESTAMP_TYPE_FIELD_PROP));
     this.outputDateFormat = config.getString(Config.TIMESTAMP_OUTPUT_DATE_FORMAT_PROP);
+    this.timeZone = TimeZone.getTimeZone(config.getString(Config.TIMESTAMP_TIMEZONE_FORMAT_PROP, "GMT"));
 
     if (timestampType == TimestampType.DATE_STRING || timestampType == TimestampType.MIXED) {
       DataSourceUtils.checkRequiredProperties(config,
           Collections.singletonList(Config.TIMESTAMP_INPUT_DATE_FORMAT_PROP));
       this.inputDateFormat = new SimpleDateFormat(config.getString(Config.TIMESTAMP_INPUT_DATE_FORMAT_PROP));
-      this.inputDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
+      this.timeZone = TimeZone.getTimeZone(config.getString(Config.TIMESTAMP_TIMEZONE_FORMAT_PROP, "GMT"));
 
 Review comment:
   `timeZone` has been init. I don't think we need to do this again.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] leesf commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
leesf commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r365166437
 
 

 ##########
 File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/TestTimestampBasedKeyGenerator.java
 ##########
 @@ -0,0 +1,80 @@
+/*
+ * 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.hudi.utilities;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.hudi.DataSourceWriteOptions;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.common.util.TypedProperties;
+import org.apache.hudi.utilities.keygen.TimestampBasedKeyGenerator;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestTimestampBasedKeyGenerator {
+  private Schema schema = SchemaTestUtil.getTimestampEvolvedSchema();
+  private GenericRecord baseRecord = null;
+
+  public TestTimestampBasedKeyGenerator() throws IOException {
+  }
+
+  @Before
+  public void initialize() throws IOException {
+    baseRecord = SchemaTestUtil
+        .generateAvroRecordFromJson(schema, 1, "001", "f1");
+  }
+
+  private TypedProperties getBaseKeyConfig(String recordKeyFieldName, String partitionPathField, String hiveStylePartitioning) {
+    TypedProperties props = new TypedProperties();
+    props.setProperty(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY(), recordKeyFieldName);
+    props.setProperty(DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY(), partitionPathField);
+    props.setProperty(DataSourceWriteOptions.HIVE_STYLE_PARTITIONING_OPT_KEY(), hiveStylePartitioning);
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "EPOCHMILLISECONDS");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.output.dateformat", "yyyy-MM-dd hh");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    return props;
+  }
+
+  @Test
+  public void testTimestampBasedKeyGenerator() {
+    // if timezone is GMT+8:00
+    baseRecord.put("createTime", 1578283932000L);
+    TypedProperties props = getBaseKeyConfig("field1", "createTime", "false");
+    HoodieKey hk1 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk1.getPartitionPath(), "2020-01-06 12");
+
+    // if timezone is GMT
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT");
+    HoodieKey hk2 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk2.getPartitionPath(), "2020-01-06 04");
+
+    // if timestamp is DATE_STRING, and timestamp type is DATE_STRING
+    baseRecord.put("createTime", "2020-01-06 12:12:12");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "DATE_STRING");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.input.dateformat", "yyyy-MM-dd hh:mm:ss");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    HoodieKey hk3 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk3.getPartitionPath(), "2020-01-06 12");
+  }
+}
 
 Review comment:
   I think we would optimize the `TestTimestampBasedKeyGenerator` to the [gist](https://gist.github.com/leesf/b36654ba68c25a48d56958dabec07b83), WDYT?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] leesf commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
leesf commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r365232440
 
 

 ##########
 File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/TestTimestampBasedKeyGenerator.java
 ##########
 @@ -0,0 +1,80 @@
+/*
+ * 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.hudi.utilities;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.hudi.DataSourceWriteOptions;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.common.util.TypedProperties;
+import org.apache.hudi.utilities.keygen.TimestampBasedKeyGenerator;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestTimestampBasedKeyGenerator {
+  private Schema schema = SchemaTestUtil.getTimestampEvolvedSchema();
+  private GenericRecord baseRecord = null;
+
+  public TestTimestampBasedKeyGenerator() throws IOException {
+  }
+
+  @Before
+  public void initialize() throws IOException {
+    baseRecord = SchemaTestUtil
+        .generateAvroRecordFromJson(schema, 1, "001", "f1");
+  }
+
+  private TypedProperties getBaseKeyConfig(String recordKeyFieldName, String partitionPathField, String hiveStylePartitioning) {
+    TypedProperties props = new TypedProperties();
+    props.setProperty(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY(), recordKeyFieldName);
+    props.setProperty(DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY(), partitionPathField);
+    props.setProperty(DataSourceWriteOptions.HIVE_STYLE_PARTITIONING_OPT_KEY(), hiveStylePartitioning);
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "EPOCHMILLISECONDS");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.output.dateformat", "yyyy-MM-dd hh");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    return props;
+  }
+
+  @Test
+  public void testTimestampBasedKeyGenerator() {
+    // if timezone is GMT+8:00
+    baseRecord.put("createTime", 1578283932000L);
+    TypedProperties props = getBaseKeyConfig("field1", "createTime", "false");
+    HoodieKey hk1 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk1.getPartitionPath(), "2020-01-06 12");
+
+    // if timezone is GMT
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT");
+    HoodieKey hk2 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk2.getPartitionPath(), "2020-01-06 04");
+
+    // if timestamp is DATE_STRING, and timestamp type is DATE_STRING
+    baseRecord.put("createTime", "2020-01-06 12:12:12");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "DATE_STRING");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.input.dateformat", "yyyy-MM-dd hh:mm:ss");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    HoodieKey hk3 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk3.getPartitionPath(), "2020-01-06 12");
+  }
+}
 
 Review comment:
   > Then what do I need to do? addition more test units?
   
   You may copy the code from gist and cover the current `TestTimestampBasedKeyGenerator` class.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] leesf commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
leesf commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r364722588
 
 

 ##########
 File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/TestTimestampBasedKeyGenerator.java
 ##########
 @@ -0,0 +1,89 @@
+/*
+ * 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.hudi.utilities;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.hudi.DataSourceWriteOptions;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.common.util.TypedProperties;
+import org.apache.hudi.utilities.keygen.TimestampBasedKeyGenerator;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestTimestampBasedKeyGenerator {
+  private Schema schema = SchemaTestUtil.getTimestampEvolvedSchema();
+  private GenericRecord baseRecord = null;
+
+  public TestTimestampBasedKeyGenerator() throws IOException {
+  }
+
+  @Before
+  public void initialize() throws IOException {
+    baseRecord = SchemaTestUtil
+        .generateAvroRecordFromJson(schema, 1, "001", "f1");
+  }
+
+  private TypedProperties getKeyConfig(String recordKeyFieldName, String partitionPathField, String hiveStylePartitioning) {
+    TypedProperties props = new TypedProperties();
+    props.setProperty(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY(), recordKeyFieldName);
+    props.setProperty(DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY(), partitionPathField);
+    props.setProperty(DataSourceWriteOptions.HIVE_STYLE_PARTITIONING_OPT_KEY(), hiveStylePartitioning);
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "EPOCHMILLISECONDS");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.output.dateformat", "yyyy-MM-dd hh");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    return props;
+  }
+
+  private TypedProperties getKeyConfig2(String recordKeyFieldName, String partitionPathField, String hiveStylePartitioning) {
+    TypedProperties props = getKeyConfig(recordKeyFieldName, partitionPathField, hiveStylePartitioning);
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT");
+    return props;
+  }
+
+  private TypedProperties getKeyConfig3(String recordKeyFieldName, String partitionPathField, String hiveStylePartitioning) {
+    TypedProperties props = getKeyConfig(recordKeyFieldName, partitionPathField, hiveStylePartitioning);
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "DATE_STRING");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.input.dateformat", "yyyy-MM-dd hh:mm:ss");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    return props;
+  }
 
 Review comment:
   would these three methods simplify to just one method? 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r365227387
 
 

 ##########
 File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/TestTimestampBasedKeyGenerator.java
 ##########
 @@ -0,0 +1,80 @@
+/*
+ * 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.hudi.utilities;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.hudi.DataSourceWriteOptions;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.common.util.TypedProperties;
+import org.apache.hudi.utilities.keygen.TimestampBasedKeyGenerator;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestTimestampBasedKeyGenerator {
+  private Schema schema = SchemaTestUtil.getTimestampEvolvedSchema();
+  private GenericRecord baseRecord = null;
+
+  public TestTimestampBasedKeyGenerator() throws IOException {
+  }
+
+  @Before
+  public void initialize() throws IOException {
+    baseRecord = SchemaTestUtil
+        .generateAvroRecordFromJson(schema, 1, "001", "f1");
+  }
+
+  private TypedProperties getBaseKeyConfig(String recordKeyFieldName, String partitionPathField, String hiveStylePartitioning) {
+    TypedProperties props = new TypedProperties();
+    props.setProperty(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY(), recordKeyFieldName);
+    props.setProperty(DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY(), partitionPathField);
+    props.setProperty(DataSourceWriteOptions.HIVE_STYLE_PARTITIONING_OPT_KEY(), hiveStylePartitioning);
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "EPOCHMILLISECONDS");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.output.dateformat", "yyyy-MM-dd hh");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    return props;
+  }
+
+  @Test
+  public void testTimestampBasedKeyGenerator() {
+    // if timezone is GMT+8:00
+    baseRecord.put("createTime", 1578283932000L);
+    TypedProperties props = getBaseKeyConfig("field1", "createTime", "false");
+    HoodieKey hk1 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk1.getPartitionPath(), "2020-01-06 12");
+
+    // if timezone is GMT
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT");
+    HoodieKey hk2 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk2.getPartitionPath(), "2020-01-06 04");
+
+    // if timestamp is DATE_STRING, and timestamp type is DATE_STRING
+    baseRecord.put("createTime", "2020-01-06 12:12:12");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "DATE_STRING");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.input.dateformat", "yyyy-MM-dd hh:mm:ss");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    HoodieKey hk3 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk3.getPartitionPath(), "2020-01-06 12");
+  }
+}
 
 Review comment:
   Is that right? This is the web address: [gist](https://gist.github.com/OpenOpened/2b50b86f21c36f3e07c78cb44d97ec9c)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r365227387
 
 

 ##########
 File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/TestTimestampBasedKeyGenerator.java
 ##########
 @@ -0,0 +1,80 @@
+/*
+ * 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.hudi.utilities;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.hudi.DataSourceWriteOptions;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.common.util.TypedProperties;
+import org.apache.hudi.utilities.keygen.TimestampBasedKeyGenerator;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestTimestampBasedKeyGenerator {
+  private Schema schema = SchemaTestUtil.getTimestampEvolvedSchema();
+  private GenericRecord baseRecord = null;
+
+  public TestTimestampBasedKeyGenerator() throws IOException {
+  }
+
+  @Before
+  public void initialize() throws IOException {
+    baseRecord = SchemaTestUtil
+        .generateAvroRecordFromJson(schema, 1, "001", "f1");
+  }
+
+  private TypedProperties getBaseKeyConfig(String recordKeyFieldName, String partitionPathField, String hiveStylePartitioning) {
+    TypedProperties props = new TypedProperties();
+    props.setProperty(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY(), recordKeyFieldName);
+    props.setProperty(DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY(), partitionPathField);
+    props.setProperty(DataSourceWriteOptions.HIVE_STYLE_PARTITIONING_OPT_KEY(), hiveStylePartitioning);
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "EPOCHMILLISECONDS");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.output.dateformat", "yyyy-MM-dd hh");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    return props;
+  }
+
+  @Test
+  public void testTimestampBasedKeyGenerator() {
+    // if timezone is GMT+8:00
+    baseRecord.put("createTime", 1578283932000L);
+    TypedProperties props = getBaseKeyConfig("field1", "createTime", "false");
+    HoodieKey hk1 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk1.getPartitionPath(), "2020-01-06 12");
+
+    // if timezone is GMT
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT");
+    HoodieKey hk2 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk2.getPartitionPath(), "2020-01-06 04");
+
+    // if timestamp is DATE_STRING, and timestamp type is DATE_STRING
+    baseRecord.put("createTime", "2020-01-06 12:12:12");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "DATE_STRING");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.input.dateformat", "yyyy-MM-dd hh:mm:ss");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    HoodieKey hk3 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk3.getPartitionPath(), "2020-01-06 12");
+  }
+}
 
 Review comment:
   Is that right? This is the web address: [gist](https://gist.github.com/OpenOpened/2b50b86f21c36f3e07c78cb44d97ec9c)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r365175719
 
 

 ##########
 File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/TestTimestampBasedKeyGenerator.java
 ##########
 @@ -0,0 +1,80 @@
+/*
+ * 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.hudi.utilities;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.hudi.DataSourceWriteOptions;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.common.util.TypedProperties;
+import org.apache.hudi.utilities.keygen.TimestampBasedKeyGenerator;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestTimestampBasedKeyGenerator {
+  private Schema schema = SchemaTestUtil.getTimestampEvolvedSchema();
+  private GenericRecord baseRecord = null;
+
+  public TestTimestampBasedKeyGenerator() throws IOException {
+  }
+
+  @Before
+  public void initialize() throws IOException {
+    baseRecord = SchemaTestUtil
+        .generateAvroRecordFromJson(schema, 1, "001", "f1");
+  }
+
+  private TypedProperties getBaseKeyConfig(String recordKeyFieldName, String partitionPathField, String hiveStylePartitioning) {
+    TypedProperties props = new TypedProperties();
+    props.setProperty(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY(), recordKeyFieldName);
+    props.setProperty(DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY(), partitionPathField);
+    props.setProperty(DataSourceWriteOptions.HIVE_STYLE_PARTITIONING_OPT_KEY(), hiveStylePartitioning);
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "EPOCHMILLISECONDS");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.output.dateformat", "yyyy-MM-dd hh");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    return props;
+  }
+
+  @Test
+  public void testTimestampBasedKeyGenerator() {
+    // if timezone is GMT+8:00
+    baseRecord.put("createTime", 1578283932000L);
+    TypedProperties props = getBaseKeyConfig("field1", "createTime", "false");
+    HoodieKey hk1 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk1.getPartitionPath(), "2020-01-06 12");
+
+    // if timezone is GMT
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT");
+    HoodieKey hk2 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk2.getPartitionPath(), "2020-01-06 04");
+
+    // if timestamp is DATE_STRING, and timestamp type is DATE_STRING
+    baseRecord.put("createTime", "2020-01-06 12:12:12");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "DATE_STRING");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.input.dateformat", "yyyy-MM-dd hh:mm:ss");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    HoodieKey hk3 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk3.getPartitionPath(), "2020-01-06 12");
+  }
+}
 
 Review comment:
   ok, What should I do?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r363567010
 
 

 ##########
 File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/TimestampBasedKeyGenerator.java
 ##########
 @@ -51,6 +51,8 @@
 
   private final String outputDateFormat;
 
+  private TimeZone timeZone;
 
 Review comment:
   Because TimeZone is not necessarily initialized when the class is initialized.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r365227085
 
 

 ##########
 File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/TestTimestampBasedKeyGenerator.java
 ##########
 @@ -0,0 +1,80 @@
+/*
+ * 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.hudi.utilities;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.hudi.DataSourceWriteOptions;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.common.util.TypedProperties;
+import org.apache.hudi.utilities.keygen.TimestampBasedKeyGenerator;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestTimestampBasedKeyGenerator {
+  private Schema schema = SchemaTestUtil.getTimestampEvolvedSchema();
+  private GenericRecord baseRecord = null;
+
+  public TestTimestampBasedKeyGenerator() throws IOException {
+  }
+
+  @Before
+  public void initialize() throws IOException {
+    baseRecord = SchemaTestUtil
+        .generateAvroRecordFromJson(schema, 1, "001", "f1");
+  }
+
+  private TypedProperties getBaseKeyConfig(String recordKeyFieldName, String partitionPathField, String hiveStylePartitioning) {
+    TypedProperties props = new TypedProperties();
+    props.setProperty(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY(), recordKeyFieldName);
+    props.setProperty(DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY(), partitionPathField);
+    props.setProperty(DataSourceWriteOptions.HIVE_STYLE_PARTITIONING_OPT_KEY(), hiveStylePartitioning);
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "EPOCHMILLISECONDS");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.output.dateformat", "yyyy-MM-dd hh");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    return props;
+  }
+
+  @Test
+  public void testTimestampBasedKeyGenerator() {
+    // if timezone is GMT+8:00
+    baseRecord.put("createTime", 1578283932000L);
+    TypedProperties props = getBaseKeyConfig("field1", "createTime", "false");
+    HoodieKey hk1 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk1.getPartitionPath(), "2020-01-06 12");
+
+    // if timezone is GMT
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT");
+    HoodieKey hk2 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk2.getPartitionPath(), "2020-01-06 04");
+
+    // if timestamp is DATE_STRING, and timestamp type is DATE_STRING
+    baseRecord.put("createTime", "2020-01-06 12:12:12");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "DATE_STRING");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.input.dateformat", "yyyy-MM-dd hh:mm:ss");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    HoodieKey hk3 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk3.getPartitionPath(), "2020-01-06 12");
+  }
+}
 
 Review comment:
   Is that right? This is the web address: [](https://gist.github.com/OpenOpened/2b50b86f21c36f3e07c78cb44d97ec9c)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r363567010
 
 

 ##########
 File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/TimestampBasedKeyGenerator.java
 ##########
 @@ -51,6 +51,8 @@
 
   private final String outputDateFormat;
 
+  private TimeZone timeZone;
 
 Review comment:
   Because TimeZone is not necessarily initialized when the class is initialized.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r365228893
 
 

 ##########
 File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/TestTimestampBasedKeyGenerator.java
 ##########
 @@ -0,0 +1,80 @@
+/*
+ * 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.hudi.utilities;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.hudi.DataSourceWriteOptions;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.common.util.TypedProperties;
+import org.apache.hudi.utilities.keygen.TimestampBasedKeyGenerator;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestTimestampBasedKeyGenerator {
+  private Schema schema = SchemaTestUtil.getTimestampEvolvedSchema();
+  private GenericRecord baseRecord = null;
+
+  public TestTimestampBasedKeyGenerator() throws IOException {
+  }
+
+  @Before
+  public void initialize() throws IOException {
+    baseRecord = SchemaTestUtil
+        .generateAvroRecordFromJson(schema, 1, "001", "f1");
+  }
+
+  private TypedProperties getBaseKeyConfig(String recordKeyFieldName, String partitionPathField, String hiveStylePartitioning) {
+    TypedProperties props = new TypedProperties();
+    props.setProperty(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY(), recordKeyFieldName);
+    props.setProperty(DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY(), partitionPathField);
+    props.setProperty(DataSourceWriteOptions.HIVE_STYLE_PARTITIONING_OPT_KEY(), hiveStylePartitioning);
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "EPOCHMILLISECONDS");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.output.dateformat", "yyyy-MM-dd hh");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    return props;
+  }
+
+  @Test
+  public void testTimestampBasedKeyGenerator() {
+    // if timezone is GMT+8:00
+    baseRecord.put("createTime", 1578283932000L);
+    TypedProperties props = getBaseKeyConfig("field1", "createTime", "false");
+    HoodieKey hk1 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk1.getPartitionPath(), "2020-01-06 12");
+
+    // if timezone is GMT
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT");
+    HoodieKey hk2 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk2.getPartitionPath(), "2020-01-06 04");
+
+    // if timestamp is DATE_STRING, and timestamp type is DATE_STRING
+    baseRecord.put("createTime", "2020-01-06 12:12:12");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "DATE_STRING");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.input.dateformat", "yyyy-MM-dd hh:mm:ss");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    HoodieKey hk3 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk3.getPartitionPath(), "2020-01-06 12");
+  }
+}
 
 Review comment:
   Then what do I need to do? addition more test units?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r365284878
 
 

 ##########
 File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/TestTimestampBasedKeyGenerator.java
 ##########
 @@ -0,0 +1,80 @@
+/*
+ * 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.hudi.utilities;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.hudi.DataSourceWriteOptions;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.common.util.TypedProperties;
+import org.apache.hudi.utilities.keygen.TimestampBasedKeyGenerator;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestTimestampBasedKeyGenerator {
+  private Schema schema = SchemaTestUtil.getTimestampEvolvedSchema();
+  private GenericRecord baseRecord = null;
+
+  public TestTimestampBasedKeyGenerator() throws IOException {
+  }
+
+  @Before
+  public void initialize() throws IOException {
+    baseRecord = SchemaTestUtil
+        .generateAvroRecordFromJson(schema, 1, "001", "f1");
+  }
+
+  private TypedProperties getBaseKeyConfig(String recordKeyFieldName, String partitionPathField, String hiveStylePartitioning) {
+    TypedProperties props = new TypedProperties();
+    props.setProperty(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY(), recordKeyFieldName);
+    props.setProperty(DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY(), partitionPathField);
+    props.setProperty(DataSourceWriteOptions.HIVE_STYLE_PARTITIONING_OPT_KEY(), hiveStylePartitioning);
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "EPOCHMILLISECONDS");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.output.dateformat", "yyyy-MM-dd hh");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    return props;
+  }
+
+  @Test
+  public void testTimestampBasedKeyGenerator() {
+    // if timezone is GMT+8:00
+    baseRecord.put("createTime", 1578283932000L);
+    TypedProperties props = getBaseKeyConfig("field1", "createTime", "false");
+    HoodieKey hk1 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk1.getPartitionPath(), "2020-01-06 12");
+
+    // if timezone is GMT
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT");
+    HoodieKey hk2 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk2.getPartitionPath(), "2020-01-06 04");
+
+    // if timestamp is DATE_STRING, and timestamp type is DATE_STRING
+    baseRecord.put("createTime", "2020-01-06 12:12:12");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "DATE_STRING");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.input.dateformat", "yyyy-MM-dd hh:mm:ss");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    HoodieKey hk3 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk3.getPartitionPath(), "2020-01-06 12");
+  }
+}
 
 Review comment:
   already covered.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] leesf commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
leesf commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r365165705
 
 

 ##########
 File path: hudi-common/src/test/resources/timestamp-test-evolved.avsc
 ##########
 @@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+{
+  "namespace": "example.avro",
+  "type": "record",
+  "name": "User",
+  "fields": [
+    {"name": "field1", "type": ["null", "string"], "default": null},
+    {"name": "field2", "type": ["null", "string"], "default": null},
+    {"name": "createTime", "type": ["null", "string"], "default": null},
+    {"name": "name", "type": ["null", "string"], "default": null},
+    {"name": "favoriteIntNumber",  "type": ["null", "int"], "default": null},
+    {"name": "favoriteNumber",  "type": ["null", "long"], "default": null},
+    {"name": "favoriteFloatNumber",  "type": ["null", "float"], "default": null},
+    {"name": "favoriteDoubleNumber",  "type": ["null", "double"], "default": null},
+    {"name": "tags", "type": ["null", {"values": ["null", {"fields": [{"default": null, "type": ["null", "string"], "name": "item1"}, {"default": null, "type": ["null", "string"], "name": "item2"} ], "type": "record", "name": "tagsMapItems"} ], "type": "map"} ], "default": null},
+    {"default": null, "name": "testNestedRecord", "type": ["null", {"fields": [{"default": null, "name": "isAdmin", "type": ["null", "boolean"] }, {"default": null, "name": "userId", "type": ["null", "string"] } ], "name": "notes", "type": "record"}]},
+    {"default": null, "name": "stringArray", "type": ["null", {"items": "string", "type": "array"}]}
 
 Review comment:
   Would we remove this useless fields?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r363568766
 
 

 ##########
 File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/TimestampBasedKeyGenerator.java
 ##########
 @@ -51,6 +51,8 @@
 
   private final String outputDateFormat;
 
+  private TimeZone timeZone;
 
 Review comment:
   fix NPE, thank's viewed

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] vinothchandar merged pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
vinothchandar merged pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
OpenOpened commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r365227085
 
 

 ##########
 File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/TestTimestampBasedKeyGenerator.java
 ##########
 @@ -0,0 +1,80 @@
+/*
+ * 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.hudi.utilities;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.hudi.DataSourceWriteOptions;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.common.util.TypedProperties;
+import org.apache.hudi.utilities.keygen.TimestampBasedKeyGenerator;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestTimestampBasedKeyGenerator {
+  private Schema schema = SchemaTestUtil.getTimestampEvolvedSchema();
+  private GenericRecord baseRecord = null;
+
+  public TestTimestampBasedKeyGenerator() throws IOException {
+  }
+
+  @Before
+  public void initialize() throws IOException {
+    baseRecord = SchemaTestUtil
+        .generateAvroRecordFromJson(schema, 1, "001", "f1");
+  }
+
+  private TypedProperties getBaseKeyConfig(String recordKeyFieldName, String partitionPathField, String hiveStylePartitioning) {
+    TypedProperties props = new TypedProperties();
+    props.setProperty(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY(), recordKeyFieldName);
+    props.setProperty(DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY(), partitionPathField);
+    props.setProperty(DataSourceWriteOptions.HIVE_STYLE_PARTITIONING_OPT_KEY(), hiveStylePartitioning);
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "EPOCHMILLISECONDS");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.output.dateformat", "yyyy-MM-dd hh");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    return props;
+  }
+
+  @Test
+  public void testTimestampBasedKeyGenerator() {
+    // if timezone is GMT+8:00
+    baseRecord.put("createTime", 1578283932000L);
+    TypedProperties props = getBaseKeyConfig("field1", "createTime", "false");
+    HoodieKey hk1 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk1.getPartitionPath(), "2020-01-06 12");
+
+    // if timezone is GMT
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT");
+    HoodieKey hk2 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk2.getPartitionPath(), "2020-01-06 04");
+
+    // if timestamp is DATE_STRING, and timestamp type is DATE_STRING
+    baseRecord.put("createTime", "2020-01-06 12:12:12");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "DATE_STRING");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.input.dateformat", "yyyy-MM-dd hh:mm:ss");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    HoodieKey hk3 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk3.getPartitionPath(), "2020-01-06 12");
+  }
+}
 
 Review comment:
   Is that right? This is the web address: [](https://gist.github.com/OpenOpened/2b50b86f21c36f3e07c78cb44d97ec9c)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] leesf commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
leesf commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r365178140
 
 

 ##########
 File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/TestTimestampBasedKeyGenerator.java
 ##########
 @@ -0,0 +1,80 @@
+/*
+ * 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.hudi.utilities;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.hudi.DataSourceWriteOptions;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.common.util.TypedProperties;
+import org.apache.hudi.utilities.keygen.TimestampBasedKeyGenerator;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestTimestampBasedKeyGenerator {
+  private Schema schema = SchemaTestUtil.getTimestampEvolvedSchema();
+  private GenericRecord baseRecord = null;
+
+  public TestTimestampBasedKeyGenerator() throws IOException {
+  }
+
+  @Before
+  public void initialize() throws IOException {
+    baseRecord = SchemaTestUtil
+        .generateAvroRecordFromJson(schema, 1, "001", "f1");
+  }
+
+  private TypedProperties getBaseKeyConfig(String recordKeyFieldName, String partitionPathField, String hiveStylePartitioning) {
+    TypedProperties props = new TypedProperties();
+    props.setProperty(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY(), recordKeyFieldName);
+    props.setProperty(DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY(), partitionPathField);
+    props.setProperty(DataSourceWriteOptions.HIVE_STYLE_PARTITIONING_OPT_KEY(), hiveStylePartitioning);
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "EPOCHMILLISECONDS");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.output.dateformat", "yyyy-MM-dd hh");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    return props;
+  }
+
+  @Test
+  public void testTimestampBasedKeyGenerator() {
+    // if timezone is GMT+8:00
+    baseRecord.put("createTime", 1578283932000L);
+    TypedProperties props = getBaseKeyConfig("field1", "createTime", "false");
+    HoodieKey hk1 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk1.getPartitionPath(), "2020-01-06 12");
+
+    // if timezone is GMT
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT");
+    HoodieKey hk2 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk2.getPartitionPath(), "2020-01-06 04");
+
+    // if timestamp is DATE_STRING, and timestamp type is DATE_STRING
+    baseRecord.put("createTime", "2020-01-06 12:12:12");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timestamp.type", "DATE_STRING");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.input.dateformat", "yyyy-MM-dd hh:mm:ss");
+    props.setProperty("hoodie.deltastreamer.keygen.timebased.timezone", "GMT+8:00");
+    HoodieKey hk3 = new TimestampBasedKeyGenerator(props).getKey(baseRecord);
+    assertEquals(hk3.getPartitionPath(), "2020-01-06 12");
+  }
+}
 
 Review comment:
   click the gist above.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] vinothchandar commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator

Posted by GitBox <gi...@apache.org>.
vinothchandar commented on a change in pull request #1188: [HUDI-502] provide a custom time zone definition for TimestampBasedKeyGenerator
URL: https://github.com/apache/incubator-hudi/pull/1188#discussion_r363486940
 
 

 ##########
 File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/TimestampBasedKeyGenerator.java
 ##########
 @@ -51,6 +51,8 @@
 
   private final String outputDateFormat;
 
+  private TimeZone timeZone;
 
 Review comment:
   any reason why this is not `final` too?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services