Sigma-Ma commented on code in PR #174: URL: https://github.com/apache/hbase-connectors/pull/174#discussion_r4501070914
########## 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: > > The unresolved case is b > 1 OR s IS NULL: the byte comparison makes the whole OR residual, and hasNullCheck then becomes false because it only examines pushed filters. Qualifier pruning can discard sparse rows before Spark evaluates the OR. > > So the issue is restricted to ByteType predicate scenarios? Could we simplify it by delegating the byte type check to the pushdown filter layer, maybe by defining a new dynamic expression to always include when there a byte comparison? Ah, ByteType was just an easy repro here. I checked a timestamp comparison OR `s IS NULL` as well, and the old scan path drops the sparse row too. An always-include expression could help, but we'd still need Spark to evaluate the original OR. We'd also need the NULL read handling when column pushdown is off. So I'd keep the scan fix here and leave partial pushdown for a follow-up. We already have `PassThroughLogicExpression` that we could reuse. -- 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]
