Github user jackylk commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/2148#discussion_r183077175
  
    --- Diff: 
integration/spark2/src/main/scala/org/apache/spark/sql/CarbonSession.scala ---
    @@ -110,6 +149,69 @@ class CarbonSession(@transient val sc: SparkContext,
           }
         }
       }
    +
    +  /**
    +   * If the query is a simple query with filter, we will try to use Search 
Mode,
    +   * otherwise execute in SparkSQL
    +   */
    +  private def trySearchMode(qe: QueryExecution, sse: SQLStart): DataFrame 
= {
    +    val analyzed = qe.analyzed
    +    analyzed match {
    +      case _@Project(columns, _@Filter(expr, s: SubqueryAlias))
    +        if s.child.isInstanceOf[LogicalRelation] &&
    +           s.child.asInstanceOf[LogicalRelation].relation
    +             .isInstanceOf[CarbonDatasourceHadoopRelation] =>
    +        runSearch(analyzed, columns, expr, 
s.child.asInstanceOf[LogicalRelation])
    +      case gl@GlobalLimit(_, ll@LocalLimit(_, p@Project(columns, 
_@Filter(expr, s: SubqueryAlias))))
    +        if s.child.isInstanceOf[LogicalRelation] &&
    +           s.child.asInstanceOf[LogicalRelation].relation
    +             .isInstanceOf[CarbonDatasourceHadoopRelation] =>
    +        val logicalRelation = s.child.asInstanceOf[LogicalRelation]
    +        runSearch(analyzed, columns, expr, logicalRelation, gl.maxRows, 
ll.maxRows)
    +      case _ =>
    +        new Dataset[Row](self, qe, RowEncoder(qe.analyzed.schema))
    +    }
    +  }
    +
    +  private var carbonStore: SparkCarbonStore = _
    +
    +  def startSearchMode(): Unit = {
    +    CarbonProperties.enableSearchMode(true)
    +    if (carbonStore == null) {
    +      carbonStore = new SparkCarbonStore(this)
    +      carbonStore.startSearchMode()
    +    }
    +  }
    +
    +  def stopSearchMode(): Unit = {
    +    CarbonProperties.enableSearchMode(false)
    +    if (carbonStore != null) {
    +      carbonStore.stopSearchMode()
    +      carbonStore = null
    +    }
    +  }
    +
    +  private def runSearch(
    +      logicalPlan: LogicalPlan,
    +      columns: Seq[NamedExpression],
    +      expr: Expression,
    +      relation: LogicalRelation,
    +      maxRows: Option[Long] = None,
    +      localMaxRows: Option[Long] = None): DataFrame = {
    +    val rows = carbonStore.search(
    +        
relation.relation.asInstanceOf[CarbonDatasourceHadoopRelation].carbonTable,
    +        columns.map(_.name).toArray,
    +        if (expr != null) CarbonFilters.transformExpression(expr) else 
null,
    +        maxRows.getOrElse(Long.MaxValue),
    +        localMaxRows.getOrElse(Long.MaxValue))
    --- End diff --
    
    I have added Long.MaxValue here, I think it is better than using -1


---

Reply via email to