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/06/17 13:54:39 UTC

[GitHub] [hudi] wangxianghu opened a new pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

wangxianghu opened a new pull request #1744:
URL: https://github.com/apache/hudi/pull/1744


   …mestamp-based complex key
   
   ## *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
   
   *Introduce TimestampBasedComplexKeyGenerator to support timestamp-based complex key*
   
   ## Brief change log
   
     - *Add TimestampBasedComplexKeyGenerator*
     - *Add KeyGeneratorTimestampConfig*
     - *Add TimestampTypeEnum*
     - *Add KeyGeneratorTimestampUtil*
     - *Add TestTimestampBasedComplexKeyGenerator*
     - *Modify ComplexKeyGenerator
     - *Modify TimestampBasedKeyGenerator*
     - *Modify TestTimestampBasedKeyGenerator*
   
   ## Verify this pull request
   
   This change added tests and can be verified as follows:
   
   TestTimestampBasedKeyGenerator#testTimestampBasedKeyGenerator
   TestTimestampBasedComplexKeyGenerator#testTimestampBasedComplexKeyGenerator
   
   ## Committer checklist
   
    - [ ] Has a corresponding JIRA in PR title & commit
    
    - [ ] Commit message is descriptive of the change
    
    - [ ] CI is green
   
    - [ ] Necessary doc changes done or have another open PR
          
    - [ ] For large changes, please consider breaking it into sub-tasks under an umbrella JIRA.


----------------------------------------------------------------
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



[GitHub] [hudi] wangxianghu commented on a change in pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on a change in pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#discussion_r443088900



