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

    https://github.com/apache/spark/pull/20560#discussion_r180389285
  
    --- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/RemoveRedundantSortsSuite.scala
 ---
    @@ -0,0 +1,93 @@
    +/*
    + * 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.spark.sql.catalyst.optimizer
    +
    +import org.apache.spark.sql.catalyst.analysis.{Analyzer, 
EmptyFunctionRegistry}
    +import org.apache.spark.sql.catalyst.catalog.{InMemoryCatalog, 
SessionCatalog}
    +import org.apache.spark.sql.catalyst.dsl.expressions._
    +import org.apache.spark.sql.catalyst.dsl.plans._
    +import org.apache.spark.sql.catalyst.expressions._
    +import org.apache.spark.sql.catalyst.plans._
    +import org.apache.spark.sql.catalyst.plans.logical._
    +import org.apache.spark.sql.catalyst.rules._
    +import org.apache.spark.sql.internal.SQLConf
    +import org.apache.spark.sql.internal.SQLConf.{CASE_SENSITIVE, 
ORDER_BY_ORDINAL}
    +
    +class RemoveRedundantSortsSuite extends PlanTest {
    +  override val conf = new SQLConf().copy(CASE_SENSITIVE -> true, 
ORDER_BY_ORDINAL -> false)
    +  val catalog = new SessionCatalog(new InMemoryCatalog, 
EmptyFunctionRegistry, conf)
    +  val analyzer = new Analyzer(catalog, conf)
    +
    +  object Optimize extends RuleExecutor[LogicalPlan] {
    +    val batches =
    +      Batch("Remove Redundant Sorts", Once,
    +        RemoveRedundantSorts) ::
    +      Batch("Collapse Project", Once,
    +        CollapseProject) :: Nil
    +  }
    +
    +  val testRelation = LocalRelation('a.int, 'b.int, 'c.int)
    +
    +  test("remove redundant order by") {
    +    val orderedPlan = testRelation.select('a, 'b).orderBy('a.asc, 
'b.desc_nullsFirst)
    +    val unnecessaryReordered = orderedPlan.select('a).orderBy('a.asc, 
'b.desc_nullsFirst)
    +    val optimized = 
Optimize.execute(analyzer.execute(unnecessaryReordered))
    --- End diff --
    
    just use `unnecessaryReordered.analyze`?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to