Skip to content

Commit 0d334e3

Browse files
committed
add ut
1 parent c4aaa8d commit 0d334e3

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,23 @@
1717

1818
package org.apache.spark.sql.catalyst.analysis
1919

20-
import java.util.TimeZone
20+
import java.util.{Locale, TimeZone}
2121

2222
import scala.reflect.ClassTag
2323

2424
import org.scalatest.Matchers
2525

2626
import org.apache.spark.api.python.PythonEvalType
2727
import org.apache.spark.sql.catalyst.TableIdentifier
28+
import org.apache.spark.sql.catalyst.catalog.{CatalogStorageFormat, CatalogTable, CatalogTableType}
2829
import org.apache.spark.sql.catalyst.dsl.expressions._
2930
import org.apache.spark.sql.catalyst.dsl.plans._
3031
import org.apache.spark.sql.catalyst.expressions._
3132
import org.apache.spark.sql.catalyst.plans.{Cross, Inner}
3233
import org.apache.spark.sql.catalyst.plans.logical._
3334
import org.apache.spark.sql.catalyst.plans.physical.{HashPartitioning, Partitioning,
3435
RangePartitioning, RoundRobinPartitioning}
36+
import org.apache.spark.sql.catalyst.rules.RuleExecutor
3537
import org.apache.spark.sql.catalyst.util._
3638
import org.apache.spark.sql.internal.SQLConf
3739
import org.apache.spark.sql.types._
@@ -604,4 +606,28 @@ class AnalysisSuite extends AnalysisTest with Matchers {
604606
checkAnalysis(input, expected)
605607
}
606608
}
609+
610+
test("SPARK-25691: AliasViewChild with different nullabilities") {
611+
object ViewAnalyzer extends RuleExecutor[LogicalPlan] {
612+
val batches = Batch("View", Once, AliasViewChild(conf), EliminateView) :: Nil
613+
}
614+
def intNotNullableAttr(name: String): Attribute = {
615+
AttributeReference(name, IntegerType, nullable = false)()
616+
}
617+
val relation = LocalRelation(intNotNullableAttr("a"), 'b.string)
618+
val view = View(CatalogTable(
619+
identifier = TableIdentifier("v1"),
620+
tableType = CatalogTableType.VIEW,
621+
storage = CatalogStorageFormat.empty,
622+
schema = StructType(Seq(StructField("a", IntegerType), StructField("b", StringType)))),
623+
output = Seq('a.int, 'b.string),
624+
child = relation)
625+
val tz = Option(conf.sessionLocalTimeZone)
626+
val expected = Project(Seq(
627+
Alias(Cast(intNotNullableAttr("a"), IntegerType, tz), "a")(),
628+
Alias(Cast('b.string, StringType, tz), "b")()),
629+
relation)
630+
val res = ViewAnalyzer.execute(view)
631+
comparePlans(res, expected)
632+
}
607633
}

0 commit comments

Comments
 (0)