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 2021/10/28 06:57:43 UTC
[GitHub] [hudi] manojpec opened a new pull request #3884: [HUDI-1295] Hash ID generator util for Hudi table columns, partition and files
manojpec opened a new pull request #3884:
URL: https://github.com/apache/hudi/pull/3884
## What is the purpose of the pull request
Metadata Index feature needs to uniquely identify Hudi table column, partition
and files from their names. Need an utility to generate unique hash ids for any
given string or byte array messages
## Brief change log
- Adding a new utility class HashID to generate 32,64,128 bits hashes for any
given message of string or byte array type. This class internally uses
MessageDigest and xxhash libraries.
- Adding stateful hash holders for Hudi table columns, partition and files to
pass around for metaindex and to convert to base64encoded strings whenever
needed
## Verify this pull request
*(Please pick either of the following options)*
This pull request is a trivial rework / code cleanup without any test coverage.
*(or)*
This pull request is already covered by existing tests, such as *(please describe tests)*.
(or)
This change added tests and can be verified as follows:
*(example:)*
- *Added integration tests for end-to-end.*
- *Added HoodieClientWriteTest to verify the change.*
- *Manually verified the change by running a job locally.*
## 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.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [hudi] nsivabalan merged pull request #3884: [HUDI-1295] Hash ID generator util for Hudi table columns, partition and files
Posted by GitBox <gi...@apache.org>.
nsivabalan merged pull request #3884:
URL: https://github.com/apache/hudi/pull/3884
--
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.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [hudi] nsivabalan commented on pull request #3884: [HUDI-1295] Hash ID generator util for Hudi table columns, partition and files
Posted by GitBox <gi...@apache.org>.
nsivabalan commented on pull request #3884:
URL: https://github.com/apache/hudi/pull/3884#issuecomment-958925548
@manojpec : for sub-tasks, may be you can create a new jira rather than referring to large one. for eg, instead of HUDI-1295, we could have created another sub-task. something to keep in mind for future.
--
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.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [hudi] hudi-bot edited a comment on pull request #3884: [HUDI-1295] Hash ID generator util for Hudi table columns, partition and files
Posted by GitBox <gi...@apache.org>.
hudi-bot edited a comment on pull request #3884:
URL: https://github.com/apache/hudi/pull/3884#issuecomment-953575134
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "86d4ccec652fd8dace97339c62beed33db526b15",
"status" : "FAILURE",
"url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=2930",
"triggerID" : "86d4ccec652fd8dace97339c62beed33db526b15",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 86d4ccec652fd8dace97339c62beed33db526b15 Azure: [FAILURE](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=2930)
<details>
<summary>Bot commands</summary>
@hudi-bot supports the following commands:
- `@hudi-bot run travis` re-run the last Travis build
- `@hudi-bot run azure` re-run the last Azure build
</details>
--
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.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [hudi] hudi-bot edited a comment on pull request #3884: [HUDI-1295] Hash ID generator util for Hudi table columns, partition and files
Posted by GitBox <gi...@apache.org>.
hudi-bot edited a comment on pull request #3884:
URL: https://github.com/apache/hudi/pull/3884#issuecomment-953575134
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "86d4ccec652fd8dace97339c62beed33db526b15",
"status" : "DELETED",
"url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=2930",
"triggerID" : "86d4ccec652fd8dace97339c62beed33db526b15",
"triggerType" : "PUSH"
}, {
"hash" : "842f6deba90c7b17863a02c04227e436b9f12ef1",
"status" : "SUCCESS",
"url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=2942",
"triggerID" : "842f6deba90c7b17863a02c04227e436b9f12ef1",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 842f6deba90c7b17863a02c04227e436b9f12ef1 Azure: [SUCCESS](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=2942)
<details>
<summary>Bot commands</summary>
@hudi-bot supports the following commands:
- `@hudi-bot run travis` re-run the last Travis build
- `@hudi-bot run azure` re-run the last Azure build
</details>
--
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.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [hudi] hudi-bot edited a comment on pull request #3884: [HUDI-1295] Hash ID generator util for Hudi table columns, partition and files
Posted by GitBox <gi...@apache.org>.
hudi-bot edited a comment on pull request #3884:
URL: https://github.com/apache/hudi/pull/3884#issuecomment-953575134
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "86d4ccec652fd8dace97339c62beed33db526b15",
"status" : "FAILURE",
"url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=2930",
"triggerID" : "86d4ccec652fd8dace97339c62beed33db526b15",
"triggerType" : "PUSH"
}, {
"hash" : "842f6deba90c7b17863a02c04227e436b9f12ef1",
"status" : "PENDING",
"url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=2942",
"triggerID" : "842f6deba90c7b17863a02c04227e436b9f12ef1",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 86d4ccec652fd8dace97339c62beed33db526b15 Azure: [FAILURE](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=2930)
* 842f6deba90c7b17863a02c04227e436b9f12ef1 Azure: [PENDING](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=2942)
<details>
<summary>Bot commands</summary>
@hudi-bot supports the following commands:
- `@hudi-bot run travis` re-run the last Travis build
- `@hudi-bot run azure` re-run the last Azure build
</details>
--
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.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [hudi] nsivabalan commented on pull request #3884: [HUDI-1295] Hash ID generator util for Hudi table columns, partition and files
Posted by GitBox <gi...@apache.org>.
nsivabalan commented on pull request #3884:
URL: https://github.com/apache/hudi/pull/3884#issuecomment-958925548
--
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.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [hudi] hudi-bot edited a comment on pull request #3884: [HUDI-1295] Hash ID generator util for Hudi table columns, partition and files
Posted by GitBox <gi...@apache.org>.
hudi-bot edited a comment on pull request #3884:
URL: https://github.com/apache/hudi/pull/3884#issuecomment-953575134
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "86d4ccec652fd8dace97339c62beed33db526b15",
"status" : "FAILURE",
"url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=2930",
"triggerID" : "86d4ccec652fd8dace97339c62beed33db526b15",
"triggerType" : "PUSH"
}, {
"hash" : "842f6deba90c7b17863a02c04227e436b9f12ef1",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "842f6deba90c7b17863a02c04227e436b9f12ef1",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 86d4ccec652fd8dace97339c62beed33db526b15 Azure: [FAILURE](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=2930)
* 842f6deba90c7b17863a02c04227e436b9f12ef1 UNKNOWN
<details>
<summary>Bot commands</summary>
@hudi-bot supports the following commands:
- `@hudi-bot run travis` re-run the last Travis build
- `@hudi-bot run azure` re-run the last Azure build
</details>
--
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.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [hudi] manojpec commented on a change in pull request #3884: [HUDI-1295] Hash ID generator util for Hudi table columns, partition and files
Posted by GitBox <gi...@apache.org>.
manojpec commented on a change in pull request #3884:
URL: https://github.com/apache/hudi/pull/3884#discussion_r739498221
##########
File path: hudi-common/src/main/java/org/apache/hudi/common/util/hash/HashID.java
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.common.util.hash;
+
+import net.jpountz.xxhash.XXHash32;
+import net.jpountz.xxhash.XXHash64;
+import net.jpountz.xxhash.XXHashFactory;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hudi.exception.HoodieIOException;
+
+import java.io.Serializable;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * A stateless Hash class which generates ID for the desired bit count.
+ */
+public class HashID implements Serializable {
+
+ private static final String MD5_ALGORITHM_NAME = "MD5";
+ private static final int HASH_SEED = 0xdabadaba;
+
+ /**
+ * Represents HashID size in bits.
+ */
+ public enum Size {
+ BITS_32(32),
+ BITS_64(64),
+ BITS_128(128);
+
+ private final int bits;
+
+ Size(int bitCount) {
+ this.bits = bitCount;
+ }
+
+ /**
+ * Get this Hash size in bytes.
+ *
+ * @return Bytes needed to represent this size
+ */
+ public int byteSize() {
+ return (((this.bits - 1) / Byte.SIZE) + 1);
+ }
+
+ /**
+ * Get this Hash size in bits.
+ *
+ * @return bits needed to represent the size
+ */
+ public int bits() {
+ return this.bits;
+ }
+
+ @Override
+ public String toString() {
+ return "HashSize{" + bits + "}";
+ }
+ }
+
+ /**
+ * Get the hash value for a string message and for the desired @{@link Size}.
+ *
+ * @param message - String message to get the hash value for
+ * @param bits - @{@link Size} of the hash value
+ * @return Hash value for the message as byte array
+ */
+ public static byte[] hash(final String message, final Size bits) {
+ return hash(message.getBytes(StandardCharsets.UTF_8), bits);
+ }
+
+ /**
+ * Get the hash value for a byte array and for the desired @{@link Size}.
+ *
+ * @param messageBytes - Byte array message to get the hash value for
+ * @param bits - @{@link Size} of the hash value
+ * @return Hash value for the message as byte array
+ */
+ public static byte[] hash(final byte[] messageBytes, final Size bits) {
+ switch (bits) {
+ case BITS_32:
+ case BITS_64:
+ return getXXHash(messageBytes, bits);
+ case BITS_128:
+ return getMD5Hash(messageBytes);
+ default:
+ throw new IllegalArgumentException("Unexpected Hash size bits: " + bits);
+ }
+ }
+
+ private static byte[] getXXHash(final byte[] message, final Size bits) {
+ XXHashFactory factory = XXHashFactory.fastestInstance();
Review comment:
I would like HashID to be a stateless class only expose static methods. Theres actually no state need to be maintained as this is pretty light weight instantiation. The seed is the only thing which makes the hash generation deterministic across time and platforms. I can do static instantiation of factory if this is really needed.
--
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.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [hudi] hudi-bot edited a comment on pull request #3884: [HUDI-1295] Hash ID generator util for Hudi table columns, partition and files
Posted by GitBox <gi...@apache.org>.
hudi-bot edited a comment on pull request #3884:
URL: https://github.com/apache/hudi/pull/3884#issuecomment-953575134
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "86d4ccec652fd8dace97339c62beed33db526b15",
"status" : "PENDING",
"url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=2930",
"triggerID" : "86d4ccec652fd8dace97339c62beed33db526b15",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 86d4ccec652fd8dace97339c62beed33db526b15 Azure: [PENDING](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=2930)
<details>
<summary>Bot commands</summary>
@hudi-bot supports the following commands:
- `@hudi-bot run travis` re-run the last Travis build
- `@hudi-bot run azure` re-run the last Azure build
</details>
--
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.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [hudi] hudi-bot commented on pull request #3884: [HUDI-1295] Hash ID generator util for Hudi table columns, partition and files
Posted by GitBox <gi...@apache.org>.
hudi-bot commented on pull request #3884:
URL: https://github.com/apache/hudi/pull/3884#issuecomment-953575134
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "86d4ccec652fd8dace97339c62beed33db526b15",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "86d4ccec652fd8dace97339c62beed33db526b15",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 86d4ccec652fd8dace97339c62beed33db526b15 UNKNOWN
<details>
<summary>Bot commands</summary>
@hudi-bot supports the following commands:
- `@hudi-bot run travis` re-run the last Travis build
- `@hudi-bot run azure` re-run the last Azure build
</details>
--
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.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [hudi] nsivabalan commented on a change in pull request #3884: [HUDI-1295] Hash ID generator util for Hudi table columns, partition and files
Posted by GitBox <gi...@apache.org>.
nsivabalan commented on a change in pull request #3884:
URL: https://github.com/apache/hudi/pull/3884#discussion_r739487446
##########
File path: hudi-common/src/main/java/org/apache/hudi/common/util/hash/HashID.java
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.common.util.hash;
+
+import net.jpountz.xxhash.XXHash32;
+import net.jpountz.xxhash.XXHash64;
+import net.jpountz.xxhash.XXHashFactory;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hudi.exception.HoodieIOException;
+
+import java.io.Serializable;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * A stateless Hash class which generates ID for the desired bit count.
+ */
+public class HashID implements Serializable {
+
+ private static final String MD5_ALGORITHM_NAME = "MD5";
+ private static final int HASH_SEED = 0xdabadaba;
+
+ /**
+ * Represents HashID size in bits.
+ */
+ public enum Size {
+ BITS_32(32),
+ BITS_64(64),
+ BITS_128(128);
+
+ private final int bits;
+
+ Size(int bitCount) {
+ this.bits = bitCount;
+ }
+
+ /**
+ * Get this Hash size in bytes.
+ *
+ * @return Bytes needed to represent this size
+ */
+ public int byteSize() {
+ return (((this.bits - 1) / Byte.SIZE) + 1);
+ }
+
+ /**
+ * Get this Hash size in bits.
+ *
+ * @return bits needed to represent the size
+ */
+ public int bits() {
+ return this.bits;
+ }
+
+ @Override
+ public String toString() {
+ return "HashSize{" + bits + "}";
+ }
+ }
+
+ /**
+ * Get the hash value for a string message and for the desired @{@link Size}.
+ *
+ * @param message - String message to get the hash value for
+ * @param bits - @{@link Size} of the hash value
+ * @return Hash value for the message as byte array
+ */
+ public static byte[] hash(final String message, final Size bits) {
+ return hash(message.getBytes(StandardCharsets.UTF_8), bits);
+ }
+
+ /**
+ * Get the hash value for a byte array and for the desired @{@link Size}.
+ *
+ * @param messageBytes - Byte array message to get the hash value for
+ * @param bits - @{@link Size} of the hash value
+ * @return Hash value for the message as byte array
+ */
+ public static byte[] hash(final byte[] messageBytes, final Size bits) {
+ switch (bits) {
+ case BITS_32:
+ case BITS_64:
+ return getXXHash(messageBytes, bits);
+ case BITS_128:
+ return getMD5Hash(messageBytes);
+ default:
+ throw new IllegalArgumentException("Unexpected Hash size bits: " + bits);
+ }
+ }
+
+ private static byte[] getXXHash(final byte[] message, final Size bits) {
+ XXHashFactory factory = XXHashFactory.fastestInstance();
Review comment:
should we instantiate factory once in the constructor and re-use for any no of hash generations?
--
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.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [hudi] nsivabalan commented on pull request #3884: [HUDI-1295] Hash ID generator util for Hudi table columns, partition and files
Posted by GitBox <gi...@apache.org>.
nsivabalan commented on pull request #3884:
URL: https://github.com/apache/hudi/pull/3884#issuecomment-958925548
@manojpec : for sub-tasks, may be you can create a new jira rather than referring to large one. for eg, instead of HUDI-1295, we could have created another sub-task. something to keep in mind for future.
--
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.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org