Skip to content

Commit

Permalink
[SPARK-27252][SQL][FOLLOWUP] Calculate min and max days independently…
Browse files Browse the repository at this point in the history
… from time zone in ComputeCurrentTimeSuite

## What changes were proposed in this pull request?

This fixes the `analyzer should replace current_date with literals` test in `ComputeCurrentTimeSuite` by making calculation of `min` and `max` days independent from time zone.

## How was this patch tested?

by `ComputeCurrentTimeSuite`.

Closes #24240 from MaxGekk/current-date-followup.

Authored-by: Maxim Gekk <max.gekk@gmail.com>
Signed-off-by: Sean Owen <sean.owen@databricks.com>
  • Loading branch information
MaxGekk authored and srowen committed Mar 29, 2019
1 parent dbc7ce1 commit 61561c1
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@

package org.apache.spark.sql.catalyst.optimizer

import java.util.concurrent.TimeUnit.MILLISECONDS

import org.apache.spark.sql.catalyst.dsl.plans._
import org.apache.spark.sql.catalyst.expressions.{Alias, CurrentDate, CurrentTimestamp, Literal}
import org.apache.spark.sql.catalyst.plans.PlanTest
import org.apache.spark.sql.catalyst.plans.logical.{LocalRelation, LogicalPlan, Project}
import org.apache.spark.sql.catalyst.rules.RuleExecutor
import org.apache.spark.sql.catalyst.util.DateTimeUtils

class ComputeCurrentTimeSuite extends PlanTest {
object Optimize extends RuleExecutor[LogicalPlan] {
Expand Down Expand Up @@ -51,9 +52,9 @@ class ComputeCurrentTimeSuite extends PlanTest {
test("analyzer should replace current_date with literals") {
val in = Project(Seq(Alias(CurrentDate(), "a")(), Alias(CurrentDate(), "b")()), LocalRelation())

val min = DateTimeUtils.millisToDays(System.currentTimeMillis())
val min = MILLISECONDS.toDays(System.currentTimeMillis())
val plan = Optimize.execute(in.analyze).asInstanceOf[Project]
val max = DateTimeUtils.millisToDays(System.currentTimeMillis())
val max = MILLISECONDS.toDays(System.currentTimeMillis())

val lits = new scala.collection.mutable.ArrayBuffer[Int]
plan.transformAllExpressions { case e: Literal =>
Expand Down

0 comments on commit 61561c1

Please sign in to comment.