Skip to content

Instantly share code, notes, and snippets.

@SingularBunny
Created November 20, 2019 18:24
Show Gist options
  • Save SingularBunny/66706216608457fc7ecda05332086e2c to your computer and use it in GitHub Desktop.
Save SingularBunny/66706216608457fc7ecda05332086e2c to your computer and use it in GitHub Desktop.
class AggregateOptimizeSuite extends PlanTest {
override val conf = new SQLConf().copy(CASE_SENSITIVE -> false, GROUP_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("Aggregate", FixedPoint(100),
FoldablePropagation,
RemoveLiteralFromGroupExpressions,
RemoveRepetitionFromGroupExpressions) :: Nil
}
val testRelation = LocalRelation('a.int, 'b.int, 'c.int)
test("remove literals in grouping expression") {
val query = testRelation.groupBy('a, Literal("1"), Literal(1) + Literal(2))(sum('b))
val optimized = Optimize.execute(analyzer.execute(query))
val correctAnswer = testRelation.groupBy('a)(sum('b)).analyze
comparePlans(optimized, correctAnswer)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment