You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@carbondata.apache.org by lionelcao <gi...@git.apache.org> on 2017/03/06 06:15:52 UTC

[GitHub] incubator-carbondata pull request #625: [CARBONDATA-743] Remove redundant Ca...

GitHub user lionelcao opened a pull request:

    https://github.com/apache/incubator-carbondata/pull/625

    [CARBONDATA-743] Remove redundant CarbonFilters file

    Remove redundant CarbonFilters file in Spark2 and keep the one in spark common.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/lionelcao/incubator-carbondata lionelcao_dev

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-carbondata/pull/625.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #625
    
----
commit 9ded763ae4fe7dec0fa6e21617c7faf72b7e70c1
Author: lucao <wh...@gmail.com>
Date:   2017-03-06T06:07:52Z

    [CARBONDATA-743] Remove redundant CarbonFilters file

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-carbondata pull request #625: [CARBONDATA-743] Remove redundant Ca...

Posted by lionelcao <gi...@git.apache.org>.
Github user lionelcao commented on a diff in the pull request:

    https://github.com/apache/incubator-carbondata/pull/625#discussion_r104575582
  
    --- Diff: integration/spark2/src/main/scala/org/apache/carbondata/spark/CarbonFilters.scala ---
    @@ -1,397 +0,0 @@
    -/*
    - * 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.carbondata.spark
    -
    -import scala.collection.mutable.ArrayBuffer
    -
    -import org.apache.spark.sql.catalyst.expressions._
    -import org.apache.spark.sql.optimizer.AttributeReferenceWrapper
    -import org.apache.spark.sql.sources
    -import org.apache.spark.sql.types.StructType
    -
    -import org.apache.carbondata.core.metadata.datatype.DataType
    -import org.apache.carbondata.core.metadata.schema.table.CarbonTable
    -import org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn
    -import org.apache.carbondata.core.scan.expression.{ColumnExpression => CarbonColumnExpression, Expression => CarbonExpression, LiteralExpression => CarbonLiteralExpression}
    -import org.apache.carbondata.core.scan.expression.conditional._
    -import org.apache.carbondata.core.scan.expression.logical.{AndExpression, FalseExpression, OrExpression}
    -import org.apache.carbondata.spark.util.CarbonScalaUtil
    -
    -/**
    - * All filter conversions are done here.
    - */
    -object CarbonFilters {
    -
    -  /**
    -   * Converts data sources filters to carbon filter predicates.
    -   */
    -  def createCarbonFilter(schema: StructType,
    -      predicate: sources.Filter): Option[CarbonExpression] = {
    -    val dataTypeOf = schema.map(f => f.name -> f.dataType).toMap
    -
    -    def createFilter(predicate: sources.Filter): Option[CarbonExpression] = {
    -      predicate match {
    -
    -        case sources.EqualTo(name, value) =>
    -          Some(new EqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.Not(sources.EqualTo(name, value)) =>
    -          Some(new NotEqualsExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -
    -        case sources.EqualNullSafe(name, value) =>
    -          Some(new EqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.Not(sources.EqualNullSafe(name, value)) =>
    -          Some(new NotEqualsExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -
    -        case sources.GreaterThan(name, value) =>
    -          Some(new GreaterThanExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.LessThan(name, value) =>
    -          Some(new LessThanExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.GreaterThanOrEqual(name, value) =>
    -          Some(new GreaterThanEqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.LessThanOrEqual(name, value) =>
    -          Some(new LessThanEqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -
    -        case sources.In(name, values) =>
    -          Some(new InExpression(getCarbonExpression(name),
    -            new ListExpression(
    -              convertToJavaList(values.map(f => getCarbonLiteralExpression(name, f)).toList))))
    -        case sources.Not(sources.In(name, values)) =>
    -          Some(new NotInExpression(getCarbonExpression(name),
    -            new ListExpression(
    -              convertToJavaList(values.map(f => getCarbonLiteralExpression(name, f)).toList))))
    -
    -        case sources.IsNull(name) =>
    -          Some(new EqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, null), true))
    -        case sources.IsNotNull(name) =>
    -          Some(new NotEqualsExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, null), true))
    -        case sources.And(lhs, rhs) =>
    -          (createFilter(lhs) ++ createFilter(rhs)).reduceOption(new AndExpression(_, _))
    -
    -        case sources.Or(lhs, rhs) =>
    -          for {
    -            lhsFilter <- createFilter(lhs)
    -            rhsFilter <- createFilter(rhs)
    -          } yield {
    -            new OrExpression(lhsFilter, rhsFilter)
    -          }
    -
    -        case _ => None
    -      }
    -    }
    -
    -    def getCarbonExpression(name: String) = {
    -      new CarbonColumnExpression(name,
    -        CarbonScalaUtil.convertSparkToCarbonDataType(dataTypeOf(name)))
    -    }
    -
    -    def getCarbonLiteralExpression(name: String, value: Any): CarbonExpression = {
    -      new CarbonLiteralExpression(value,
    -        CarbonScalaUtil.convertSparkToCarbonDataType(dataTypeOf(name)))
    -    }
    -
    -    createFilter(predicate)
    -  }
    -
    -
    -  // Check out which filters can be pushed down to carbon, remaining can be handled in spark layer.
    -  // Mostly dimension filters are only pushed down since it is faster in carbon.
    -  def selectFilters(filters: Seq[Expression],
    -      attrList: java.util.HashSet[AttributeReferenceWrapper],
    -      aliasMap: CarbonAliasDecoderRelation): Unit = {
    -    def translate(expr: Expression, or: Boolean = false): Option[sources.Filter] = {
    -      expr match {
    -        case or@ Or(left, right) =>
    -
    -          val leftFilter = translate(left, or = true)
    -          val rightFilter = translate(right, or = true)
    -          if (leftFilter.isDefined && rightFilter.isDefined) {
    -            Some( sources.Or(leftFilter.get, rightFilter.get))
    -          } else {
    -            or.collect {
    -              case attr: AttributeReference =>
    -                attrList.add(AttributeReferenceWrapper(aliasMap.getOrElse(attr, attr)))
    -            }
    -            None
    -          }
    -
    -        case And(left, right) =>
    -          (translate(left) ++ translate(right)).reduceOption(sources.And)
    -
    -        case EqualTo(a: Attribute, Literal(v, t)) =>
    -          Some(sources.EqualTo(a.name, v))
    -        case EqualTo(l@Literal(v, t), a: Attribute) =>
    -          Some(sources.EqualTo(a.name, v))
    -        case EqualTo(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.EqualTo(a.name, v))
    -        case EqualTo(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.EqualTo(a.name, v))
    -
    -        case Not(EqualTo(a: Attribute, Literal(v, t))) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case Not(EqualTo(Literal(v, t), a: Attribute)) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case Not(EqualTo(Cast(a: Attribute, _), Literal(v, t))) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case Not(EqualTo(Literal(v, t), Cast(a: Attribute, _))) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case IsNotNull(a: Attribute) => Some(sources.IsNotNull(a.name))
    -        case IsNull(a: Attribute) => Some(sources.IsNull(a.name))
    -        case Not(In(a: Attribute, list)) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.Not(sources.In(a.name, hSet.toArray)))
    -        case In(a: Attribute, list) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.In(a.name, hSet.toArray))
    -        case Not(In(Cast(a: Attribute, _), list))
    -          if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.Not(sources.In(a.name, hSet.toArray)))
    -        case In(Cast(a: Attribute, _), list) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.In(a.name, hSet.toArray))
    -
    -        case GreaterThan(a: Attribute, Literal(v, t)) =>
    -          Some(sources.GreaterThan(a.name, v))
    -        case GreaterThan(Literal(v, t), a: Attribute) =>
    -          Some(sources.LessThan(a.name, v))
    -        case GreaterThan(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.GreaterThan(a.name, v))
    -        case GreaterThan(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.LessThan(a.name, v))
    -
    -        case LessThan(a: Attribute, Literal(v, t)) =>
    -          Some(sources.LessThan(a.name, v))
    -        case LessThan(Literal(v, t), a: Attribute) =>
    -          Some(sources.GreaterThan(a.name, v))
    -        case LessThan(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.LessThan(a.name, v))
    -        case LessThan(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.GreaterThan(a.name, v))
    -
    -        case GreaterThanOrEqual(a: Attribute, Literal(v, t)) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -        case GreaterThanOrEqual(Literal(v, t), a: Attribute) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -        case GreaterThanOrEqual(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -        case GreaterThanOrEqual(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -
    -        case LessThanOrEqual(a: Attribute, Literal(v, t)) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -        case LessThanOrEqual(Literal(v, t), a: Attribute) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -        case LessThanOrEqual(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -        case LessThanOrEqual(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -
    -        case others =>
    -          if (!or) {
    -            others.collect {
    -              case attr: AttributeReference =>
    -                attrList.add(AttributeReferenceWrapper(aliasMap.getOrElse(attr, attr)))
    -            }
    -          }
    -          None
    -      }
    -    }
    -    filters.flatMap(translate(_)).toArray
    --- End diff --
    
    The 2nd parameter in translate() is false by default thus translate(_) equals to translate(_, false).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-carbondata issue #625: [CARBONDATA-743] Remove redundant CarbonFil...

Posted by CarbonDataQA <gi...@git.apache.org>.
Github user CarbonDataQA commented on the issue:

    https://github.com/apache/incubator-carbondata/pull/625
  
    Build Failed  with Spark 1.6.2, Please check CI http://136.243.101.176:8080/job/ApacheCarbonPRBuilder/1020/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-carbondata pull request #625: [CARBONDATA-743] Remove redundant Ca...

Posted by chenliang613 <gi...@git.apache.org>.
Github user chenliang613 commented on a diff in the pull request:

    https://github.com/apache/incubator-carbondata/pull/625#discussion_r104424923
  
    --- Diff: integration/spark2/src/main/scala/org/apache/carbondata/spark/CarbonFilters.scala ---
    @@ -1,397 +0,0 @@
    -/*
    - * 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.carbondata.spark
    -
    -import scala.collection.mutable.ArrayBuffer
    -
    -import org.apache.spark.sql.catalyst.expressions._
    -import org.apache.spark.sql.optimizer.AttributeReferenceWrapper
    -import org.apache.spark.sql.sources
    -import org.apache.spark.sql.types.StructType
    -
    -import org.apache.carbondata.core.metadata.datatype.DataType
    -import org.apache.carbondata.core.metadata.schema.table.CarbonTable
    -import org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn
    -import org.apache.carbondata.core.scan.expression.{ColumnExpression => CarbonColumnExpression, Expression => CarbonExpression, LiteralExpression => CarbonLiteralExpression}
    -import org.apache.carbondata.core.scan.expression.conditional._
    -import org.apache.carbondata.core.scan.expression.logical.{AndExpression, FalseExpression, OrExpression}
    -import org.apache.carbondata.spark.util.CarbonScalaUtil
    -
    -/**
    - * All filter conversions are done here.
    - */
    -object CarbonFilters {
    -
    -  /**
    -   * Converts data sources filters to carbon filter predicates.
    -   */
    -  def createCarbonFilter(schema: StructType,
    -      predicate: sources.Filter): Option[CarbonExpression] = {
    -    val dataTypeOf = schema.map(f => f.name -> f.dataType).toMap
    -
    -    def createFilter(predicate: sources.Filter): Option[CarbonExpression] = {
    -      predicate match {
    -
    -        case sources.EqualTo(name, value) =>
    -          Some(new EqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.Not(sources.EqualTo(name, value)) =>
    -          Some(new NotEqualsExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -
    -        case sources.EqualNullSafe(name, value) =>
    -          Some(new EqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.Not(sources.EqualNullSafe(name, value)) =>
    -          Some(new NotEqualsExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -
    -        case sources.GreaterThan(name, value) =>
    -          Some(new GreaterThanExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.LessThan(name, value) =>
    -          Some(new LessThanExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.GreaterThanOrEqual(name, value) =>
    -          Some(new GreaterThanEqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.LessThanOrEqual(name, value) =>
    -          Some(new LessThanEqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -
    -        case sources.In(name, values) =>
    -          Some(new InExpression(getCarbonExpression(name),
    -            new ListExpression(
    -              convertToJavaList(values.map(f => getCarbonLiteralExpression(name, f)).toList))))
    -        case sources.Not(sources.In(name, values)) =>
    -          Some(new NotInExpression(getCarbonExpression(name),
    -            new ListExpression(
    -              convertToJavaList(values.map(f => getCarbonLiteralExpression(name, f)).toList))))
    -
    -        case sources.IsNull(name) =>
    -          Some(new EqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, null), true))
    -        case sources.IsNotNull(name) =>
    -          Some(new NotEqualsExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, null), true))
    -        case sources.And(lhs, rhs) =>
    -          (createFilter(lhs) ++ createFilter(rhs)).reduceOption(new AndExpression(_, _))
    -
    -        case sources.Or(lhs, rhs) =>
    -          for {
    -            lhsFilter <- createFilter(lhs)
    -            rhsFilter <- createFilter(rhs)
    -          } yield {
    -            new OrExpression(lhsFilter, rhsFilter)
    -          }
    -
    -        case _ => None
    -      }
    -    }
    -
    -    def getCarbonExpression(name: String) = {
    -      new CarbonColumnExpression(name,
    -        CarbonScalaUtil.convertSparkToCarbonDataType(dataTypeOf(name)))
    -    }
    -
    -    def getCarbonLiteralExpression(name: String, value: Any): CarbonExpression = {
    -      new CarbonLiteralExpression(value,
    -        CarbonScalaUtil.convertSparkToCarbonDataType(dataTypeOf(name)))
    -    }
    -
    -    createFilter(predicate)
    -  }
    -
    -
    -  // Check out which filters can be pushed down to carbon, remaining can be handled in spark layer.
    -  // Mostly dimension filters are only pushed down since it is faster in carbon.
    -  def selectFilters(filters: Seq[Expression],
    -      attrList: java.util.HashSet[AttributeReferenceWrapper],
    -      aliasMap: CarbonAliasDecoderRelation): Unit = {
    -    def translate(expr: Expression, or: Boolean = false): Option[sources.Filter] = {
    -      expr match {
    -        case or@ Or(left, right) =>
    -
    -          val leftFilter = translate(left, or = true)
    -          val rightFilter = translate(right, or = true)
    -          if (leftFilter.isDefined && rightFilter.isDefined) {
    -            Some( sources.Or(leftFilter.get, rightFilter.get))
    -          } else {
    -            or.collect {
    -              case attr: AttributeReference =>
    -                attrList.add(AttributeReferenceWrapper(aliasMap.getOrElse(attr, attr)))
    -            }
    -            None
    -          }
    -
    -        case And(left, right) =>
    -          (translate(left) ++ translate(right)).reduceOption(sources.And)
    -
    -        case EqualTo(a: Attribute, Literal(v, t)) =>
    -          Some(sources.EqualTo(a.name, v))
    -        case EqualTo(l@Literal(v, t), a: Attribute) =>
    -          Some(sources.EqualTo(a.name, v))
    -        case EqualTo(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.EqualTo(a.name, v))
    -        case EqualTo(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.EqualTo(a.name, v))
    -
    -        case Not(EqualTo(a: Attribute, Literal(v, t))) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case Not(EqualTo(Literal(v, t), a: Attribute)) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case Not(EqualTo(Cast(a: Attribute, _), Literal(v, t))) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case Not(EqualTo(Literal(v, t), Cast(a: Attribute, _))) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case IsNotNull(a: Attribute) => Some(sources.IsNotNull(a.name))
    -        case IsNull(a: Attribute) => Some(sources.IsNull(a.name))
    -        case Not(In(a: Attribute, list)) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.Not(sources.In(a.name, hSet.toArray)))
    -        case In(a: Attribute, list) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.In(a.name, hSet.toArray))
    -        case Not(In(Cast(a: Attribute, _), list))
    -          if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.Not(sources.In(a.name, hSet.toArray)))
    -        case In(Cast(a: Attribute, _), list) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.In(a.name, hSet.toArray))
    -
    -        case GreaterThan(a: Attribute, Literal(v, t)) =>
    -          Some(sources.GreaterThan(a.name, v))
    -        case GreaterThan(Literal(v, t), a: Attribute) =>
    -          Some(sources.LessThan(a.name, v))
    -        case GreaterThan(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.GreaterThan(a.name, v))
    -        case GreaterThan(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.LessThan(a.name, v))
    -
    -        case LessThan(a: Attribute, Literal(v, t)) =>
    -          Some(sources.LessThan(a.name, v))
    -        case LessThan(Literal(v, t), a: Attribute) =>
    -          Some(sources.GreaterThan(a.name, v))
    -        case LessThan(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.LessThan(a.name, v))
    -        case LessThan(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.GreaterThan(a.name, v))
    -
    -        case GreaterThanOrEqual(a: Attribute, Literal(v, t)) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -        case GreaterThanOrEqual(Literal(v, t), a: Attribute) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -        case GreaterThanOrEqual(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -        case GreaterThanOrEqual(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -
    -        case LessThanOrEqual(a: Attribute, Literal(v, t)) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -        case LessThanOrEqual(Literal(v, t), a: Attribute) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -        case LessThanOrEqual(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -        case LessThanOrEqual(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -
    -        case others =>
    -          if (!or) {
    -            others.collect {
    -              case attr: AttributeReference =>
    -                attrList.add(AttributeReferenceWrapper(aliasMap.getOrElse(attr, attr)))
    -            }
    -          }
    -          None
    -      }
    -    }
    -    filters.flatMap(translate(_)).toArray
    -  }
    -
    -  def processExpression(exprs: Seq[Expression],
    -      attributesNeedToDecode: java.util.HashSet[AttributeReference],
    -      unprocessedExprs: ArrayBuffer[Expression],
    -      carbonTable: CarbonTable): Option[CarbonExpression] = {
    -    def transformExpression(expr: Expression, or: Boolean = false): Option[CarbonExpression] = {
    -      expr match {
    -        case or@ Or(left, right) =>
    -          val leftFilter = transformExpression(left, or = true)
    -          val rightFilter = transformExpression(right, or = true)
    -          if (leftFilter.isDefined && rightFilter.isDefined) {
    -            Some(new OrExpression(leftFilter.get, rightFilter.get))
    -          } else {
    -            or.collect {
    -              case attr: AttributeReference => attributesNeedToDecode.add(attr)
    -            }
    -            unprocessedExprs += or
    -            None
    -          }
    -
    -        case And(left, right) =>
    -          (transformExpression(left) ++ transformExpression(right)).reduceOption(new
    -              AndExpression(_, _))
    -
    -        case EqualTo(a: Attribute, l@Literal(v, t)) =>
    -            Some(new EqualToExpression(transformExpression(a).get, transformExpression(l).get))
    -        case EqualTo(l@Literal(v, t), a: Attribute) =>
    -            Some(new EqualToExpression(transformExpression(a).get, transformExpression(l).get))
    -        case EqualTo(Cast(a: Attribute, _), l@Literal(v, t)) =>
    -            Some(new EqualToExpression(transformExpression(a).get, transformExpression(l).get))
    -        case EqualTo(l@Literal(v, t), Cast(a: Attribute, _)) =>
    -            Some(new EqualToExpression(transformExpression(a).get, transformExpression(l).get))
    -
    -        case Not(EqualTo(a: Attribute, l@Literal(v, t))) =>
    -            Some(new NotEqualsExpression(transformExpression(a).get, transformExpression(l).get))
    -        case Not(EqualTo(l@Literal(v, t), a: Attribute)) =>
    -            Some(new NotEqualsExpression(transformExpression(a).get, transformExpression(l).get))
    -        case Not(EqualTo(Cast(a: Attribute, _), l@Literal(v, t))) =>
    -            Some(new NotEqualsExpression(transformExpression(a).get, transformExpression(l).get))
    -        case Not(EqualTo(l@Literal(v, t), Cast(a: Attribute, _))) =>
    -            Some(new NotEqualsExpression(transformExpression(a).get, transformExpression(l).get))
    -        case IsNotNull(child: Attribute) =>
    -            Some(new NotEqualsExpression(transformExpression(child).get,
    -             transformExpression(Literal(null)).get, true))
    -        case IsNull(child: Attribute) =>
    -            Some(new EqualToExpression(transformExpression(child).get,
    -             transformExpression(Literal(null)).get, true))
    -        case Not(In(a: Attribute, list))
    -          if !list.exists(!_.isInstanceOf[Literal]) =>
    -          if (list.exists(x => isNullLiteral(x.asInstanceOf[Literal]))) {
    -            Some(new FalseExpression(transformExpression(a).get))
    -          } else {
    -            Some(new NotInExpression(transformExpression(a).get,
    -              new ListExpression(convertToJavaList(list.map(transformExpression(_).get)))))
    -          }
    -        case In(a: Attribute, list) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          Some(new InExpression(transformExpression(a).get,
    -            new ListExpression(convertToJavaList(list.map(transformExpression(_).get)))))
    -        case Not(In(Cast(a: Attribute, _), list))
    -          if !list.exists(!_.isInstanceOf[Literal]) =>
    -          /* if any illogical expression comes in NOT IN Filter like
    -           NOT IN('scala',NULL) this will be treated as false expression and will
    -           always return no result. */
    -          if (list.exists(x => isNullLiteral(x.asInstanceOf[Literal]))) {
    -            Some(new FalseExpression(transformExpression(a).get))
    -          } else {
    -            Some(new NotInExpression(transformExpression(a).get, new ListExpression(
    -              convertToJavaList(list.map(transformExpression(_).get)))))
    -          }
    -        case In(Cast(a: Attribute, _), list) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          Some(new InExpression(transformExpression(a).get,
    -            new ListExpression(convertToJavaList(list.map(transformExpression(_).get)))))
    -
    -        case GreaterThan(a: Attribute, l@Literal(v, t)) =>
    -          Some(new GreaterThanExpression(transformExpression(a).get, transformExpression(l).get))
    -        case GreaterThan(Cast(a: Attribute, _), l@Literal(v, t)) =>
    -          Some(new GreaterThanExpression(transformExpression(a).get, transformExpression(l).get))
    -        case GreaterThan(l@Literal(v, t), a: Attribute) =>
    -          Some(new LessThanExpression(transformExpression(a).get, transformExpression(l).get))
    -        case GreaterThan(l@Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(new LessThanExpression(transformExpression(a).get, transformExpression(l).get))
    -
    -        case LessThan(a: Attribute, l@Literal(v, t)) =>
    -          Some(new LessThanExpression(transformExpression(a).get, transformExpression(l).get))
    -        case LessThan(Cast(a: Attribute, _), l@Literal(v, t)) =>
    -          Some(new LessThanExpression(transformExpression(a).get, transformExpression(l).get))
    -        case LessThan(l@Literal(v, t), a: Attribute) =>
    -          Some(new GreaterThanExpression(transformExpression(a).get, transformExpression(l).get))
    -        case LessThan(l@Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(new GreaterThanExpression(transformExpression(a).get, transformExpression(l).get))
    -
    -        case GreaterThanOrEqual(a: Attribute, l@Literal(v, t)) =>
    -          Some(new GreaterThanEqualToExpression(transformExpression(a).get,
    -            transformExpression(l).get))
    -        case GreaterThanOrEqual(Cast(a: Attribute, _), l@Literal(v, t)) =>
    -          Some(new GreaterThanEqualToExpression(transformExpression(a).get,
    -            transformExpression(l).get))
    -        case GreaterThanOrEqual(l@Literal(v, t), a: Attribute) =>
    -          Some(new LessThanEqualToExpression(transformExpression(a).get,
    -            transformExpression(l).get))
    -        case GreaterThanOrEqual(l@Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(new LessThanEqualToExpression(transformExpression(a).get,
    -            transformExpression(l).get))
    -
    -        case LessThanOrEqual(a: Attribute, l@Literal(v, t)) =>
    -          Some(new LessThanEqualToExpression(transformExpression(a).get,
    -            transformExpression(l).get))
    -        case LessThanOrEqual(Cast(a: Attribute, _), l@Literal(v, t)) =>
    -          Some(new LessThanEqualToExpression(transformExpression(a).get,
    -            transformExpression(l).get))
    -        case LessThanOrEqual(l@Literal(v, t), a: Attribute) =>
    -          Some(new GreaterThanEqualToExpression(transformExpression(a).get,
    -            transformExpression(l).get))
    -        case LessThanOrEqual(l@Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(new GreaterThanEqualToExpression(transformExpression(a).get,
    -            transformExpression(l).get))
    -
    -        case AttributeReference(name, dataType, _, _) =>
    -          Some(new CarbonColumnExpression(name,
    -            CarbonScalaUtil.convertSparkToCarbonDataType(
    -              getActualCarbonDataType(name, carbonTable))))
    -        case Literal(name, dataType) => Some(new
    -            CarbonLiteralExpression(name, CarbonScalaUtil.convertSparkToCarbonDataType(dataType)))
    -        case Cast(left, right) if !left.isInstanceOf[Literal] => transformExpression(left)
    -        case others =>
    -          if (!or) {
    -            others.collect {
    -              case attr: AttributeReference => attributesNeedToDecode.add(attr)
    -            }
    -            unprocessedExprs += others
    -          }
    -          None
    -      }
    -    }
    -    exprs.flatMap(transformExpression(_)).reduceOption(new AndExpression(_, _))
    --- End diff --
    
    The below code is different with spark-common's CarbonFilter.scala, please consider if need to keep consistent.
    `exprs.flatMap(transformExpression(_)).reduceOption(new AndExpression(_, _))`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-carbondata pull request #625: [CARBONDATA-743] Remove redundant Ca...

Posted by chenliang613 <gi...@git.apache.org>.
Github user chenliang613 commented on a diff in the pull request:

    https://github.com/apache/incubator-carbondata/pull/625#discussion_r104424526
  
    --- Diff: integration/spark2/src/main/scala/org/apache/carbondata/spark/CarbonFilters.scala ---
    @@ -1,397 +0,0 @@
    -/*
    - * 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.carbondata.spark
    -
    -import scala.collection.mutable.ArrayBuffer
    -
    -import org.apache.spark.sql.catalyst.expressions._
    -import org.apache.spark.sql.optimizer.AttributeReferenceWrapper
    -import org.apache.spark.sql.sources
    -import org.apache.spark.sql.types.StructType
    -
    -import org.apache.carbondata.core.metadata.datatype.DataType
    -import org.apache.carbondata.core.metadata.schema.table.CarbonTable
    -import org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn
    -import org.apache.carbondata.core.scan.expression.{ColumnExpression => CarbonColumnExpression, Expression => CarbonExpression, LiteralExpression => CarbonLiteralExpression}
    -import org.apache.carbondata.core.scan.expression.conditional._
    -import org.apache.carbondata.core.scan.expression.logical.{AndExpression, FalseExpression, OrExpression}
    -import org.apache.carbondata.spark.util.CarbonScalaUtil
    -
    -/**
    - * All filter conversions are done here.
    - */
    -object CarbonFilters {
    -
    -  /**
    -   * Converts data sources filters to carbon filter predicates.
    -   */
    -  def createCarbonFilter(schema: StructType,
    -      predicate: sources.Filter): Option[CarbonExpression] = {
    -    val dataTypeOf = schema.map(f => f.name -> f.dataType).toMap
    -
    -    def createFilter(predicate: sources.Filter): Option[CarbonExpression] = {
    -      predicate match {
    -
    -        case sources.EqualTo(name, value) =>
    -          Some(new EqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.Not(sources.EqualTo(name, value)) =>
    -          Some(new NotEqualsExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -
    -        case sources.EqualNullSafe(name, value) =>
    -          Some(new EqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.Not(sources.EqualNullSafe(name, value)) =>
    -          Some(new NotEqualsExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -
    -        case sources.GreaterThan(name, value) =>
    -          Some(new GreaterThanExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.LessThan(name, value) =>
    -          Some(new LessThanExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.GreaterThanOrEqual(name, value) =>
    -          Some(new GreaterThanEqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.LessThanOrEqual(name, value) =>
    -          Some(new LessThanEqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -
    -        case sources.In(name, values) =>
    -          Some(new InExpression(getCarbonExpression(name),
    -            new ListExpression(
    -              convertToJavaList(values.map(f => getCarbonLiteralExpression(name, f)).toList))))
    -        case sources.Not(sources.In(name, values)) =>
    -          Some(new NotInExpression(getCarbonExpression(name),
    -            new ListExpression(
    -              convertToJavaList(values.map(f => getCarbonLiteralExpression(name, f)).toList))))
    -
    -        case sources.IsNull(name) =>
    -          Some(new EqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, null), true))
    -        case sources.IsNotNull(name) =>
    -          Some(new NotEqualsExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, null), true))
    -        case sources.And(lhs, rhs) =>
    -          (createFilter(lhs) ++ createFilter(rhs)).reduceOption(new AndExpression(_, _))
    -
    -        case sources.Or(lhs, rhs) =>
    -          for {
    -            lhsFilter <- createFilter(lhs)
    -            rhsFilter <- createFilter(rhs)
    -          } yield {
    -            new OrExpression(lhsFilter, rhsFilter)
    -          }
    -
    -        case _ => None
    -      }
    -    }
    -
    -    def getCarbonExpression(name: String) = {
    -      new CarbonColumnExpression(name,
    -        CarbonScalaUtil.convertSparkToCarbonDataType(dataTypeOf(name)))
    -    }
    -
    -    def getCarbonLiteralExpression(name: String, value: Any): CarbonExpression = {
    -      new CarbonLiteralExpression(value,
    -        CarbonScalaUtil.convertSparkToCarbonDataType(dataTypeOf(name)))
    -    }
    -
    -    createFilter(predicate)
    -  }
    -
    -
    -  // Check out which filters can be pushed down to carbon, remaining can be handled in spark layer.
    -  // Mostly dimension filters are only pushed down since it is faster in carbon.
    -  def selectFilters(filters: Seq[Expression],
    -      attrList: java.util.HashSet[AttributeReferenceWrapper],
    -      aliasMap: CarbonAliasDecoderRelation): Unit = {
    -    def translate(expr: Expression, or: Boolean = false): Option[sources.Filter] = {
    -      expr match {
    -        case or@ Or(left, right) =>
    -
    -          val leftFilter = translate(left, or = true)
    -          val rightFilter = translate(right, or = true)
    -          if (leftFilter.isDefined && rightFilter.isDefined) {
    -            Some( sources.Or(leftFilter.get, rightFilter.get))
    -          } else {
    -            or.collect {
    -              case attr: AttributeReference =>
    -                attrList.add(AttributeReferenceWrapper(aliasMap.getOrElse(attr, attr)))
    -            }
    -            None
    -          }
    -
    -        case And(left, right) =>
    -          (translate(left) ++ translate(right)).reduceOption(sources.And)
    -
    -        case EqualTo(a: Attribute, Literal(v, t)) =>
    -          Some(sources.EqualTo(a.name, v))
    -        case EqualTo(l@Literal(v, t), a: Attribute) =>
    -          Some(sources.EqualTo(a.name, v))
    -        case EqualTo(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.EqualTo(a.name, v))
    -        case EqualTo(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.EqualTo(a.name, v))
    -
    -        case Not(EqualTo(a: Attribute, Literal(v, t))) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case Not(EqualTo(Literal(v, t), a: Attribute)) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case Not(EqualTo(Cast(a: Attribute, _), Literal(v, t))) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case Not(EqualTo(Literal(v, t), Cast(a: Attribute, _))) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case IsNotNull(a: Attribute) => Some(sources.IsNotNull(a.name))
    -        case IsNull(a: Attribute) => Some(sources.IsNull(a.name))
    -        case Not(In(a: Attribute, list)) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.Not(sources.In(a.name, hSet.toArray)))
    -        case In(a: Attribute, list) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.In(a.name, hSet.toArray))
    -        case Not(In(Cast(a: Attribute, _), list))
    -          if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.Not(sources.In(a.name, hSet.toArray)))
    -        case In(Cast(a: Attribute, _), list) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.In(a.name, hSet.toArray))
    -
    -        case GreaterThan(a: Attribute, Literal(v, t)) =>
    -          Some(sources.GreaterThan(a.name, v))
    -        case GreaterThan(Literal(v, t), a: Attribute) =>
    -          Some(sources.LessThan(a.name, v))
    -        case GreaterThan(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.GreaterThan(a.name, v))
    -        case GreaterThan(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.LessThan(a.name, v))
    -
    -        case LessThan(a: Attribute, Literal(v, t)) =>
    -          Some(sources.LessThan(a.name, v))
    -        case LessThan(Literal(v, t), a: Attribute) =>
    -          Some(sources.GreaterThan(a.name, v))
    -        case LessThan(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.LessThan(a.name, v))
    -        case LessThan(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.GreaterThan(a.name, v))
    -
    -        case GreaterThanOrEqual(a: Attribute, Literal(v, t)) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -        case GreaterThanOrEqual(Literal(v, t), a: Attribute) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -        case GreaterThanOrEqual(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -        case GreaterThanOrEqual(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -
    -        case LessThanOrEqual(a: Attribute, Literal(v, t)) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -        case LessThanOrEqual(Literal(v, t), a: Attribute) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -        case LessThanOrEqual(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -        case LessThanOrEqual(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -
    -        case others =>
    -          if (!or) {
    -            others.collect {
    -              case attr: AttributeReference =>
    -                attrList.add(AttributeReferenceWrapper(aliasMap.getOrElse(attr, attr)))
    -            }
    -          }
    -          None
    -      }
    -    }
    -    filters.flatMap(translate(_)).toArray
    --- End diff --
    
    The below code is different with spark-common's CarbonFilter.scala, please consider if need to keep consistent.
    `filters.flatMap(translate(_, false)).toArray`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-carbondata issue #625: [CARBONDATA-743] Remove redundant CarbonFil...

Posted by chenliang613 <gi...@git.apache.org>.
Github user chenliang613 commented on the issue:

    https://github.com/apache/incubator-carbondata/pull/625
  
    add to whitelist


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-carbondata issue #625: [CARBONDATA-743] Remove redundant CarbonFil...

Posted by CarbonDataQA <gi...@git.apache.org>.
Github user CarbonDataQA commented on the issue:

    https://github.com/apache/incubator-carbondata/pull/625
  
    Build Success with Spark 1.6.2, Please check CI http://136.243.101.176:8080/job/ApacheCarbonPRBuilder/1021/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-carbondata issue #625: [CARBONDATA-743] Remove redundant CarbonFil...

Posted by CarbonDataQA <gi...@git.apache.org>.
Github user CarbonDataQA commented on the issue:

    https://github.com/apache/incubator-carbondata/pull/625
  
    Can one of the admins verify this patch?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-carbondata pull request #625: [CARBONDATA-743] Remove redundant Ca...

Posted by chenliang613 <gi...@git.apache.org>.
Github user chenliang613 commented on a diff in the pull request:

    https://github.com/apache/incubator-carbondata/pull/625#discussion_r104424040
  
    --- Diff: integration/spark2/src/main/scala/org/apache/carbondata/spark/CarbonFilters.scala ---
    @@ -1,397 +0,0 @@
    -/*
    - * 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.carbondata.spark
    -
    -import scala.collection.mutable.ArrayBuffer
    -
    -import org.apache.spark.sql.catalyst.expressions._
    -import org.apache.spark.sql.optimizer.AttributeReferenceWrapper
    -import org.apache.spark.sql.sources
    -import org.apache.spark.sql.types.StructType
    -
    -import org.apache.carbondata.core.metadata.datatype.DataType
    -import org.apache.carbondata.core.metadata.schema.table.CarbonTable
    -import org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn
    -import org.apache.carbondata.core.scan.expression.{ColumnExpression => CarbonColumnExpression, Expression => CarbonExpression, LiteralExpression => CarbonLiteralExpression}
    -import org.apache.carbondata.core.scan.expression.conditional._
    -import org.apache.carbondata.core.scan.expression.logical.{AndExpression, FalseExpression, OrExpression}
    -import org.apache.carbondata.spark.util.CarbonScalaUtil
    -
    -/**
    - * All filter conversions are done here.
    - */
    -object CarbonFilters {
    -
    -  /**
    -   * Converts data sources filters to carbon filter predicates.
    -   */
    -  def createCarbonFilter(schema: StructType,
    -      predicate: sources.Filter): Option[CarbonExpression] = {
    -    val dataTypeOf = schema.map(f => f.name -> f.dataType).toMap
    -
    -    def createFilter(predicate: sources.Filter): Option[CarbonExpression] = {
    -      predicate match {
    -
    -        case sources.EqualTo(name, value) =>
    -          Some(new EqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.Not(sources.EqualTo(name, value)) =>
    -          Some(new NotEqualsExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -
    -        case sources.EqualNullSafe(name, value) =>
    -          Some(new EqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.Not(sources.EqualNullSafe(name, value)) =>
    -          Some(new NotEqualsExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -
    -        case sources.GreaterThan(name, value) =>
    -          Some(new GreaterThanExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.LessThan(name, value) =>
    -          Some(new LessThanExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.GreaterThanOrEqual(name, value) =>
    -          Some(new GreaterThanEqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.LessThanOrEqual(name, value) =>
    -          Some(new LessThanEqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -
    -        case sources.In(name, values) =>
    -          Some(new InExpression(getCarbonExpression(name),
    -            new ListExpression(
    -              convertToJavaList(values.map(f => getCarbonLiteralExpression(name, f)).toList))))
    -        case sources.Not(sources.In(name, values)) =>
    -          Some(new NotInExpression(getCarbonExpression(name),
    -            new ListExpression(
    -              convertToJavaList(values.map(f => getCarbonLiteralExpression(name, f)).toList))))
    -
    -        case sources.IsNull(name) =>
    -          Some(new EqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, null), true))
    -        case sources.IsNotNull(name) =>
    -          Some(new NotEqualsExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, null), true))
    -        case sources.And(lhs, rhs) =>
    -          (createFilter(lhs) ++ createFilter(rhs)).reduceOption(new AndExpression(_, _))
    -
    -        case sources.Or(lhs, rhs) =>
    -          for {
    -            lhsFilter <- createFilter(lhs)
    -            rhsFilter <- createFilter(rhs)
    -          } yield {
    -            new OrExpression(lhsFilter, rhsFilter)
    -          }
    -
    -        case _ => None
    -      }
    -    }
    -
    -    def getCarbonExpression(name: String) = {
    -      new CarbonColumnExpression(name,
    -        CarbonScalaUtil.convertSparkToCarbonDataType(dataTypeOf(name)))
    -    }
    -
    -    def getCarbonLiteralExpression(name: String, value: Any): CarbonExpression = {
    -      new CarbonLiteralExpression(value,
    -        CarbonScalaUtil.convertSparkToCarbonDataType(dataTypeOf(name)))
    -    }
    -
    -    createFilter(predicate)
    -  }
    -
    -
    -  // Check out which filters can be pushed down to carbon, remaining can be handled in spark layer.
    -  // Mostly dimension filters are only pushed down since it is faster in carbon.
    -  def selectFilters(filters: Seq[Expression],
    -      attrList: java.util.HashSet[AttributeReferenceWrapper],
    -      aliasMap: CarbonAliasDecoderRelation): Unit = {
    -    def translate(expr: Expression, or: Boolean = false): Option[sources.Filter] = {
    -      expr match {
    -        case or@ Or(left, right) =>
    -
    -          val leftFilter = translate(left, or = true)
    -          val rightFilter = translate(right, or = true)
    -          if (leftFilter.isDefined && rightFilter.isDefined) {
    -            Some( sources.Or(leftFilter.get, rightFilter.get))
    -          } else {
    -            or.collect {
    -              case attr: AttributeReference =>
    -                attrList.add(AttributeReferenceWrapper(aliasMap.getOrElse(attr, attr)))
    -            }
    -            None
    -          }
    -
    -        case And(left, right) =>
    -          (translate(left) ++ translate(right)).reduceOption(sources.And)
    -
    -        case EqualTo(a: Attribute, Literal(v, t)) =>
    -          Some(sources.EqualTo(a.name, v))
    -        case EqualTo(l@Literal(v, t), a: Attribute) =>
    -          Some(sources.EqualTo(a.name, v))
    -        case EqualTo(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.EqualTo(a.name, v))
    -        case EqualTo(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.EqualTo(a.name, v))
    -
    -        case Not(EqualTo(a: Attribute, Literal(v, t))) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case Not(EqualTo(Literal(v, t), a: Attribute)) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case Not(EqualTo(Cast(a: Attribute, _), Literal(v, t))) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case Not(EqualTo(Literal(v, t), Cast(a: Attribute, _))) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case IsNotNull(a: Attribute) => Some(sources.IsNotNull(a.name))
    -        case IsNull(a: Attribute) => Some(sources.IsNull(a.name))
    -        case Not(In(a: Attribute, list)) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.Not(sources.In(a.name, hSet.toArray)))
    -        case In(a: Attribute, list) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.In(a.name, hSet.toArray))
    -        case Not(In(Cast(a: Attribute, _), list))
    -          if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.Not(sources.In(a.name, hSet.toArray)))
    -        case In(Cast(a: Attribute, _), list) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.In(a.name, hSet.toArray))
    -
    -        case GreaterThan(a: Attribute, Literal(v, t)) =>
    -          Some(sources.GreaterThan(a.name, v))
    -        case GreaterThan(Literal(v, t), a: Attribute) =>
    -          Some(sources.LessThan(a.name, v))
    -        case GreaterThan(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.GreaterThan(a.name, v))
    -        case GreaterThan(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.LessThan(a.name, v))
    -
    -        case LessThan(a: Attribute, Literal(v, t)) =>
    -          Some(sources.LessThan(a.name, v))
    -        case LessThan(Literal(v, t), a: Attribute) =>
    -          Some(sources.GreaterThan(a.name, v))
    -        case LessThan(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.LessThan(a.name, v))
    -        case LessThan(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.GreaterThan(a.name, v))
    -
    -        case GreaterThanOrEqual(a: Attribute, Literal(v, t)) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -        case GreaterThanOrEqual(Literal(v, t), a: Attribute) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -        case GreaterThanOrEqual(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -        case GreaterThanOrEqual(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -
    -        case LessThanOrEqual(a: Attribute, Literal(v, t)) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -        case LessThanOrEqual(Literal(v, t), a: Attribute) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -        case LessThanOrEqual(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -        case LessThanOrEqual(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -
    -        case others =>
    -          if (!or) {
    -            others.collect {
    -              case attr: AttributeReference =>
    -                attrList.add(AttributeReferenceWrapper(aliasMap.getOrElse(attr, attr)))
    -            }
    -          }
    -          None
    -      }
    -    }
    -    filters.flatMap(translate(_)).toArray
    -  }
    -
    -  def processExpression(exprs: Seq[Expression],
    -      attributesNeedToDecode: java.util.HashSet[AttributeReference],
    -      unprocessedExprs: ArrayBuffer[Expression],
    -      carbonTable: CarbonTable): Option[CarbonExpression] = {
    -    def transformExpression(expr: Expression, or: Boolean = false): Option[CarbonExpression] = {
    -      expr match {
    -        case or@ Or(left, right) =>
    -          val leftFilter = transformExpression(left, or = true)
    --- End diff --
    
    The below code is different with spark-common's CarbonFilter.scala, please consider if need to keep consistent.
    ```
    val leftFilter = transformExpression(left, or = true)
              val rightFilter = transformExpression(right, or = true)
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-carbondata pull request #625: [CARBONDATA-743] Remove redundant Ca...

Posted by lionelcao <gi...@git.apache.org>.
Github user lionelcao closed the pull request at:

    https://github.com/apache/incubator-carbondata/pull/625


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-carbondata pull request #625: [CARBONDATA-743] Remove redundant Ca...

Posted by lionelcao <gi...@git.apache.org>.
Github user lionelcao commented on a diff in the pull request:

    https://github.com/apache/incubator-carbondata/pull/625#discussion_r104575573
  
    --- Diff: integration/spark2/src/main/scala/org/apache/carbondata/spark/CarbonFilters.scala ---
    @@ -1,397 +0,0 @@
    -/*
    - * 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.carbondata.spark
    -
    -import scala.collection.mutable.ArrayBuffer
    -
    -import org.apache.spark.sql.catalyst.expressions._
    -import org.apache.spark.sql.optimizer.AttributeReferenceWrapper
    -import org.apache.spark.sql.sources
    -import org.apache.spark.sql.types.StructType
    -
    -import org.apache.carbondata.core.metadata.datatype.DataType
    -import org.apache.carbondata.core.metadata.schema.table.CarbonTable
    -import org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn
    -import org.apache.carbondata.core.scan.expression.{ColumnExpression => CarbonColumnExpression, Expression => CarbonExpression, LiteralExpression => CarbonLiteralExpression}
    -import org.apache.carbondata.core.scan.expression.conditional._
    -import org.apache.carbondata.core.scan.expression.logical.{AndExpression, FalseExpression, OrExpression}
    -import org.apache.carbondata.spark.util.CarbonScalaUtil
    -
    -/**
    - * All filter conversions are done here.
    - */
    -object CarbonFilters {
    -
    -  /**
    -   * Converts data sources filters to carbon filter predicates.
    -   */
    -  def createCarbonFilter(schema: StructType,
    -      predicate: sources.Filter): Option[CarbonExpression] = {
    -    val dataTypeOf = schema.map(f => f.name -> f.dataType).toMap
    -
    -    def createFilter(predicate: sources.Filter): Option[CarbonExpression] = {
    -      predicate match {
    -
    -        case sources.EqualTo(name, value) =>
    -          Some(new EqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.Not(sources.EqualTo(name, value)) =>
    -          Some(new NotEqualsExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -
    -        case sources.EqualNullSafe(name, value) =>
    -          Some(new EqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.Not(sources.EqualNullSafe(name, value)) =>
    -          Some(new NotEqualsExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -
    -        case sources.GreaterThan(name, value) =>
    -          Some(new GreaterThanExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.LessThan(name, value) =>
    -          Some(new LessThanExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.GreaterThanOrEqual(name, value) =>
    -          Some(new GreaterThanEqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.LessThanOrEqual(name, value) =>
    -          Some(new LessThanEqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -
    -        case sources.In(name, values) =>
    -          Some(new InExpression(getCarbonExpression(name),
    -            new ListExpression(
    -              convertToJavaList(values.map(f => getCarbonLiteralExpression(name, f)).toList))))
    -        case sources.Not(sources.In(name, values)) =>
    -          Some(new NotInExpression(getCarbonExpression(name),
    -            new ListExpression(
    -              convertToJavaList(values.map(f => getCarbonLiteralExpression(name, f)).toList))))
    -
    -        case sources.IsNull(name) =>
    -          Some(new EqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, null), true))
    -        case sources.IsNotNull(name) =>
    -          Some(new NotEqualsExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, null), true))
    -        case sources.And(lhs, rhs) =>
    -          (createFilter(lhs) ++ createFilter(rhs)).reduceOption(new AndExpression(_, _))
    -
    -        case sources.Or(lhs, rhs) =>
    -          for {
    -            lhsFilter <- createFilter(lhs)
    -            rhsFilter <- createFilter(rhs)
    -          } yield {
    -            new OrExpression(lhsFilter, rhsFilter)
    -          }
    -
    -        case _ => None
    -      }
    -    }
    -
    -    def getCarbonExpression(name: String) = {
    -      new CarbonColumnExpression(name,
    -        CarbonScalaUtil.convertSparkToCarbonDataType(dataTypeOf(name)))
    -    }
    -
    -    def getCarbonLiteralExpression(name: String, value: Any): CarbonExpression = {
    -      new CarbonLiteralExpression(value,
    -        CarbonScalaUtil.convertSparkToCarbonDataType(dataTypeOf(name)))
    -    }
    -
    -    createFilter(predicate)
    -  }
    -
    -
    -  // Check out which filters can be pushed down to carbon, remaining can be handled in spark layer.
    -  // Mostly dimension filters are only pushed down since it is faster in carbon.
    -  def selectFilters(filters: Seq[Expression],
    -      attrList: java.util.HashSet[AttributeReferenceWrapper],
    -      aliasMap: CarbonAliasDecoderRelation): Unit = {
    -    def translate(expr: Expression, or: Boolean = false): Option[sources.Filter] = {
    -      expr match {
    -        case or@ Or(left, right) =>
    -
    -          val leftFilter = translate(left, or = true)
    -          val rightFilter = translate(right, or = true)
    -          if (leftFilter.isDefined && rightFilter.isDefined) {
    -            Some( sources.Or(leftFilter.get, rightFilter.get))
    -          } else {
    -            or.collect {
    -              case attr: AttributeReference =>
    -                attrList.add(AttributeReferenceWrapper(aliasMap.getOrElse(attr, attr)))
    -            }
    -            None
    -          }
    -
    -        case And(left, right) =>
    -          (translate(left) ++ translate(right)).reduceOption(sources.And)
    -
    -        case EqualTo(a: Attribute, Literal(v, t)) =>
    -          Some(sources.EqualTo(a.name, v))
    -        case EqualTo(l@Literal(v, t), a: Attribute) =>
    -          Some(sources.EqualTo(a.name, v))
    -        case EqualTo(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.EqualTo(a.name, v))
    -        case EqualTo(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.EqualTo(a.name, v))
    -
    -        case Not(EqualTo(a: Attribute, Literal(v, t))) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case Not(EqualTo(Literal(v, t), a: Attribute)) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case Not(EqualTo(Cast(a: Attribute, _), Literal(v, t))) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case Not(EqualTo(Literal(v, t), Cast(a: Attribute, _))) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case IsNotNull(a: Attribute) => Some(sources.IsNotNull(a.name))
    -        case IsNull(a: Attribute) => Some(sources.IsNull(a.name))
    -        case Not(In(a: Attribute, list)) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.Not(sources.In(a.name, hSet.toArray)))
    -        case In(a: Attribute, list) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.In(a.name, hSet.toArray))
    -        case Not(In(Cast(a: Attribute, _), list))
    -          if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.Not(sources.In(a.name, hSet.toArray)))
    -        case In(Cast(a: Attribute, _), list) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.In(a.name, hSet.toArray))
    -
    -        case GreaterThan(a: Attribute, Literal(v, t)) =>
    -          Some(sources.GreaterThan(a.name, v))
    -        case GreaterThan(Literal(v, t), a: Attribute) =>
    -          Some(sources.LessThan(a.name, v))
    -        case GreaterThan(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.GreaterThan(a.name, v))
    -        case GreaterThan(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.LessThan(a.name, v))
    -
    -        case LessThan(a: Attribute, Literal(v, t)) =>
    -          Some(sources.LessThan(a.name, v))
    -        case LessThan(Literal(v, t), a: Attribute) =>
    -          Some(sources.GreaterThan(a.name, v))
    -        case LessThan(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.LessThan(a.name, v))
    -        case LessThan(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.GreaterThan(a.name, v))
    -
    -        case GreaterThanOrEqual(a: Attribute, Literal(v, t)) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -        case GreaterThanOrEqual(Literal(v, t), a: Attribute) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -        case GreaterThanOrEqual(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -        case GreaterThanOrEqual(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -
    -        case LessThanOrEqual(a: Attribute, Literal(v, t)) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -        case LessThanOrEqual(Literal(v, t), a: Attribute) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -        case LessThanOrEqual(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -        case LessThanOrEqual(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -
    -        case others =>
    -          if (!or) {
    -            others.collect {
    -              case attr: AttributeReference =>
    -                attrList.add(AttributeReferenceWrapper(aliasMap.getOrElse(attr, attr)))
    -            }
    -          }
    -          None
    -      }
    -    }
    -    filters.flatMap(translate(_)).toArray
    -  }
    -
    -  def processExpression(exprs: Seq[Expression],
    -      attributesNeedToDecode: java.util.HashSet[AttributeReference],
    -      unprocessedExprs: ArrayBuffer[Expression],
    -      carbonTable: CarbonTable): Option[CarbonExpression] = {
    -    def transformExpression(expr: Expression, or: Boolean = false): Option[CarbonExpression] = {
    -      expr match {
    -        case or@ Or(left, right) =>
    -          val leftFilter = transformExpression(left, or = true)
    -          val rightFilter = transformExpression(right, or = true)
    -          if (leftFilter.isDefined && rightFilter.isDefined) {
    -            Some(new OrExpression(leftFilter.get, rightFilter.get))
    -          } else {
    -            or.collect {
    -              case attr: AttributeReference => attributesNeedToDecode.add(attr)
    -            }
    -            unprocessedExprs += or
    -            None
    -          }
    -
    -        case And(left, right) =>
    -          (transformExpression(left) ++ transformExpression(right)).reduceOption(new
    -              AndExpression(_, _))
    -
    -        case EqualTo(a: Attribute, l@Literal(v, t)) =>
    -            Some(new EqualToExpression(transformExpression(a).get, transformExpression(l).get))
    -        case EqualTo(l@Literal(v, t), a: Attribute) =>
    -            Some(new EqualToExpression(transformExpression(a).get, transformExpression(l).get))
    -        case EqualTo(Cast(a: Attribute, _), l@Literal(v, t)) =>
    -            Some(new EqualToExpression(transformExpression(a).get, transformExpression(l).get))
    -        case EqualTo(l@Literal(v, t), Cast(a: Attribute, _)) =>
    -            Some(new EqualToExpression(transformExpression(a).get, transformExpression(l).get))
    -
    -        case Not(EqualTo(a: Attribute, l@Literal(v, t))) =>
    -            Some(new NotEqualsExpression(transformExpression(a).get, transformExpression(l).get))
    -        case Not(EqualTo(l@Literal(v, t), a: Attribute)) =>
    -            Some(new NotEqualsExpression(transformExpression(a).get, transformExpression(l).get))
    -        case Not(EqualTo(Cast(a: Attribute, _), l@Literal(v, t))) =>
    -            Some(new NotEqualsExpression(transformExpression(a).get, transformExpression(l).get))
    -        case Not(EqualTo(l@Literal(v, t), Cast(a: Attribute, _))) =>
    -            Some(new NotEqualsExpression(transformExpression(a).get, transformExpression(l).get))
    -        case IsNotNull(child: Attribute) =>
    -            Some(new NotEqualsExpression(transformExpression(child).get,
    -             transformExpression(Literal(null)).get, true))
    -        case IsNull(child: Attribute) =>
    -            Some(new EqualToExpression(transformExpression(child).get,
    -             transformExpression(Literal(null)).get, true))
    -        case Not(In(a: Attribute, list))
    -          if !list.exists(!_.isInstanceOf[Literal]) =>
    -          if (list.exists(x => isNullLiteral(x.asInstanceOf[Literal]))) {
    -            Some(new FalseExpression(transformExpression(a).get))
    -          } else {
    -            Some(new NotInExpression(transformExpression(a).get,
    -              new ListExpression(convertToJavaList(list.map(transformExpression(_).get)))))
    -          }
    -        case In(a: Attribute, list) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          Some(new InExpression(transformExpression(a).get,
    -            new ListExpression(convertToJavaList(list.map(transformExpression(_).get)))))
    -        case Not(In(Cast(a: Attribute, _), list))
    -          if !list.exists(!_.isInstanceOf[Literal]) =>
    -          /* if any illogical expression comes in NOT IN Filter like
    -           NOT IN('scala',NULL) this will be treated as false expression and will
    -           always return no result. */
    -          if (list.exists(x => isNullLiteral(x.asInstanceOf[Literal]))) {
    -            Some(new FalseExpression(transformExpression(a).get))
    -          } else {
    -            Some(new NotInExpression(transformExpression(a).get, new ListExpression(
    -              convertToJavaList(list.map(transformExpression(_).get)))))
    -          }
    -        case In(Cast(a: Attribute, _), list) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          Some(new InExpression(transformExpression(a).get,
    -            new ListExpression(convertToJavaList(list.map(transformExpression(_).get)))))
    -
    -        case GreaterThan(a: Attribute, l@Literal(v, t)) =>
    -          Some(new GreaterThanExpression(transformExpression(a).get, transformExpression(l).get))
    -        case GreaterThan(Cast(a: Attribute, _), l@Literal(v, t)) =>
    -          Some(new GreaterThanExpression(transformExpression(a).get, transformExpression(l).get))
    -        case GreaterThan(l@Literal(v, t), a: Attribute) =>
    -          Some(new LessThanExpression(transformExpression(a).get, transformExpression(l).get))
    -        case GreaterThan(l@Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(new LessThanExpression(transformExpression(a).get, transformExpression(l).get))
    -
    -        case LessThan(a: Attribute, l@Literal(v, t)) =>
    -          Some(new LessThanExpression(transformExpression(a).get, transformExpression(l).get))
    -        case LessThan(Cast(a: Attribute, _), l@Literal(v, t)) =>
    -          Some(new LessThanExpression(transformExpression(a).get, transformExpression(l).get))
    -        case LessThan(l@Literal(v, t), a: Attribute) =>
    -          Some(new GreaterThanExpression(transformExpression(a).get, transformExpression(l).get))
    -        case LessThan(l@Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(new GreaterThanExpression(transformExpression(a).get, transformExpression(l).get))
    -
    -        case GreaterThanOrEqual(a: Attribute, l@Literal(v, t)) =>
    -          Some(new GreaterThanEqualToExpression(transformExpression(a).get,
    -            transformExpression(l).get))
    -        case GreaterThanOrEqual(Cast(a: Attribute, _), l@Literal(v, t)) =>
    -          Some(new GreaterThanEqualToExpression(transformExpression(a).get,
    -            transformExpression(l).get))
    -        case GreaterThanOrEqual(l@Literal(v, t), a: Attribute) =>
    -          Some(new LessThanEqualToExpression(transformExpression(a).get,
    -            transformExpression(l).get))
    -        case GreaterThanOrEqual(l@Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(new LessThanEqualToExpression(transformExpression(a).get,
    -            transformExpression(l).get))
    -
    -        case LessThanOrEqual(a: Attribute, l@Literal(v, t)) =>
    -          Some(new LessThanEqualToExpression(transformExpression(a).get,
    -            transformExpression(l).get))
    -        case LessThanOrEqual(Cast(a: Attribute, _), l@Literal(v, t)) =>
    -          Some(new LessThanEqualToExpression(transformExpression(a).get,
    -            transformExpression(l).get))
    -        case LessThanOrEqual(l@Literal(v, t), a: Attribute) =>
    -          Some(new GreaterThanEqualToExpression(transformExpression(a).get,
    -            transformExpression(l).get))
    -        case LessThanOrEqual(l@Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(new GreaterThanEqualToExpression(transformExpression(a).get,
    -            transformExpression(l).get))
    -
    -        case AttributeReference(name, dataType, _, _) =>
    -          Some(new CarbonColumnExpression(name,
    -            CarbonScalaUtil.convertSparkToCarbonDataType(
    -              getActualCarbonDataType(name, carbonTable))))
    -        case Literal(name, dataType) => Some(new
    -            CarbonLiteralExpression(name, CarbonScalaUtil.convertSparkToCarbonDataType(dataType)))
    -        case Cast(left, right) if !left.isInstanceOf[Literal] => transformExpression(left)
    -        case others =>
    -          if (!or) {
    -            others.collect {
    -              case attr: AttributeReference => attributesNeedToDecode.add(attr)
    -            }
    -            unprocessedExprs += others
    -          }
    -          None
    -      }
    -    }
    -    exprs.flatMap(transformExpression(_)).reduceOption(new AndExpression(_, _))
    --- End diff --
    
    The 2nd parameter in transformExpression() is false by default thus transformExpression(_) equals to transformExpression(_, false).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-carbondata pull request #625: [CARBONDATA-743] Remove redundant Ca...

Posted by lionelcao <gi...@git.apache.org>.
Github user lionelcao commented on a diff in the pull request:

    https://github.com/apache/incubator-carbondata/pull/625#discussion_r104578046
  
    --- Diff: integration/spark2/src/main/scala/org/apache/carbondata/spark/CarbonFilters.scala ---
    @@ -1,397 +0,0 @@
    -/*
    - * 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.carbondata.spark
    -
    -import scala.collection.mutable.ArrayBuffer
    -
    -import org.apache.spark.sql.catalyst.expressions._
    -import org.apache.spark.sql.optimizer.AttributeReferenceWrapper
    -import org.apache.spark.sql.sources
    -import org.apache.spark.sql.types.StructType
    -
    -import org.apache.carbondata.core.metadata.datatype.DataType
    -import org.apache.carbondata.core.metadata.schema.table.CarbonTable
    -import org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn
    -import org.apache.carbondata.core.scan.expression.{ColumnExpression => CarbonColumnExpression, Expression => CarbonExpression, LiteralExpression => CarbonLiteralExpression}
    -import org.apache.carbondata.core.scan.expression.conditional._
    -import org.apache.carbondata.core.scan.expression.logical.{AndExpression, FalseExpression, OrExpression}
    -import org.apache.carbondata.spark.util.CarbonScalaUtil
    -
    -/**
    - * All filter conversions are done here.
    - */
    -object CarbonFilters {
    -
    -  /**
    -   * Converts data sources filters to carbon filter predicates.
    -   */
    -  def createCarbonFilter(schema: StructType,
    -      predicate: sources.Filter): Option[CarbonExpression] = {
    -    val dataTypeOf = schema.map(f => f.name -> f.dataType).toMap
    -
    -    def createFilter(predicate: sources.Filter): Option[CarbonExpression] = {
    -      predicate match {
    -
    -        case sources.EqualTo(name, value) =>
    -          Some(new EqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.Not(sources.EqualTo(name, value)) =>
    -          Some(new NotEqualsExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -
    -        case sources.EqualNullSafe(name, value) =>
    -          Some(new EqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.Not(sources.EqualNullSafe(name, value)) =>
    -          Some(new NotEqualsExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -
    -        case sources.GreaterThan(name, value) =>
    -          Some(new GreaterThanExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.LessThan(name, value) =>
    -          Some(new LessThanExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.GreaterThanOrEqual(name, value) =>
    -          Some(new GreaterThanEqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -        case sources.LessThanOrEqual(name, value) =>
    -          Some(new LessThanEqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, value)))
    -
    -        case sources.In(name, values) =>
    -          Some(new InExpression(getCarbonExpression(name),
    -            new ListExpression(
    -              convertToJavaList(values.map(f => getCarbonLiteralExpression(name, f)).toList))))
    -        case sources.Not(sources.In(name, values)) =>
    -          Some(new NotInExpression(getCarbonExpression(name),
    -            new ListExpression(
    -              convertToJavaList(values.map(f => getCarbonLiteralExpression(name, f)).toList))))
    -
    -        case sources.IsNull(name) =>
    -          Some(new EqualToExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, null), true))
    -        case sources.IsNotNull(name) =>
    -          Some(new NotEqualsExpression(getCarbonExpression(name),
    -            getCarbonLiteralExpression(name, null), true))
    -        case sources.And(lhs, rhs) =>
    -          (createFilter(lhs) ++ createFilter(rhs)).reduceOption(new AndExpression(_, _))
    -
    -        case sources.Or(lhs, rhs) =>
    -          for {
    -            lhsFilter <- createFilter(lhs)
    -            rhsFilter <- createFilter(rhs)
    -          } yield {
    -            new OrExpression(lhsFilter, rhsFilter)
    -          }
    -
    -        case _ => None
    -      }
    -    }
    -
    -    def getCarbonExpression(name: String) = {
    -      new CarbonColumnExpression(name,
    -        CarbonScalaUtil.convertSparkToCarbonDataType(dataTypeOf(name)))
    -    }
    -
    -    def getCarbonLiteralExpression(name: String, value: Any): CarbonExpression = {
    -      new CarbonLiteralExpression(value,
    -        CarbonScalaUtil.convertSparkToCarbonDataType(dataTypeOf(name)))
    -    }
    -
    -    createFilter(predicate)
    -  }
    -
    -
    -  // Check out which filters can be pushed down to carbon, remaining can be handled in spark layer.
    -  // Mostly dimension filters are only pushed down since it is faster in carbon.
    -  def selectFilters(filters: Seq[Expression],
    -      attrList: java.util.HashSet[AttributeReferenceWrapper],
    -      aliasMap: CarbonAliasDecoderRelation): Unit = {
    -    def translate(expr: Expression, or: Boolean = false): Option[sources.Filter] = {
    -      expr match {
    -        case or@ Or(left, right) =>
    -
    -          val leftFilter = translate(left, or = true)
    -          val rightFilter = translate(right, or = true)
    -          if (leftFilter.isDefined && rightFilter.isDefined) {
    -            Some( sources.Or(leftFilter.get, rightFilter.get))
    -          } else {
    -            or.collect {
    -              case attr: AttributeReference =>
    -                attrList.add(AttributeReferenceWrapper(aliasMap.getOrElse(attr, attr)))
    -            }
    -            None
    -          }
    -
    -        case And(left, right) =>
    -          (translate(left) ++ translate(right)).reduceOption(sources.And)
    -
    -        case EqualTo(a: Attribute, Literal(v, t)) =>
    -          Some(sources.EqualTo(a.name, v))
    -        case EqualTo(l@Literal(v, t), a: Attribute) =>
    -          Some(sources.EqualTo(a.name, v))
    -        case EqualTo(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.EqualTo(a.name, v))
    -        case EqualTo(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.EqualTo(a.name, v))
    -
    -        case Not(EqualTo(a: Attribute, Literal(v, t))) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case Not(EqualTo(Literal(v, t), a: Attribute)) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case Not(EqualTo(Cast(a: Attribute, _), Literal(v, t))) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case Not(EqualTo(Literal(v, t), Cast(a: Attribute, _))) =>
    -            Some(sources.Not(sources.EqualTo(a.name, v)))
    -        case IsNotNull(a: Attribute) => Some(sources.IsNotNull(a.name))
    -        case IsNull(a: Attribute) => Some(sources.IsNull(a.name))
    -        case Not(In(a: Attribute, list)) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.Not(sources.In(a.name, hSet.toArray)))
    -        case In(a: Attribute, list) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.In(a.name, hSet.toArray))
    -        case Not(In(Cast(a: Attribute, _), list))
    -          if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.Not(sources.In(a.name, hSet.toArray)))
    -        case In(Cast(a: Attribute, _), list) if !list.exists(!_.isInstanceOf[Literal]) =>
    -          val hSet = list.map(e => e.eval(EmptyRow))
    -          Some(sources.In(a.name, hSet.toArray))
    -
    -        case GreaterThan(a: Attribute, Literal(v, t)) =>
    -          Some(sources.GreaterThan(a.name, v))
    -        case GreaterThan(Literal(v, t), a: Attribute) =>
    -          Some(sources.LessThan(a.name, v))
    -        case GreaterThan(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.GreaterThan(a.name, v))
    -        case GreaterThan(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.LessThan(a.name, v))
    -
    -        case LessThan(a: Attribute, Literal(v, t)) =>
    -          Some(sources.LessThan(a.name, v))
    -        case LessThan(Literal(v, t), a: Attribute) =>
    -          Some(sources.GreaterThan(a.name, v))
    -        case LessThan(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.LessThan(a.name, v))
    -        case LessThan(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.GreaterThan(a.name, v))
    -
    -        case GreaterThanOrEqual(a: Attribute, Literal(v, t)) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -        case GreaterThanOrEqual(Literal(v, t), a: Attribute) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -        case GreaterThanOrEqual(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -        case GreaterThanOrEqual(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -
    -        case LessThanOrEqual(a: Attribute, Literal(v, t)) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -        case LessThanOrEqual(Literal(v, t), a: Attribute) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -        case LessThanOrEqual(Cast(a: Attribute, _), Literal(v, t)) =>
    -          Some(sources.LessThanOrEqual(a.name, v))
    -        case LessThanOrEqual(Literal(v, t), Cast(a: Attribute, _)) =>
    -          Some(sources.GreaterThanOrEqual(a.name, v))
    -
    -        case others =>
    -          if (!or) {
    -            others.collect {
    -              case attr: AttributeReference =>
    -                attrList.add(AttributeReferenceWrapper(aliasMap.getOrElse(attr, attr)))
    -            }
    -          }
    -          None
    -      }
    -    }
    -    filters.flatMap(translate(_)).toArray
    -  }
    -
    -  def processExpression(exprs: Seq[Expression],
    -      attributesNeedToDecode: java.util.HashSet[AttributeReference],
    -      unprocessedExprs: ArrayBuffer[Expression],
    -      carbonTable: CarbonTable): Option[CarbonExpression] = {
    -    def transformExpression(expr: Expression, or: Boolean = false): Option[CarbonExpression] = {
    -      expr match {
    -        case or@ Or(left, right) =>
    -          val leftFilter = transformExpression(left, or = true)
    --- End diff --
    
    transformExpression(left, or = true)  equals to transformExpression(left, true) here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-carbondata issue #625: [CARBONDATA-743] Remove redundant CarbonFil...

Posted by CarbonDataQA <gi...@git.apache.org>.
Github user CarbonDataQA commented on the issue:

    https://github.com/apache/incubator-carbondata/pull/625
  
    Build Success with Spark 1.6.2, Please check CI http://136.243.101.176:8080/job/ApacheCarbonPRBuilder/1014/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---