wchevreuil commented on code in PR #174:
URL: https://github.com/apache/hbase-connectors/pull/174#discussion_r4486069866


##########
spark4/hbase-spark4/src/main/scala/org/apache/hadoop/hbase/spark/datasources/HBaseScanBuilder.scala:
##########
@@ -109,7 +101,13 @@ class HBaseScanBuilder(schema: StructType, properties: 
Map[String, String])
   }
 
   override def build(): Scan = {
-    new HBaseScan(requiredSchema, properties, catalog, _pushedFilters, 
_rowKeyFilters,
-      encoderClsName, encoder)
+    new HBaseScan(
+      requiredSchema,
+      properties,
+      catalog,
+      _pushedFilters,
+      _rowKeyFilters,
+      encoderClsName,
+      encoder)

Review Comment:
   nit: avoid unnecessary formatting changes.



##########
spark/hbase-spark-pushdown/src/main/scala/org/apache/hadoop/hbase/spark/datasources/PredicatePushdownSupport.scala:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.sources._
+import org.apache.spark.sql.types._
+import org.apache.yetus.audience.InterfaceAudience
+
[email protected]
+private[spark] object PredicatePushdownSupport {
+
+  def isSupported(
+      filter: Filter,
+      dataTypeOf: String => Option[DataType],
+      isNaiveEncoder: Boolean): Boolean = {
+    def hasSafeLiteral(attr: String, value: Any): Boolean = {
+      (dataTypeOf(attr), value) match {
+        case (Some(BooleanType), _: Boolean) => true
+        case (Some(ByteType), _: Byte) => true
+        case (Some(ShortType), _: Short) => true
+        case (Some(IntegerType), _: Int) => true
+        case (Some(LongType), _: Long) => true
+        case (Some(StringType), _: String) => true
+        case (Some(BinaryType), _: Array[Byte]) => true
+        // shortcut: temporal, decimal and floating point comparisons stay in 
Spark until
+        // encoding, SQL comparison semantics and row-key pruning are all 
supported.
+        case _ => false
+      }
+    }
+
+    // Byte has no comparison tag, and its ranges do not split signed values 
at zero.
+    def supportsRange(attr: String, value: Any): Boolean =
+      isNaiveEncoder && hasSafeLiteral(attr, value) && 
!dataTypeOf(attr).contains(ByteType)
+
+    filter match {
+      case EqualTo(attr, value) => hasSafeLiteral(attr, value)
+      case LessThan(attr, value) => supportsRange(attr, value)
+      case LessThanOrEqual(attr, value) => supportsRange(attr, value)
+      case GreaterThan(attr, value) => supportsRange(attr, value)
+      case GreaterThanOrEqual(attr, value) => supportsRange(attr, value)
+      case StringStartsWith(attr, value) => value != null && 
dataTypeOf(attr).contains(StringType)
+      case IsNull(attr) => dataTypeOf(attr).isDefined

Review Comment:
   I don't think this is actually a problem, the 
SparkSQLPushDownFilter.filterRow with the IsNullLogicExpression is guaranteed 
to include the row with a missing cell.



##########
spark4/hbase-spark4/src/main/scala/org/apache/hadoop/hbase/spark/datasources/HBaseScanBuilder.scala:
##########
@@ -57,33 +57,25 @@ class HBaseScanBuilder(schema: StructType, properties: 
Map[String, String])
   override def pushFilters(filters: Array[Filter]): Array[Filter] = {
     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)
-      case StringStartsWith(attr, _) => isSupportedField(attr)
-      case IsNull(attr) => isSupportedField(attr)
-      case IsNotNull(attr) => isSupportedField(attr)
-      case Or(left, right) => isSupported(left) && isSupported(right)
-      case And(left, right) => isSupported(left) && isSupported(right)
-      case _ => false
-    }
-
-    def isSupportedField(attr: String): Boolean = {
-      catalog.sMap.map.get(attr) match {
-        case Some(field) => !(hasCompositeRowKey && field.isRowKey)
-        case None => false
-      }
-    }
+    def dataTypeOf(attr: String): Option[DataType] =
+      catalog.sMap.map
+        .get(attr)
+        .filter(
+          field =>
+            !(hasCompositeRowKey && field.isRowKey) &&
+              field.avroSchema.isEmpty && field.serdes.isEmpty)

Review Comment:
   isn't this dealing with the problem below?
   
   > and primitive Avro equality fallback can raise a ClassCastException.



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