wchevreuil commented on code in PR #162: URL: https://github.com/apache/hbase-connectors/pull/162#discussion_r3969873721
########## spark4/hbase-spark4/src/main/scala/org/apache/hadoop/hbase/spark/datasources/HBaseScan.scala: ########## @@ -0,0 +1,153 @@ +/* + * 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.{Batch, Scan} +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 Scan. + * + * An immutable snapshot of the scan plan after negotiation is complete. + * Holds the pushed filters, required schema, and encoder. + * Builds the RowKeyFilter (for scan range narrowing from row key predicates) and produces the Batch. + * + * In the spark 3 V1 model, there was no separation between "plan" and "execution", the buildScan() method did both. + * + * @param requiredSchema + * @param properties + * @param catalog + * @param pushedFilters + * @param encoderClsName + * @param encoder + */ [email protected] +class HBaseScan( + requiredSchema: StructType, + properties: Map[String, String], + catalog: HBaseTableCatalog, + pushedFilters: Array[Filter], + encoderClsName: String, + @transient encoder: BytesEncoder) + extends Scan + with Logging { + + override def readSchema(): StructType = requiredSchema + + override def toBatch: Batch = { + val rowKeyFilter = buildRowKeyFilter() + new HBaseBatch(requiredSchema, properties, catalog, rowKeyFilter, pushedFilters, encoderClsName) + } + + private def buildRowKeyFilter(): RowKeyFilter = { + var superRowKeyFilter: RowKeyFilter = null + val queryValueList = new ListBuffer[Array[Byte]] + + pushedFilters.foreach { f => + val rowKeyFilter = new RowKeyFilter() + traverseFilterTree(rowKeyFilter, queryValueList, f) + if (superRowKeyFilter == null) { + superRowKeyFilter = rowKeyFilter + } else { + superRowKeyFilter.mergeIntersect(rowKeyFilter) + } + } + + if (superRowKeyFilter == null) { + superRowKeyFilter = new RowKeyFilter + } + superRowKeyFilter + } + + private def traverseFilterTree( + parentRowKeyFilter: RowKeyFilter, + valueArray: ListBuffer[Array[Byte]], + filter: Filter): Unit = { Review Comment: Addressing on next commit. -- 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]
