petersomogyi commented on code in PR #157:
URL: https://github.com/apache/hbase-connectors/pull/157#discussion_r3529623496
##########
dev-support/jenkins/Dockerfile:
##########
@@ -28,6 +28,18 @@ RUN apt-get -q update && apt-get -q install
--no-install-recommends -y \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
+# JDK 17 for the Spark4 profile (maven-enforcer-plugin requires JDK 17+)
+RUN wget -q
https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.11%2B9/OpenJDK17U-jdk_x64_linux_hotspot_17.0.11_9.tar.gz
-O /tmp/jdk17.tar.gz && \
+ mkdir -p /usr/local/openjdk-17 && \
+ tar -xzf /tmp/jdk17.tar.gz --strip-components=1 -C /usr/local/openjdk-17
&& \
+ rm /tmp/jdk17.tar.gz
+
+# Yetus xml check uses jrunscript (removed in JDK 14). Provide a wrapper so
+# it remains available when JAVA_HOME points to JDK 17.
+RUN printf '#!/bin/sh\nexec /usr/local/openjdk-8/bin/jrunscript "$@"\n' \
Review Comment:
Is this required because we're using an older Yetus in hbase-connectors? I
don't see similar in the main repository.
##########
spark4/hbase-spark4/pom.xml:
##########
@@ -200,7 +224,30 @@
</execution>
<execution>
<id>scala-test-compile</id>
- <phase>none</phase>
+ <goals>
+ <goal>testCompile</goal>
+ </goals>
+ <phase>process-test-resources</phase>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.scalatest</groupId>
+ <artifactId>scalatest-maven-plugin</artifactId>
+ <version>2.2.0</version>
Review Comment:
Can you use a property for the version? The scalatest-maven-plugin is also
defined in `spark/hbase-spark/pom.xml` file.
##########
pom.xml:
##########
@@ -839,6 +841,13 @@
</format>
</formats>
</configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.openjdk.nashorn</groupId>
+ <artifactId>nashorn-core</artifactId>
+ <version>15.4</version>
Review Comment:
Please use a version property.
##########
dev-support/jenkins/hbase-personality.sh:
##########
@@ -30,6 +30,17 @@ function personality_modules
local extra=""
local MODULES=("${CHANGED_MODULES[@]}")
+ # When spark4 modules are in the changed set, activate the spark4 profile
+ # so the full reactor (including hbase-spark-pushdown_2.13) is built.
+ # The maven-enforcer-plugin in the spark4 profile requires JDK 17+.
+ if [[ "${MODULES[*]}" =~ spark4 ]]; then
Review Comment:
Does it also work if the changed file is in the global pom.xml as an example?
##########
spark4/hbase-spark4/pom.xml:
##########
@@ -110,6 +110,30 @@
<groupId>org.apache.yetus</groupId>
<artifactId>audience-annotations</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.hbase</groupId>
+ <artifactId>hbase-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hbase</groupId>
+ <artifactId>hbase-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hbase</groupId>
+ <artifactId>hbase-mapreduce</artifactId>
+ </dependency>
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>org.scalatest</groupId>
+ <artifactId>scalatest_${scala.binary.version}</artifactId>
+ <version>3.2.17</version>
Review Comment:
The spark/hbase-spark/pom.xml also has `scalatest` dependency. Can the
versions be harmonised between the 2 places?
##########
spark4/hbase-spark4/src/test/scala/org/apache/hadoop/hbase/spark/HBaseContextSuite.scala:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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 org.apache.hadoop.hbase.{CellUtil, KeyValue}
+import org.apache.hadoop.hbase.client.Result
+import org.apache.hadoop.hbase.util.Bytes
+import org.apache.spark.{SparkConf, SparkContext}
+import org.apache.spark.sql.Row
+import org.scalatest.BeforeAndAfterAll
+import org.scalatest.funsuite.AnyFunSuite
+
+class HBaseContextSuite extends AnyFunSuite with BeforeAndAfterAll {
+
+ @transient var sc: SparkContext = _
+
+ val columnFamily = "c"
+
+ override def beforeAll(): Unit = {
+ val conf = new SparkConf()
+ .setMaster("local[2]")
+ .setAppName("HBaseContextSuite")
+ sc = new SparkContext(conf)
+ }
+
+ override def afterAll(): Unit = {
+ if (sc != null) {
+ sc.stop()
+ }
+ }
+
+ private def buildResult(rowKey: String, columns: Map[String, String]):
Result = {
+ val kvs = columns
+ .map {
+ case (qualifier, value) =>
+ new KeyValue(
+ Bytes.toBytes(rowKey),
+ Bytes.toBytes(columnFamily),
+ Bytes.toBytes(qualifier),
+ Bytes.toBytes(value))
+ }
+ .toArray
+ .sortBy(kv => Bytes.toString(CellUtil.cloneQualifier(kv)))
+
+ Result.create(kvs.asInstanceOf[Array[org.apache.hadoop.hbase.Cell]])
+ }
+
+ private def resultToRow(result: Result, cols: Array[String]): Row = {
+ val cells = result.listCells()
+ val values = new java.util.HashMap[String, String](cells.size())
+ val iter = cells.iterator()
+ while (iter.hasNext) {
+ val cell = iter.next()
+ values.put(
+ Bytes.toString(CellUtil.cloneQualifier(cell)),
+ Bytes.toString(CellUtil.cloneValue(cell)))
+ }
+ Row.fromSeq(cols.map(col => values.get(col): Any))
+ }
+
+ test("hbaseRDDAsRows extracts specified columns into Row objects") {
+ val columns = Seq("name", "age")
+ val cols = columns.toArray
+
+ val row1 = resultToRow(buildResult("row1", Map("name" -> "Alice", "age" ->
"30")), cols)
+ val row2 = resultToRow(buildResult("row2", Map("name" -> "Bob", "age" ->
"25")), cols)
+ val row3 = resultToRow(buildResult("row3", Map("name" -> "Charlie", "age"
-> "35")), cols)
+
+ val rows = Array(row1, row2, row3).sortBy(_.getString(0))
+ assert(rows.length == 3)
+ assert(rows(0).getString(0) == "Alice")
+ assert(rows(0).getString(1) == "30")
+ assert(rows(1).getString(0) == "Bob")
+ assert(rows(1).getString(1) == "25")
+ assert(rows(2).getString(0) == "Charlie")
+ assert(rows(2).getString(1) == "35")
+ }
+
+ test("hbaseRDDAsRows returns null for missing columns") {
+ val columns = Seq("name", "nonexistent_col")
+ val cols = columns.toArray
+
+ val row = resultToRow(buildResult("row1", Map("name" -> "Alice", "age" ->
"30")), cols)
+
+ assert(row.getString(0) == "Alice")
+ assert(row.get(1) == null)
+ }
+
+ test("hbaseRDDAsRows handles empty result set") {
+ val columns = Seq("name", "age")
+ val cols = columns.toArray
+
+ val rdd = sc.parallelize(Seq.empty[Array[String]])
+ val rows = rdd
+ .map {
+ fields =>
+ Row.fromSeq(
+ cols.map(col => fields.find(_.startsWith(col +
"=")).map(_.split("=")(1)).orNull: Any))
+ }
+ .collect()
+
+ assert(rows.isEmpty)
+ }
+
+ test("hbaseRDDAsRows preserves column ordering") {
+ val columns = Seq("m_col", "a_col", "z_col")
+ val cols = columns.toArray
+
+ val row = resultToRow(
+ buildResult("row1", Map("z_col" -> "last", "a_col" -> "first", "m_col"
-> "middle")),
+ cols)
+
+ assert(row.getString(0) == "middle")
+ assert(row.getString(1) == "first")
+ assert(row.getString(2) == "last")
+ }
+
+ test("closure serialization succeeds with serializable column array") {
Review Comment:
What does this test actually 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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]