Skip to content

Commit db84e25

Browse files
committed
fix review comments
1 parent 47f6534 commit db84e25

File tree

3 files changed

+67
-42
lines changed

3 files changed

+67
-42
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@ import scala.collection.mutable.ArrayBuffer
2222

2323
import org.apache.spark.sql.AnalysisException
2424
import org.apache.spark.sql.catalyst.{CatalystConf, ScalaReflection, SimpleCatalystConf}
25-
import org.apache.spark.sql.catalyst.catalog.{CatalogDatabase, CatalogRelation, InMemoryCatalog, SessionCatalog}
25+
import org.apache.spark.sql.catalyst.catalog.{CatalogDatabase, InMemoryCatalog, SessionCatalog}
2626
import org.apache.spark.sql.catalyst.encoders.OuterScopes
2727
import org.apache.spark.sql.catalyst.expressions._
2828
import org.apache.spark.sql.catalyst.expressions.aggregate._
2929
import org.apache.spark.sql.catalyst.expressions.objects.NewInstance
3030
import org.apache.spark.sql.catalyst.optimizer.BooleanSimplification
31-
import org.apache.spark.sql.catalyst.planning.IntegerIndex
3231
import org.apache.spark.sql.catalyst.plans._
3332
import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, _}
3433
import org.apache.spark.sql.catalyst.rules._
35-
import org.apache.spark.sql.catalyst.trees.{CurrentOrigin, Origin, TreeNodeRef}
34+
import org.apache.spark.sql.catalyst.trees.{TreeNodeRef}
3635
import org.apache.spark.sql.catalyst.util.toPrettySQL
3736
import org.apache.spark.sql.types._
3837

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisSuite.scala

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -377,43 +377,4 @@ class AnalysisSuite extends AnalysisTest {
377377
assertExpressionType(sum(Divide(Decimal(1), 2.0)), DoubleType)
378378
assertExpressionType(sum(Divide(1.0, Decimal(2.0))), DoubleType)
379379
}
380-
381-
test("test rule UnresolvedOrdinalSubstitution, replaces ordinal in order by or group by") {
382-
val a = testRelation2.output(0)
383-
val b = testRelation2.output(1)
384-
val conf = new SimpleCatalystConf(caseSensitiveAnalysis = true)
385-
386-
// Expression OrderByOrdinal is unresolved.
387-
assert(!UnresolvedOrdinal(0).resolved)
388-
389-
// Tests order by ordinal, apply single rule.
390-
val plan = testRelation2.orderBy(Literal(1).asc, Literal(2).asc)
391-
comparePlans(
392-
new UnresolvedOrdinalSubstitution(conf).apply(plan),
393-
testRelation2.orderBy(UnresolvedOrdinal(1).asc, UnresolvedOrdinal(2).asc))
394-
395-
// Tests order by ordinal, do full analysis
396-
checkAnalysis(plan, testRelation2.orderBy(a.asc, b.asc))
397-
398-
// order by ordinal can be turned off by config
399-
comparePlans(
400-
new UnresolvedOrdinalSubstitution(conf.copy(orderByOrdinal = false)).apply(plan),
401-
testRelation2.orderBy(Literal(1).asc, Literal(2).asc))
402-
403-
404-
// Tests group by ordinal, apply single rule.
405-
val plan2 = testRelation2.groupBy(Literal(1), Literal(2))('a, 'b)
406-
comparePlans(
407-
new UnresolvedOrdinalSubstitution(conf).apply(plan2),
408-
testRelation2.groupBy(UnresolvedOrdinal(1), UnresolvedOrdinal(2))('a, 'b))
409-
410-
// Tests group by ordinal, do full analysis
411-
checkAnalysis(plan2, testRelation2.groupBy(a, b)(a, b))
412-
413-
// group by ordinal can be turned off by config
414-
comparePlans(
415-
new UnresolvedOrdinalSubstitution(conf.copy(groupByOrdinal = false)).apply(plan2),
416-
testRelation2.groupBy(Literal(1), Literal(2))('a, 'b))
417-
418-
}
419380
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.sql.catalyst.analysis
19+
20+
import org.apache.spark.sql.catalyst.analysis.TestRelations.testRelation2
21+
import org.apache.spark.sql.catalyst.dsl.expressions._
22+
import org.apache.spark.sql.catalyst.dsl.plans._
23+
import org.apache.spark.sql.catalyst.expressions.Literal
24+
import org.apache.spark.sql.catalyst.SimpleCatalystConf
25+
26+
class UnresolvedOrdinalSubstitutionSuite extends AnalysisTest {
27+
28+
test("test rule UnresolvedOrdinalSubstitution, replaces ordinal in order by or group by") {
29+
val a = testRelation2.output(0)
30+
val b = testRelation2.output(1)
31+
val conf = new SimpleCatalystConf(caseSensitiveAnalysis = true)
32+
33+
// Expression OrderByOrdinal is unresolved.
34+
assert(!UnresolvedOrdinal(0).resolved)
35+
36+
// Tests order by ordinal, apply single rule.
37+
val plan = testRelation2.orderBy(Literal(1).asc, Literal(2).asc)
38+
comparePlans(
39+
new UnresolvedOrdinalSubstitution(conf).apply(plan),
40+
testRelation2.orderBy(UnresolvedOrdinal(1).asc, UnresolvedOrdinal(2).asc))
41+
42+
// Tests order by ordinal, do full analysis
43+
checkAnalysis(plan, testRelation2.orderBy(a.asc, b.asc))
44+
45+
// order by ordinal can be turned off by config
46+
comparePlans(
47+
new UnresolvedOrdinalSubstitution(conf.copy(orderByOrdinal = false)).apply(plan),
48+
testRelation2.orderBy(Literal(1).asc, Literal(2).asc))
49+
50+
51+
// Tests group by ordinal, apply single rule.
52+
val plan2 = testRelation2.groupBy(Literal(1), Literal(2))('a, 'b)
53+
comparePlans(
54+
new UnresolvedOrdinalSubstitution(conf).apply(plan2),
55+
testRelation2.groupBy(UnresolvedOrdinal(1), UnresolvedOrdinal(2))('a, 'b))
56+
57+
// Tests group by ordinal, do full analysis
58+
checkAnalysis(plan2, testRelation2.groupBy(a, b)(a, b))
59+
60+
// group by ordinal can be turned off by config
61+
comparePlans(
62+
new UnresolvedOrdinalSubstitution(conf.copy(groupByOrdinal = false)).apply(plan2),
63+
testRelation2.groupBy(Literal(1), Literal(2))('a, 'b))
64+
}
65+
}

0 commit comments

Comments
 (0)