Copilot commented on code in PR #162:
URL: https://github.com/apache/hbase-connectors/pull/162#discussion_r3989614222


##########
spark4/hbase-spark4/src/main/scala/org/apache/hadoop/hbase/spark/datasources/HBasePartitionReaderFactory.scala:
##########
@@ -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.hadoop.hbase.spark.datasources
+
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.connector.read.{InputPartition, PartitionReader, 
PartitionReaderFactory}
+import org.apache.spark.sql.sources.Filter
+import org.apache.spark.sql.types.StructType
+import org.apache.yetus.audience.InterfaceAudience
+
+/**
+ * This is a new class in the spark4 module. Implements PartitionReaderFactory 
for
+ * creating HBasePartitionReader instances on executors.
+ *
+ * In the spark 3 DS V1 model, there was no factory, the 
RDD.compute(partition) call directly created the iterator.
+ *
+ *
+ * @param requiredSchema
+ * @param properties
+ * @param catalog
+ * @param pushedFilters
+ * @param encoderClsName
+ * @param usePushDownColumnFilter
+ */
[email protected]
+class HBasePartitionReaderFactory(
+    requiredSchema: StructType,
+    properties: Map[String, String],
+    catalog: HBaseTableCatalog,

Review Comment:
   `PartitionReaderFactory` is serialized to executors, but this catalog 
retains each instantiated `Field.serdes`. `SerDes` does not extend 
`Serializable` (`SerDes.scala:24`), and even the bundled `DoubleSerDes` is 
therefore enough to make a scan fail with `NotSerializableException`. Pass the 
catalog properties and rebuild `HBaseTableCatalog` inside `createReader`, or 
make serializability part of the `SerDes` contract.



##########
spark4/hbase-spark4/src/main/scala/org/apache/hadoop/hbase/spark/datasources/HBaseScanBuilder.scala:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.datasources
+
+import org.apache.hadoop.hbase.spark.Logging
+import org.apache.spark.sql.connector.read.{Scan, ScanBuilder, 
SupportsPushDownFilters, SupportsPushDownRequiredColumns}
+import org.apache.spark.sql.sources._
+import org.apache.spark.sql.types.StructType
+import org.apache.yetus.audience.InterfaceAudience
+import scala.collection.mutable.ListBuffer
+
+/**
+ * This is a new class in the spark4 module.
+ * Implements ScanBuilder, SupportsPushDownFilters, and 
SupportsPushDownRequiredColumns.
+ * This is where Catalyst negotiates with the connector. Spark calls 
pushFilters() with
+ * candidate predicates and the builder accepts what it can handle and returns 
the rest.
+ * Spark calls pruneColumns() to say which columns it actually needs.
+ * Then build() produces the final scan plan.
+ *
+ * In the spark 3 V1 model, this negotiation happened implicitly via
+ * PrunedFilteredScan.buildScan(requiredColumns, filters) as a single method 
call with no back-and-forth.
+ *
+ * @param schema
+ * @param properties
+ */
[email protected]
+class HBaseScanBuilder(schema: StructType, properties: Map[String, String])
+    extends ScanBuilder
+    with SupportsPushDownFilters
+    with SupportsPushDownRequiredColumns
+    with Logging {
+
+  private val catalog = HBaseTableCatalog(properties)
+  private val encoderClsName =
+    properties.getOrElse(HBaseSparkConf.QUERY_ENCODER, 
HBaseSparkConf.DEFAULT_QUERY_ENCODER)
+  @transient private val encoder = JavaBytesEncoder.create(encoderClsName)
+
+  private var _pushedFilters: Array[Filter] = Array.empty
+  private var requiredSchema: StructType = schema
+
+  override def pushFilters(filters: Array[Filter]): Array[Filter] = {
+    val usePushDown = properties
+      .get(HBaseSparkConf.PUSHDOWN_COLUMN_FILTER)
+      .map(_.toBoolean)
+      .getOrElse(HBaseSparkConf.DEFAULT_PUSHDOWN_COLUMN_FILTER)
+
+    if (!usePushDown) {
+      _pushedFilters = Array.empty
+      return filters
+    }
+
+    val hasCompositeRowKey = catalog.getRowKey.size > 1
+
+    def isSupported(f: Filter): Boolean = f match {
+      case EqualTo(attr, _) => isSupportedField(attr)
+      case LessThan(attr, _) => isSupportedField(attr)
+      case GreaterThan(attr, _) => isSupportedField(attr)
+      case LessThanOrEqual(attr, _) => isSupportedField(attr)
+      case GreaterThanOrEqual(attr, _) => isSupportedField(attr)

Review Comment:
   Range predicates are accepted for every catalog type, but the default 
`NaiveEncoder` cannot encode all of those literals consistently with stored 
HBase bytes. In particular, timestamp encoding casts Spark's external timestamp 
literal to `Long`, while date and decimal fall back to textual `UnknownEnc`; 
these predicates can throw or return wrong rows, and Spark will not re-evaluate 
them because they were reported as pushed. Restrict each comparison to 
encoder-supported types or add correct date/timestamp/decimal encoding first.



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

Reply via email to