##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/common/TimestampTypeEnum.java
##########
@@ -0,0 +1,28 @@
+/*
+ * 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.keygen.common;
+
+import java.io.Serializable;
+
+/**
+ * TimestampType enum.

Review comment:
       I'll give a detailed description




----------------------------------------------------------------
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



[GitHub] [hudi] wangxianghu closed pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
wangxianghu closed pull request #1744:
URL: https://github.com/apache/hudi/pull/1744


   


----------------------------------------------------------------
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



[GitHub] [hudi] wangxianghu commented on a change in pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on a change in pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#discussion_r443088789



##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/util/TimestampBasedKeyGeneratorHelper.java
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.keygen.util;
+
+import org.apache.hudi.DataSourceUtils;
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.exception.HoodieNotSupportedException;
+import org.apache.hudi.utilities.keygen.common.KeyGeneratorTimestampConfig;
+import org.apache.hudi.utilities.keygen.common.TimestampTypeEnum;
+
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.TimeZone;
+import java.util.concurrent.TimeUnit;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+/**
+ * Util helps to build TimestampBasedKeyGenerator.
+ */
+public class TimestampBasedKeyGeneratorHelper {

Review comment:
       `TimestampProcessor` seems better




----------------------------------------------------------------
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



[GitHub] [hudi] wangxianghu commented on pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#issuecomment-646933340


   hi @yanghua, thanks for your detailed review, I have addressed all your concerns, PTAL when free.


----------------------------------------------------------------
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



[GitHub] [hudi] wangxianghu commented on a change in pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on a change in pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#discussion_r443088843



##########
File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/keygen/TestTimestampBasedKeyGenerator.java
##########
@@ -63,24 +66,24 @@ private TypedProperties getBaseKeyConfig(String timestampType, String dateFormat
   public void testTimestampBasedKeyGenerator() {
     // timezone is GMT+8:00
     baseRecord.put("createTime", 1578283932000L);
-    properties = getBaseKeyConfig("EPOCHMILLISECONDS", "yyyy-MM-dd hh", "GMT+8:00", null);
+    properties = getBaseKeyConfig("EPOCHMILLISECONDS", "yyyy-MM-dd HH", "GMT+8:00", null);
     HoodieKey hk1 = new TimestampBasedKeyGenerator(properties).getKey(baseRecord);
     assertEquals("2020-01-06 12", hk1.getPartitionPath());
 
     // timezone is GMT
-    properties = getBaseKeyConfig("EPOCHMILLISECONDS", "yyyy-MM-dd hh", "GMT", null);
+    properties = getBaseKeyConfig("EPOCHMILLISECONDS", "yyyy-MM-dd HH", "GMT", null);
     HoodieKey hk2 = new TimestampBasedKeyGenerator(properties).getKey(baseRecord);
     assertEquals("2020-01-06 04", hk2.getPartitionPath());
 
     // timestamp is DATE_STRING, timezone is GMT+8:00
     baseRecord.put("createTime", "2020-01-06 12:12:12");
-    properties = getBaseKeyConfig("DATE_STRING", "yyyy-MM-dd hh", "GMT+8:00", null);
-    properties.setProperty("hoodie.deltastreamer.keygen.timebased.input.dateformat", "yyyy-MM-dd hh:mm:ss");
+    properties = getBaseKeyConfig("DATE_STRING", "yyyy-MM-dd HH", "GMT+8:00", null);

Review comment:
       sure




----------------------------------------------------------------
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



[GitHub] [hudi] wangxianghu commented on a change in pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on a change in pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#discussion_r443088652



##########
File path: hudi-spark/src/main/java/org/apache/hudi/keygen/ComplexKeyGenerator.java
##########
@@ -49,11 +49,11 @@
 
   public ComplexKeyGenerator(TypedProperties props) {
     super(props);
-    this.recordKeyFields = Arrays.asList(props.getString(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY()).split(","))
-            .stream().map(String::trim).collect(Collectors.toList());
+    this.recordKeyFields = Arrays.stream(props.getString(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY())

Review comment:
       sure




----------------------------------------------------------------
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



[GitHub] [hudi] wangxianghu commented on a change in pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on a change in pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#discussion_r443098352



##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/TimestampBasedComplexKeyGenerator.java
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.keygen;
+
+import org.apache.hudi.DataSourceUtils;
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.exception.HoodieKeyException;
+import org.apache.hudi.keygen.ComplexKeyGenerator;
+import org.apache.hudi.utilities.keygen.util.TimestampBasedKeyGeneratorHelper;
+
+import org.apache.avro.generic.GenericRecord;
+
+/**
+ * ComplexKey generator, which takes names of fields to be used for recordKey and relies on timestamps for

Review comment:
       done




----------------------------------------------------------------
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



[GitHub] [hudi] yanghua commented on a change in pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
yanghua commented on a change in pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#discussion_r442705842



##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/TimestampBasedComplexKeyGenerator.java
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.keygen;
+
+import org.apache.hudi.DataSourceUtils;
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.exception.HoodieKeyException;
+import org.apache.hudi.keygen.ComplexKeyGenerator;
+import org.apache.hudi.utilities.exception.HoodieDeltaStreamerException;
+import org.apache.hudi.utilities.keygen.common.KeyGeneratorTimestampConfig;
+import org.apache.hudi.utilities.keygen.common.TimestampTypeEnum;
+import org.apache.hudi.utilities.keygen.util.KeyGeneratorTimestampUtil;
+
+import org.apache.avro.generic.GenericRecord;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.concurrent.TimeUnit;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+/**
+ * Key generator, that relies on timestamps for partitioning field. Still picks record key by name.

Review comment:
       We should mark it to be `Complex Key generator` and add more description about its usage scenario. WDYT?

##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/TimestampBasedComplexKeyGenerator.java
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.keygen;
+
+import org.apache.hudi.DataSourceUtils;
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.exception.HoodieKeyException;
+import org.apache.hudi.keygen.ComplexKeyGenerator;
+import org.apache.hudi.utilities.exception.HoodieDeltaStreamerException;
+import org.apache.hudi.utilities.keygen.common.KeyGeneratorTimestampConfig;
+import org.apache.hudi.utilities.keygen.common.TimestampTypeEnum;
+import org.apache.hudi.utilities.keygen.util.KeyGeneratorTimestampUtil;
+
+import org.apache.avro.generic.GenericRecord;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.concurrent.TimeUnit;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+/**
+ * Key generator, that relies on timestamps for partitioning field. Still picks record key by name.
+ */
+public class TimestampBasedComplexKeyGenerator extends ComplexKeyGenerator {

Review comment:
       IMO, the `TimestampBasedKeyGenerator` and `TimestampBasedComplexKeyGenerator` have the similar business logic(both in constructor and timestamp parse). Can we extract them with an abstract class so that we can reduce some unnecessary code?




----------------------------------------------------------------
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



[GitHub] [hudi] wangxianghu commented on a change in pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on a change in pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#discussion_r442913719



##########
File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/keygen/TestTimestampBasedKeyGenerator.java
##########
@@ -91,8 +94,9 @@ public void testScalar() {
     baseRecord.put("createTime", 20000L);
 
     // timezone is GMT
-    properties = getBaseKeyConfig("SCALAR", "yyyy-MM-dd hh", "GMT", "days");
+    properties = getBaseKeyConfig("SCALAR", "yyyy-MM-dd HH", "GMT", "days");
     HoodieKey hk5 = new TimestampBasedKeyGenerator(properties).getKey(baseRecord);
-    assertEquals(hk5.getPartitionPath(), "2024-10-04 12");
+    assertEquals(hk5.getPartitionPath(), "2024-10-04 00");

Review comment:
       Hi @afilipchik, would you please help me out here, I am not kind of familiar with SCALAR time.
   My unit test shows that the actual `partitionPath` is "2024-10-04 00", while yours are "2024-10-04 12" 
   thanks :)




----------------------------------------------------------------
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



[GitHub] [hudi] wangxianghu commented on a change in pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on a change in pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#discussion_r443098129



##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/common/TimestampTypeEnum.java
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.keygen.common;
+
+import java.io.Serializable;
+
+/**
+ * Timestamp type enum, currently only five types are supported.
+ */
+public enum TimestampTypeEnum implements Serializable {
+
+  /**
+   * Timestamp of the long type with length 10, such as 1592616630.
+   */
+  UNIX_TIMESTAMP,
+
+  /**
+   * Timestamp of string type, whose format is depended on config, see
+   * {@link KeyGeneratorTimestampConfig#TIMESTAMP_INPUT_DATE_FORMAT_PROP}.
+   */
+  DATE_STRING,
+
+  /**
+   * A special type of {@link TimestampTypeEnum#DATE_STRING}, this aims to be compatible with more string date formats,
+   * but with the expense of time accuracy.
+   * <p>
+   * when the timestamp type is set to MIXED, it means the input value is of
+   * {@link TimestampTypeEnum#DATE_STRING} type, but might have several different string formats.
+   * For example. If the timestamp type is set to MIXED, and {@link TimestampTypeEnum#DATE_STRING} set to "yyyy-MM-dd",
+   * then the KeyGenerator could take in timestamp with "yyyy-MM-dd", "yyyy-MM-dd HH","yyyy-MM-dd HH:mm:ss" format,
+   * but the parsed result will lose some accuracy, in "yyyy-MM-dd" format only.
+   */
+  MIXED,

Review comment:
       Hi @vinothchandar, I need your help here, I am not sure IIUC, please take a look when free :)




----------------------------------------------------------------
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



[GitHub] [hudi] wangxianghu commented on a change in pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on a change in pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#discussion_r442913719



##########
File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/keygen/TestTimestampBasedKeyGenerator.java
##########
@@ -91,8 +94,9 @@ public void testScalar() {
     baseRecord.put("createTime", 20000L);
 
     // timezone is GMT
-    properties = getBaseKeyConfig("SCALAR", "yyyy-MM-dd hh", "GMT", "days");
+    properties = getBaseKeyConfig("SCALAR", "yyyy-MM-dd HH", "GMT", "days");
     HoodieKey hk5 = new TimestampBasedKeyGenerator(properties).getKey(baseRecord);
-    assertEquals(hk5.getPartitionPath(), "2024-10-04 12");
+    assertEquals(hk5.getPartitionPath(), "2024-10-04 00");

Review comment:
       Hi @afilipchik, would you please help me out here, I am not kind of familiar with SCALAR time.
   My unit test shows that the actual `partitionPath` is "2024-10-04 00", while yours are "2024-10-04 12" 
   thanks :)




----------------------------------------------------------------
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



[GitHub] [hudi] wangxianghu commented on pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#issuecomment-646707364


   Hi @yanghua, I have addressed all your concerns, PTAL when you get a chance.


----------------------------------------------------------------
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



[GitHub] [hudi] wangxianghu commented on pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#issuecomment-647213962


   This feature has been taken care of by  https://github.com/apache/hudi/pull/1433, closing now.


----------------------------------------------------------------
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



[GitHub] [hudi] wangxianghu commented on pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#issuecomment-645404822


   @yanghua please take a look when free :)


----------------------------------------------------------------
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



[GitHub] [hudi] wangxianghu commented on a change in pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on a change in pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#discussion_r443098129



##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/common/TimestampTypeEnum.java
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.keygen.common;
+
+import java.io.Serializable;
+
+/**
+ * Timestamp type enum, currently only five types are supported.
+ */
+public enum TimestampTypeEnum implements Serializable {
+
+  /**
+   * Timestamp of the long type with length 10, such as 1592616630.
+   */
+  UNIX_TIMESTAMP,
+
+  /**
+   * Timestamp of string type, whose format is depended on config, see
+   * {@link KeyGeneratorTimestampConfig#TIMESTAMP_INPUT_DATE_FORMAT_PROP}.
+   */
+  DATE_STRING,
+
+  /**
+   * A special type of {@link TimestampTypeEnum#DATE_STRING}, this aims to be compatible with more string date formats,
+   * but with the expense of time accuracy.
+   * <p>
+   * when the timestamp type is set to MIXED, it means the input value is of
+   * {@link TimestampTypeEnum#DATE_STRING} type, but might have several different string formats.
+   * For example. If the timestamp type is set to MIXED, and {@link TimestampTypeEnum#DATE_STRING} set to "yyyy-MM-dd",
+   * then the KeyGenerator could take in timestamp with "yyyy-MM-dd", "yyyy-MM-dd HH","yyyy-MM-dd HH:mm:ss" format,
+   * but the parsed result will lose some accuracy, in "yyyy-MM-dd" format only.
+   */
+  MIXED,

Review comment:
       Hi @vinothchandar, I need your help here, I am not sure IIUC, please take a look when free :)




----------------------------------------------------------------
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



[GitHub] [hudi] codecov-commenter commented on pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#issuecomment-645436576


   # [Codecov](https://codecov.io/gh/apache/hudi/pull/1744?src=pr&el=h1) Report
   > Merging [#1744](https://codecov.io/gh/apache/hudi/pull/1744?src=pr&el=desc) into [master](https://codecov.io/gh/apache/hudi/commit/2a04647f5e7b33e7a4d658b1258d21cc947b6f94&el=desc) will **increase** coverage by `0.01%`.
   > The diff coverage is `0.00%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/hudi/pull/1744/graphs/tree.svg?width=650&height=150&src=pr&token=VTTXabwbs2)](https://codecov.io/gh/apache/hudi/pull/1744?src=pr&el=tree)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #1744      +/-   ##
   ============================================
   + Coverage     18.14%   18.15%   +0.01%     
   - Complexity      859      860       +1     
   ============================================
     Files           352      352              
     Lines         15414    15416       +2     
     Branches       1526     1526              
   ============================================
   + Hits           2797     2799       +2     
     Misses        12259    12259              
     Partials        358      358              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/hudi/pull/1744?src=pr&el=tree) | Coverage Δ | Complexity Δ | |
   |---|---|---|---|
   | [...va/org/apache/hudi/keygen/ComplexKeyGenerator.java](https://codecov.io/gh/apache/hudi/pull/1744/diff?src=pr&el=tree#diff-aHVkaS1zcGFyay9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaHVkaS9rZXlnZW4vQ29tcGxleEtleUdlbmVyYXRvci5qYXZh) | `0.00% <0.00%> (ø)` | `0.00 <0.00> (ø)` | |
   | [...apache/hudi/common/fs/HoodieWrapperFileSystem.java](https://codecov.io/gh/apache/hudi/pull/1744/diff?src=pr&el=tree#diff-aHVkaS1jb21tb24vc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1ZGkvY29tbW9uL2ZzL0hvb2RpZVdyYXBwZXJGaWxlU3lzdGVtLmphdmE=) | `22.69% <0.00%> (+0.70%)` | `29.00% <0.00%> (+1.00%)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/hudi/pull/1744?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/hudi/pull/1744?src=pr&el=footer). Last update [2a04647...a6e2a50](https://codecov.io/gh/apache/hudi/pull/1744?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


----------------------------------------------------------------
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



[GitHub] [hudi] wangxianghu commented on a change in pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on a change in pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#discussion_r442717930



##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/TimestampBasedComplexKeyGenerator.java
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.keygen;
+
+import org.apache.hudi.DataSourceUtils;
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.exception.HoodieKeyException;
+import org.apache.hudi.keygen.ComplexKeyGenerator;
+import org.apache.hudi.utilities.exception.HoodieDeltaStreamerException;
+import org.apache.hudi.utilities.keygen.common.KeyGeneratorTimestampConfig;
+import org.apache.hudi.utilities.keygen.common.TimestampTypeEnum;
+import org.apache.hudi.utilities.keygen.util.KeyGeneratorTimestampUtil;
+
+import org.apache.avro.generic.GenericRecord;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.concurrent.TimeUnit;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+/**
+ * Key generator, that relies on timestamps for partitioning field. Still picks record key by name.

Review comment:
       @yanghua yes,  It make sense




----------------------------------------------------------------
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



[GitHub] [hudi] wangxianghu commented on a change in pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on a change in pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#discussion_r442720534



##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/TimestampBasedComplexKeyGenerator.java
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.keygen;
+
+import org.apache.hudi.DataSourceUtils;
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.exception.HoodieKeyException;
+import org.apache.hudi.keygen.ComplexKeyGenerator;
+import org.apache.hudi.utilities.exception.HoodieDeltaStreamerException;
+import org.apache.hudi.utilities.keygen.common.KeyGeneratorTimestampConfig;
+import org.apache.hudi.utilities.keygen.common.TimestampTypeEnum;
+import org.apache.hudi.utilities.keygen.util.KeyGeneratorTimestampUtil;
+
+import org.apache.avro.generic.GenericRecord;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.concurrent.TimeUnit;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+/**
+ * Key generator, that relies on timestamps for partitioning field. Still picks record key by name.
+ */
+public class TimestampBasedComplexKeyGenerator extends ComplexKeyGenerator {

Review comment:
       @yanghua that's a good suggestion, but a little diffcult. because `TimestampBasedComplexKeyGenerator `has already extends `ComplexKeygenerator`, I'll see what I can do to reuse more code.
   thanks for your review 




----------------------------------------------------------------
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



[GitHub] [hudi] wangxianghu commented on a change in pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on a change in pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#discussion_r442913719



##########
File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/keygen/TestTimestampBasedKeyGenerator.java
##########
@@ -91,8 +94,9 @@ public void testScalar() {
     baseRecord.put("createTime", 20000L);
 
     // timezone is GMT
-    properties = getBaseKeyConfig("SCALAR", "yyyy-MM-dd hh", "GMT", "days");
+    properties = getBaseKeyConfig("SCALAR", "yyyy-MM-dd HH", "GMT", "days");
     HoodieKey hk5 = new TimestampBasedKeyGenerator(properties).getKey(baseRecord);
-    assertEquals(hk5.getPartitionPath(), "2024-10-04 12");
+    assertEquals(hk5.getPartitionPath(), "2024-10-04 00");

Review comment:
       Hi @afilipchik, would you please help me out here, I am not kind of familiar with SCALAR time.
   My unit test shows that the actual `partitionPath` is "2024-10-04 00", while yours are "2024-10-04 12" 




----------------------------------------------------------------
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



[GitHub] [hudi] yanghua commented on a change in pull request #1744: [HUDI-1027] Introduce TimestampBasedComplexKeyGenerator to support ti…

Posted by GitBox <gi...@apache.org>.
yanghua commented on a change in pull request #1744:
URL: https://github.com/apache/hudi/pull/1744#discussion_r443084118



##########
File path: hudi-spark/src/main/java/org/apache/hudi/keygen/ComplexKeyGenerator.java
##########
@@ -49,11 +49,11 @@
 
   public ComplexKeyGenerator(TypedProperties props) {
     super(props);
-    this.recordKeyFields = Arrays.asList(props.getString(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY()).split(","))
-            .stream().map(String::trim).collect(Collectors.toList());
+    this.recordKeyFields = Arrays.stream(props.getString(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY())

Review comment:
       These changes belong to the field of code cleanup. Based on the rule that one PR does one thing. It would be better to refactor it in a separate PR **next time**.

##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/TimestampBasedComplexKeyGenerator.java
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.keygen;
+
+import org.apache.hudi.DataSourceUtils;
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.exception.HoodieKeyException;
+import org.apache.hudi.keygen.ComplexKeyGenerator;
+import org.apache.hudi.utilities.keygen.util.TimestampBasedKeyGeneratorHelper;
+
+import org.apache.avro.generic.GenericRecord;
+
+/**
+ * ComplexKey generator, which takes names of fields to be used for recordKey and relies on timestamps for

Review comment:
       `ComplexKey` -> `Complex key `

##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/util/TimestampBasedKeyGeneratorHelper.java
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.keygen.util;
+
+import org.apache.hudi.DataSourceUtils;
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.exception.HoodieNotSupportedException;
+import org.apache.hudi.utilities.keygen.common.KeyGeneratorTimestampConfig;
+import org.apache.hudi.utilities.keygen.common.TimestampTypeEnum;
+
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.TimeZone;
+import java.util.concurrent.TimeUnit;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+/**
+ * Util helps to build TimestampBasedKeyGenerator.
+ */
+public class TimestampBasedKeyGeneratorHelper {

Review comment:
       I am thinking about the naming of this class. Generally speaking, if the name of a class has a suffix like `xxxHelper` or `xxxUtils` would only contain **static** method. What about renaming to `TimestampParser` or `TimestampProcessor` or something else?

##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/keygen/common/TimestampTypeEnum.java
##########
@@ -0,0 +1,28 @@
+/*
+ * 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.keygen.common;
+
+import java.io.Serializable;
+
+/**
+ * TimestampType enum.

Review comment:
       It could be more describable. For example, `The definition of all supported timestamp types.`(just an example).

##########
File path: hudi-utilities/src/test/java/org/apache/hudi/utilities/keygen/TestTimestampBasedKeyGenerator.java
##########
@@ -63,24 +66,24 @@ private TypedProperties getBaseKeyConfig(String timestampType, String dateFormat
   public void testTimestampBasedKeyGenerator() {
     // timezone is GMT+8:00
     baseRecord.put("createTime", 1578283932000L);
-    properties = getBaseKeyConfig("EPOCHMILLISECONDS", "yyyy-MM-dd hh", "GMT+8:00", null);
+    properties = getBaseKeyConfig("EPOCHMILLISECONDS", "yyyy-MM-dd HH", "GMT+8:00", null);
     HoodieKey hk1 = new TimestampBasedKeyGenerator(properties).getKey(baseRecord);
     assertEquals("2020-01-06 12", hk1.getPartitionPath());
 
     // timezone is GMT
-    properties = getBaseKeyConfig("EPOCHMILLISECONDS", "yyyy-MM-dd hh", "GMT", null);
+    properties = getBaseKeyConfig("EPOCHMILLISECONDS", "yyyy-MM-dd HH", "GMT", null);
     HoodieKey hk2 = new TimestampBasedKeyGenerator(properties).getKey(baseRecord);
     assertEquals("2020-01-06 04", hk2.getPartitionPath());
 
     // timestamp is DATE_STRING, timezone is GMT+8:00
     baseRecord.put("createTime", "2020-01-06 12:12:12");
-    properties = getBaseKeyConfig("DATE_STRING", "yyyy-MM-dd hh", "GMT+8:00", null);
-    properties.setProperty("hoodie.deltastreamer.keygen.timebased.input.dateformat", "yyyy-MM-dd hh:mm:ss");
+    properties = getBaseKeyConfig("DATE_STRING", "yyyy-MM-dd HH", "GMT+8:00", null);

Review comment:
       ditto, next time open another code cleanup PR for this work.




----------------------------------------------------------------
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