-
Notifications
You must be signed in to change notification settings - Fork 180
HBASE-30187 Port hbase-spark bulk load functionality to Spark 4 #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wchevreuil
merged 2 commits into
apache:master
from
Sigma-Ma:HBASE-30187-port-hbase-spark-bulk-load-to-spark4
Sep 11, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
spark4/hbase-spark4/src/main/scala/org/apache/hadoop/hbase/spark/BulkLoadPartitioner.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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.hadoop.hbase.spark | ||
|
|
||
| import java.util | ||
| import java.util.Comparator | ||
| import org.apache.hadoop.hbase.util.Bytes | ||
| import org.apache.spark.Partitioner | ||
| import org.apache.yetus.audience.InterfaceAudience | ||
|
|
||
| /** | ||
| * A Partitioner implementation that will separate records to different | ||
| * HBase Regions based on region splits | ||
| * | ||
| * @param startKeys The start keys for the given table | ||
| */ | ||
| @InterfaceAudience.Public | ||
| class BulkLoadPartitioner(startKeys: Array[Array[Byte]]) extends Partitioner { | ||
| @transient private lazy val comparator: Comparator[Array[Byte]] = | ||
| new Comparator[Array[Byte]] { | ||
| override def compare(o1: Array[Byte], o2: Array[Byte]): Int = { | ||
| Bytes.compareTo(o1, o2) | ||
| } | ||
| } | ||
|
|
||
| // when table not exist, startKeys = Byte[0][] | ||
| override def numPartitions: Int = if (startKeys.length == 0) 1 else startKeys.length | ||
|
|
||
| override def getPartition(key: Any): Int = { | ||
| val rowKey: Array[Byte] = | ||
| key match { | ||
| case qualifier: KeyFamilyQualifier => | ||
| qualifier.rowKey | ||
| case wrapper: ByteArrayWrapper => | ||
| wrapper.value | ||
| case _ => | ||
| key.asInstanceOf[Array[Byte]] | ||
| } | ||
| var partition = util.Arrays.binarySearch(startKeys, rowKey, comparator) | ||
| if (partition < 0) | ||
| partition = partition * -1 + -2 | ||
| if (partition < 0) | ||
| partition = 0 | ||
| partition | ||
| } | ||
| } | ||
48 changes: 48 additions & 0 deletions
48
spark4/hbase-spark4/src/main/scala/org/apache/hadoop/hbase/spark/ByteArrayWrapper.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * 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.hadoop.hbase.spark | ||
|
|
||
| import java.io.Serializable | ||
| import org.apache.hadoop.hbase.util.Bytes | ||
| import org.apache.yetus.audience.InterfaceAudience | ||
|
|
||
| /** | ||
| * This is a wrapper over a byte array so it can work as | ||
| * a key in a hashMap | ||
| * | ||
| * @param value The Byte Array value | ||
| */ | ||
| @InterfaceAudience.Public | ||
| class ByteArrayWrapper(var value: Array[Byte]) | ||
| extends Comparable[ByteArrayWrapper] | ||
| with Serializable { | ||
| override def compareTo(valueOther: ByteArrayWrapper): Int = { | ||
| Bytes.compareTo(value, valueOther.value) | ||
| } | ||
| override def equals(o2: Any): Boolean = { | ||
| o2 match { | ||
| case wrapper: ByteArrayWrapper => | ||
| Bytes.equals(value, wrapper.value) | ||
| case _ => | ||
| false | ||
| } | ||
| } | ||
| override def hashCode(): Int = { | ||
| Bytes.hashCode(value) | ||
| } | ||
| } |
67 changes: 67 additions & 0 deletions
67
.../hbase-spark4/src/main/scala/org/apache/hadoop/hbase/spark/FamiliesQualifiersValues.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * 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.hadoop.hbase.spark | ||
|
|
||
| import java.util | ||
| import org.apache.yetus.audience.InterfaceAudience | ||
|
|
||
| /** | ||
| * This object is a clean way to store and sort all cells that will be bulk | ||
| * loaded into a single row | ||
| */ | ||
| @InterfaceAudience.Public | ||
| class FamiliesQualifiersValues extends Serializable { | ||
| // Tree maps are used because we need the results to | ||
| // be sorted when we read them | ||
| val familyMap = new util.TreeMap[ByteArrayWrapper, util.TreeMap[ByteArrayWrapper, Array[Byte]]]() | ||
|
|
||
| // normally in a row there are more columns then | ||
| // column families this wrapper is reused for column | ||
| // family look ups | ||
| val reusableWrapper = new ByteArrayWrapper(null) | ||
|
|
||
| /** | ||
| * Adds a new cell to an existing row | ||
| * @param family HBase column family | ||
| * @param qualifier HBase column qualifier | ||
| * @param value HBase cell value | ||
| */ | ||
| def +=(family: Array[Byte], qualifier: Array[Byte], value: Array[Byte]): Unit = { | ||
|
|
||
| reusableWrapper.value = family | ||
|
|
||
| var qualifierValues = familyMap.get(reusableWrapper) | ||
|
|
||
| if (qualifierValues == null) { | ||
| qualifierValues = new util.TreeMap[ByteArrayWrapper, Array[Byte]]() | ||
| familyMap.put(new ByteArrayWrapper(family), qualifierValues) | ||
| } | ||
|
|
||
| qualifierValues.put(new ByteArrayWrapper(qualifier), value) | ||
| } | ||
|
|
||
| /** | ||
| * A wrapper for "+=" method above, can be used by Java | ||
| * @param family HBase column family | ||
| * @param qualifier HBase column qualifier | ||
| * @param value HBase cell value | ||
| */ | ||
| def add(family: Array[Byte], qualifier: Array[Byte], value: Array[Byte]): Unit = { | ||
| this += (family, qualifier, value) | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
...4/hbase-spark4/src/main/scala/org/apache/hadoop/hbase/spark/FamilyHFileWriteOptions.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * 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.hadoop.hbase.spark | ||
|
|
||
| import java.io.Serializable | ||
| import org.apache.yetus.audience.InterfaceAudience | ||
|
|
||
| /** | ||
| * This object will hold optional data for how a given column family's | ||
| * writer will work | ||
| * | ||
| * @param compression String to define the Compression to be used in the HFile | ||
| * @param bloomType String to define the bloom type to be used in the HFile | ||
| * @param blockSize The block size to be used in the HFile | ||
| * @param dataBlockEncoding String to define the data block encoding to be used | ||
| * in the HFile | ||
| */ | ||
| @InterfaceAudience.Public | ||
| class FamilyHFileWriteOptions( | ||
| val compression: String, | ||
| val bloomType: String, | ||
| val blockSize: Int, | ||
| val dataBlockEncoding: String) | ||
| extends Serializable |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.