def foldFilter()

in src/spark-project/spark-common/src/main/scala/org/apache/spark/sql/execution/datasource/FilePruner.scala [813:888]


  def foldFilter(filter: Filter): Filter = {

    def getDataType(col: String, value: Any): DataType = {
      if (value.isInstanceOf[Date] || value.isInstanceOf[Timestamp]) return DataType.getType("date")
      dimCols.get(col.toInt).getType
    }

    filter match {
      case EqualTo(id, value: Any) =>
        val col = escapeQuote(id)
        hitColumns.add(col)
        insurance(col, value) {
          ts => {
            val dataType = getDataType(col, value)
            Trivial(dataType.compare(ts.toString, dimRange.get(col).getMin) >= 0
              && dataType.compare(ts.toString, dimRange.get(col).getMax) <= 0)
          }
        }
      case In(id, values: Array[Any]) =>
        val col = escapeQuote(id)
        hitColumns.add(col)
        val satisfied = values.map(v => insurance(col, v) {
          ts => {
            val dataType = getDataType(col, v)
            Trivial(dataType.compare(ts.toString, dimRange.get(col).getMin) >= 0
              && dataType.compare(ts.toString, dimRange.get(col).getMax) <= 0)
          }
        }).exists(_.equals(Trivial(true)))
        Trivial(satisfied)

      case IsNull(_) =>
        Trivial(true)
      case IsNotNull(_) =>
        Trivial(true)
      case GreaterThan(id, value: Any) =>
        val col = escapeQuote(id)
        insurance(col, value) {
          ts => Trivial(getDataType(col, value).compare(ts.toString, dimRange.get(col).getMax) < 0)
        }
      case GreaterThanOrEqual(id, value: Any) =>
        val col = escapeQuote(id)
        insurance(col, value) {
          ts => Trivial(getDataType(col, value).compare(ts.toString, dimRange.get(col).getMax) <= 0)
        }
      case LessThan(id, value: Any) =>
        val col = escapeQuote(id)
        insurance(col, value) {
          ts => Trivial(getDataType(col, value).compare(ts.toString, dimRange.get(col).getMin) > 0)
        }
      case LessThanOrEqual(id, value: Any) =>
        val col = escapeQuote(id)
        insurance(col, value) {
          ts => Trivial(getDataType(col, value).compare(ts.toString, dimRange.get(col).getMin) >= 0)
        }
      case And(left: Filter, right: Filter) =>
        And(foldFilter(left), foldFilter(right)) match {
          case And(Trivial(false), _) => Trivial(false)
          case And(_, Trivial(false)) => Trivial(false)
          case And(Trivial(true), right) => right
          case And(left, Trivial(true)) => left
          case other => other
        }
      case Or(left: Filter, right: Filter) =>
        Or(foldFilter(left), foldFilter(right)) match {
          case Or(Trivial(true), _) => Trivial(true)
          case Or(_, Trivial(true)) => Trivial(true)
          case Or(Trivial(false), right) => right
          case Or(left, Trivial(false)) => left
          case other => other
        }
      case trivial: Trivial =>
        trivial
      case _ =>
        Trivial(true)
    }
  }