From 7235f4a731f83a3a81fd65846179efaf38354bfa Mon Sep 17 00:00:00 2001 From: setjet Date: Wed, 24 May 2017 01:20:30 +0100 Subject: [PATCH 1/5] added additional weekofyear function --- .../catalyst/analysis/FunctionRegistry.scala | 1 + .../expressions/datetimeExpressions.scala | 51 ++++++++++++++++++- .../expressions/DateExpressionsSuite.scala | 16 +++++- 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala index d2042ad00a81..78fd48d27a2a 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala @@ -358,6 +358,7 @@ object FunctionRegistry { expression[TruncDate]("trunc"), expression[UnixTimestamp]("unix_timestamp"), expression[WeekOfYear]("weekofyear"), + expression[WeekOfYearISO8601]("weekofyear_iso8601"), expression[Year]("year"), expression[TimeWindow]("window"), diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala index 43ca2cff5882..e2bfb3783b2c 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala @@ -402,14 +402,17 @@ case class DayOfMonth(child: Expression) extends UnaryExpression with ImplicitCa } } +// scalastyle:off line.size.limit @ExpressionDescription( - usage = "_FUNC_(date) - Returns the week of the year of the given date.", + usage = "_FUNC_(date) - Returns the week of the year of the given date according to the ISO 8601 standard", extended = """ Examples: > SELECT _FUNC_('2008-02-20'); 8 """) -case class WeekOfYear(child: Expression) extends UnaryExpression with ImplicitCastInputTypes { +// scalastyle:on line.size.limit +case class WeekOfYearISO8601(child: Expression) extends + UnaryExpression with ImplicitCastInputTypes { override def inputTypes: Seq[AbstractDataType] = Seq(DateType) @@ -446,6 +449,50 @@ case class WeekOfYear(child: Expression) extends UnaryExpression with ImplicitCa } } +// scalastyle:off line.size.limit +@ExpressionDescription( + usage = "_FUNC_(date) - Returns the week of the year of the given date, where the first day of the year is always in week 1", + extended = """ + Examples: + > SELECT _FUNC_('2017-01-01'); + 8 + """) +// scalastyle:on line.size.limit +case class WeekOfYear(child: Expression) extends UnaryExpression with ImplicitCastInputTypes { + + override def inputTypes: Seq[AbstractDataType] = Seq(DateType) + + override def dataType: DataType = IntegerType + + @transient private lazy val c = { + val c = Calendar.getInstance(DateTimeUtils.getTimeZone("UTC")) + c.setMinimalDaysInFirstWeek(1) + c + } + + override protected def nullSafeEval(date: Any): Any = { + c.setTimeInMillis(date.asInstanceOf[Int] * 1000L * 3600L * 24L) + c.get(Calendar.WEEK_OF_YEAR) + } + + override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = { + nullSafeCodeGen(ctx, ev, time => { + val cal = classOf[Calendar].getName + val c = ctx.freshName("cal") + val dtu = DateTimeUtils.getClass.getName.stripSuffix("$") + ctx.addMutableState(cal, c, + s""" + $c = $cal.getInstance($dtu.getTimeZone("UTC")); + $c.setMinimalDaysInFirstWeek(1); + """) + s""" + $c.setTimeInMillis($time * 1000L * 3600L * 24L); + ${ev.value} = $c.get($cal.WEEK_OF_YEAR); + """ + }) + } +} + // scalastyle:off line.size.limit @ExpressionDescription( usage = "_FUNC_(timestamp, fmt) - Converts `timestamp` to a value of string in the format specified by the date format `fmt`.", diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala index 4ce68538c87a..904e4bb32422 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala @@ -196,12 +196,26 @@ class DateExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper { } } + test("WeekOfYearISO8601") { + checkEvaluation(WeekOfYearISO8601(Literal.create(null, DateType)), null) + checkEvaluation(WeekOfYearISO8601(Literal(d)), 15) + checkEvaluation(WeekOfYearISO8601(Cast(Literal(sdfDate.format(d)), DateType, gmtId)), 15) + checkEvaluation(WeekOfYearISO8601(Cast(Literal(ts), DateType, gmtId)), 45) + checkEvaluation(WeekOfYearISO8601(Cast(Literal("2017-01-01"), DateType, gmtId)), 52) + checkEvaluation(WeekOfYearISO8601(Cast(Literal("2011-05-06"), DateType, gmtId)), 18) + checkEvaluation( + WeekOfYearISO8601(Literal(new Date(sdf.parse("1582-10-15 13:10:15").getTime))), 40) + checkEvaluation( + WeekOfYearISO8601(Literal(new Date(sdf.parse("1582-10-04 13:10:15").getTime))), 40) + checkConsistencyBetweenInterpretedAndCodegen(WeekOfYearISO8601, DateType) + } + test("WeekOfYear") { checkEvaluation(WeekOfYear(Literal.create(null, DateType)), null) checkEvaluation(WeekOfYear(Literal(d)), 15) checkEvaluation(WeekOfYear(Cast(Literal(sdfDate.format(d)), DateType, gmtId)), 15) checkEvaluation(WeekOfYear(Cast(Literal(ts), DateType, gmtId)), 45) - checkEvaluation(WeekOfYear(Cast(Literal("2011-05-06"), DateType, gmtId)), 18) + checkEvaluation(WeekOfYear(Cast(Literal("2017-01-01"), DateType, gmtId)), 1) checkEvaluation(WeekOfYear(Literal(new Date(sdf.parse("1582-10-15 13:10:15").getTime))), 40) checkEvaluation(WeekOfYear(Literal(new Date(sdf.parse("1582-10-04 13:10:15").getTime))), 40) checkConsistencyBetweenInterpretedAndCodegen(WeekOfYear, DateType) From 057ede5b68cc7980987ae181156f376f84c41809 Mon Sep 17 00:00:00 2001 From: setjet Date: Wed, 24 May 2017 01:22:54 +0100 Subject: [PATCH 2/5] updated desc --- .../spark/sql/catalyst/expressions/datetimeExpressions.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala index e2bfb3783b2c..eda9d2128765 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala @@ -455,7 +455,7 @@ case class WeekOfYearISO8601(child: Expression) extends extended = """ Examples: > SELECT _FUNC_('2017-01-01'); - 8 + 1 """) // scalastyle:on line.size.limit case class WeekOfYear(child: Expression) extends UnaryExpression with ImplicitCastInputTypes { From d26d1cbe7b1d8b93dd378ec188a459ce3ee6d8aa Mon Sep 17 00:00:00 2001 From: setjet Date: Wed, 24 May 2017 18:56:39 +0100 Subject: [PATCH 3/5] merged functions into 1 --- .../catalyst/analysis/FunctionRegistry.scala | 1 - .../expressions/datetimeExpressions.scala | 66 +++++-------------- .../expressions/DateExpressionsSuite.scala | 36 +++++----- 3 files changed, 34 insertions(+), 69 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala index 78fd48d27a2a..d2042ad00a81 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala @@ -358,7 +358,6 @@ object FunctionRegistry { expression[TruncDate]("trunc"), expression[UnixTimestamp]("unix_timestamp"), expression[WeekOfYear]("weekofyear"), - expression[WeekOfYearISO8601]("weekofyear_iso8601"), expression[Year]("year"), expression[TimeWindow]("window"), diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala index eda9d2128765..74f2989f1fab 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala @@ -404,69 +404,38 @@ case class DayOfMonth(child: Expression) extends UnaryExpression with ImplicitCa // scalastyle:off line.size.limit @ExpressionDescription( - usage = "_FUNC_(date) - Returns the week of the year of the given date according to the ISO 8601 standard", + usage = "_FUNC_(date[, format]) - Returns the week of the year of the given date. Defaults to ISO 8601 standard, but can be gregorian specific", extended = """ Examples: > SELECT _FUNC_('2008-02-20'); 8 + > SELECT _FUNC_('2017-01-01', 'gregorian'); + 1 + > SELECT _FUNC_('2017-01-01', 'iso'); + 52 + > SELECT _FUNC_('2017-01-01'); + 52 """) // scalastyle:on line.size.limit -case class WeekOfYearISO8601(child: Expression) extends +case class WeekOfYear(child: Expression, format: Expression) extends UnaryExpression with ImplicitCastInputTypes { - override def inputTypes: Seq[AbstractDataType] = Seq(DateType) - - override def dataType: DataType = IntegerType - - @transient private lazy val c = { - val c = Calendar.getInstance(DateTimeUtils.getTimeZone("UTC")) - c.setFirstDayOfWeek(Calendar.MONDAY) - c.setMinimalDaysInFirstWeek(4) - c + def this(child: Expression) = { + this(child, Literal("iso")) } - override protected def nullSafeEval(date: Any): Any = { - c.setTimeInMillis(date.asInstanceOf[Int] * 1000L * 3600L * 24L) - c.get(Calendar.WEEK_OF_YEAR) - } - - override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = { - nullSafeCodeGen(ctx, ev, time => { - val cal = classOf[Calendar].getName - val c = ctx.freshName("cal") - val dtu = DateTimeUtils.getClass.getName.stripSuffix("$") - ctx.addMutableState(cal, c, - s""" - $c = $cal.getInstance($dtu.getTimeZone("UTC")); - $c.setFirstDayOfWeek($cal.MONDAY); - $c.setMinimalDaysInFirstWeek(4); - """) - s""" - $c.setTimeInMillis($time * 1000L * 3600L * 24L); - ${ev.value} = $c.get($cal.WEEK_OF_YEAR); - """ - }) - } -} - -// scalastyle:off line.size.limit -@ExpressionDescription( - usage = "_FUNC_(date) - Returns the week of the year of the given date, where the first day of the year is always in week 1", - extended = """ - Examples: - > SELECT _FUNC_('2017-01-01'); - 1 - """) -// scalastyle:on line.size.limit -case class WeekOfYear(child: Expression) extends UnaryExpression with ImplicitCastInputTypes { - override def inputTypes: Seq[AbstractDataType] = Seq(DateType) override def dataType: DataType = IntegerType + @transient private lazy val minimalDays = { + if ("gregorian".equalsIgnoreCase(format.toString)) 1 else 4 + } + @transient private lazy val c = { val c = Calendar.getInstance(DateTimeUtils.getTimeZone("UTC")) - c.setMinimalDaysInFirstWeek(1) + c.setFirstDayOfWeek(Calendar.MONDAY) + c.setMinimalDaysInFirstWeek(minimalDays) c } @@ -483,7 +452,8 @@ case class WeekOfYear(child: Expression) extends UnaryExpression with ImplicitCa ctx.addMutableState(cal, c, s""" $c = $cal.getInstance($dtu.getTimeZone("UTC")); - $c.setMinimalDaysInFirstWeek(1); + $c.setFirstDayOfWeek($cal.MONDAY); + $c.setMinimalDaysInFirstWeek($minimalDays); """) s""" $c.setTimeInMillis($time * 1000L * 3600L * 24L); diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala index 904e4bb32422..b0ac3db9b8e2 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala @@ -196,29 +196,25 @@ class DateExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper { } } - test("WeekOfYearISO8601") { - checkEvaluation(WeekOfYearISO8601(Literal.create(null, DateType)), null) - checkEvaluation(WeekOfYearISO8601(Literal(d)), 15) - checkEvaluation(WeekOfYearISO8601(Cast(Literal(sdfDate.format(d)), DateType, gmtId)), 15) - checkEvaluation(WeekOfYearISO8601(Cast(Literal(ts), DateType, gmtId)), 45) - checkEvaluation(WeekOfYearISO8601(Cast(Literal("2017-01-01"), DateType, gmtId)), 52) - checkEvaluation(WeekOfYearISO8601(Cast(Literal("2011-05-06"), DateType, gmtId)), 18) + test("WeekOfYear") { + checkEvaluation(WeekOfYear(Literal.create(null, DateType), Literal("iso")), null) + checkEvaluation(WeekOfYear(Literal(d), Literal(false)), 15) + checkEvaluation(WeekOfYear(Cast(Literal(ts), DateType, gmtId), Literal("iso")), 45) checkEvaluation( - WeekOfYearISO8601(Literal(new Date(sdf.parse("1582-10-15 13:10:15").getTime))), 40) + WeekOfYear(Cast(Literal(sdfDate.format(d)), DateType, gmtId), Literal("iso")), 15) checkEvaluation( - WeekOfYearISO8601(Literal(new Date(sdf.parse("1582-10-04 13:10:15").getTime))), 40) - checkConsistencyBetweenInterpretedAndCodegen(WeekOfYearISO8601, DateType) - } + WeekOfYear(Literal(new Date(sdf.parse("1582-10-15 13:10:15").getTime)), Literal("iso")), 40) + checkEvaluation( + WeekOfYear(Literal(new Date(sdf.parse("1582-10-04 13:10:15").getTime)), Literal("iso")), 40) + + checkEvaluation( + WeekOfYear(Cast(Literal("2017-01-01"), DateType, gmtId), Literal("iso")), 52) + checkEvaluation( + WeekOfYear(Cast(Literal("2017-01-01"), DateType, gmtId), Literal("gregorian")), 1) + + checkConsistencyBetweenInterpretedAndCodegen( + (child: Expression) => WeekOfYear(child, Literal(true)), DateType) - test("WeekOfYear") { - checkEvaluation(WeekOfYear(Literal.create(null, DateType)), null) - checkEvaluation(WeekOfYear(Literal(d)), 15) - checkEvaluation(WeekOfYear(Cast(Literal(sdfDate.format(d)), DateType, gmtId)), 15) - checkEvaluation(WeekOfYear(Cast(Literal(ts), DateType, gmtId)), 45) - checkEvaluation(WeekOfYear(Cast(Literal("2017-01-01"), DateType, gmtId)), 1) - checkEvaluation(WeekOfYear(Literal(new Date(sdf.parse("1582-10-15 13:10:15").getTime))), 40) - checkEvaluation(WeekOfYear(Literal(new Date(sdf.parse("1582-10-04 13:10:15").getTime))), 40) - checkConsistencyBetweenInterpretedAndCodegen(WeekOfYear, DateType) } test("DateFormat") { From 0c4618c2f80501b201ca00640de62bdc238390cb Mon Sep 17 00:00:00 2001 From: setjet Date: Sat, 27 May 2017 14:08:20 +0100 Subject: [PATCH 4/5] added support to specify start of week --- .../expressions/datetimeExpressions.scala | 39 ++++++++++++++----- .../expressions/DateExpressionsSuite.scala | 35 ++++++++++------- 2 files changed, 49 insertions(+), 25 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala index 74f2989f1fab..720a4b9049ac 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala @@ -404,24 +404,31 @@ case class DayOfMonth(child: Expression) extends UnaryExpression with ImplicitCa // scalastyle:off line.size.limit @ExpressionDescription( - usage = "_FUNC_(date[, format]) - Returns the week of the year of the given date. Defaults to ISO 8601 standard, but can be gregorian specific", + usage = "_FUNC_(date[, format[, firstDayOfWeek]) - Returns the week of the year of the given date. Defaults to ISO 8601 standard: weeks start on Monday, and week 1 is defined as the first week in the new year that contains a thursday. Start of week can be overriden, and the week first week can be defined as the week that contains the first day of the new year by setting it to 'gregorian'.", extended = """ Examples: - > SELECT _FUNC_('2008-02-20'); - 8 - > SELECT _FUNC_('2017-01-01', 'gregorian'); + > SELECT _FUNC_('2011-01-01'); + 52 + > SELECT _FUNC_('2011-01-01', 'gregorian'); 1 - > SELECT _FUNC_('2017-01-01', 'iso'); + > SELECT _FUNC_('2011-01-01', 'iso'); 52 - > SELECT _FUNC_('2017-01-01'); + > SELECT _FUNC_('2011-01-01', 'iso', 'monday'); 52 + > SELECT _FUNC_('2011-01-01', 'iso', 'sunday'); + 1 + """) // scalastyle:on line.size.limit -case class WeekOfYear(child: Expression, format: Expression) extends +case class WeekOfYear(child: Expression, format: Expression, firstDayOfWeek: Expression) extends UnaryExpression with ImplicitCastInputTypes { def this(child: Expression) = { - this(child, Literal("iso")) + this(child, Literal("iso"), Literal("monday")) + } + + def this(child: Expression, format: Expression) = { + this(child, format, Literal("monday")) } override def inputTypes: Seq[AbstractDataType] = Seq(DateType) @@ -432,9 +439,21 @@ case class WeekOfYear(child: Expression, format: Expression) extends if ("gregorian".equalsIgnoreCase(format.toString)) 1 else 4 } + @transient private lazy val startOfWeek = { + firstDayOfWeek.toString match { + case day if "monday".equalsIgnoreCase(day) => Calendar.MONDAY + case day if "tuesday".equalsIgnoreCase(day) => Calendar.TUESDAY + case day if "wednesday".equalsIgnoreCase(day) => Calendar.WEDNESDAY + case day if "thursday".equalsIgnoreCase(day) => Calendar.THURSDAY + case day if "friday".equalsIgnoreCase(day) => Calendar.FRIDAY + case day if "saturday".equalsIgnoreCase(day) => Calendar.SATURDAY + case day if "sunday".equalsIgnoreCase(day) => Calendar.SUNDAY + } + } + @transient private lazy val c = { val c = Calendar.getInstance(DateTimeUtils.getTimeZone("UTC")) - c.setFirstDayOfWeek(Calendar.MONDAY) + c.setFirstDayOfWeek(startOfWeek) c.setMinimalDaysInFirstWeek(minimalDays) c } @@ -452,7 +471,7 @@ case class WeekOfYear(child: Expression, format: Expression) extends ctx.addMutableState(cal, c, s""" $c = $cal.getInstance($dtu.getTimeZone("UTC")); - $c.setFirstDayOfWeek($cal.MONDAY); + $c.setFirstDayOfWeek($startOfWeek); $c.setMinimalDaysInFirstWeek($minimalDays); """) s""" diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala index b0ac3db9b8e2..679303de6943 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala @@ -197,23 +197,28 @@ class DateExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper { } test("WeekOfYear") { - checkEvaluation(WeekOfYear(Literal.create(null, DateType), Literal("iso")), null) - checkEvaluation(WeekOfYear(Literal(d), Literal(false)), 15) - checkEvaluation(WeekOfYear(Cast(Literal(ts), DateType, gmtId), Literal("iso")), 45) - checkEvaluation( - WeekOfYear(Cast(Literal(sdfDate.format(d)), DateType, gmtId), Literal("iso")), 15) - checkEvaluation( - WeekOfYear(Literal(new Date(sdf.parse("1582-10-15 13:10:15").getTime)), Literal("iso")), 40) - checkEvaluation( - WeekOfYear(Literal(new Date(sdf.parse("1582-10-04 13:10:15").getTime)), Literal("iso")), 40) - - checkEvaluation( - WeekOfYear(Cast(Literal("2017-01-01"), DateType, gmtId), Literal("iso")), 52) - checkEvaluation( - WeekOfYear(Cast(Literal("2017-01-01"), DateType, gmtId), Literal("gregorian")), 1) + checkEvaluation(WeekOfYear( + Literal.create(null, DateType), Literal("iso"), Literal("monday")), null) + checkEvaluation(WeekOfYear(Literal(d), Literal("iso"), Literal("monday")), 15) + checkEvaluation(WeekOfYear( + Cast(Literal(ts), DateType, gmtId), Literal("iso"), Literal("monday")), 45) + checkEvaluation(WeekOfYear( + Cast(Literal(sdfDate.format(d)), DateType, gmtId), Literal("iso"), Literal("monday")), 15) + checkEvaluation(WeekOfYear( + Literal(new Date(sdf.parse("1582-10-15 13:10:15").getTime)), + Literal("iso"), Literal("monday")), 40) + checkEvaluation(WeekOfYear( + Literal(new Date(sdf.parse("1582-10-04 13:10:15").getTime)), + Literal("iso"), Literal("monday")), 40) + checkEvaluation(WeekOfYear( + Cast(Literal("2011-01-01"), DateType, gmtId), Literal("iso"), Literal("monday")), 52) + checkEvaluation(WeekOfYear( + Cast(Literal("2011-01-01"), DateType, gmtId), Literal("gregorian"), Literal("monday")), 1) + checkEvaluation(WeekOfYear( + Cast(Literal("2011-01-01"), DateType, gmtId), Literal("iso"), Literal("sunday")), 52) checkConsistencyBetweenInterpretedAndCodegen( - (child: Expression) => WeekOfYear(child, Literal(true)), DateType) + (child: Expression) => WeekOfYear(child, Literal("iso"), Literal("monday")), DateType) } From c9b5d3c6af85b2d189bd9a81a1dcdf10f4b6f2e8 Mon Sep 17 00:00:00 2001 From: setjet Date: Sat, 27 May 2017 14:10:31 +0100 Subject: [PATCH 5/5] updated description --- .../spark/sql/catalyst/expressions/datetimeExpressions.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala index 720a4b9049ac..8f2877caeb83 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala @@ -404,7 +404,7 @@ case class DayOfMonth(child: Expression) extends UnaryExpression with ImplicitCa // scalastyle:off line.size.limit @ExpressionDescription( - usage = "_FUNC_(date[, format[, firstDayOfWeek]) - Returns the week of the year of the given date. Defaults to ISO 8601 standard: weeks start on Monday, and week 1 is defined as the first week in the new year that contains a thursday. Start of week can be overriden, and the week first week can be defined as the week that contains the first day of the new year by setting it to 'gregorian'.", + usage = "_FUNC_(date[, format[, firstDayOfWeek]) - Returns the week of the year of the given date. Defaults to ISO 8601 standard: weeks start on Monday, and week 1 is defined as the first week in the new year that contains more than half of the days (Thursday in a Monday to Sunday week). Start of week can be overriden, and the week first week can be defined as the week that contains the first day of the new year by setting it to 'gregorian'.", extended = """ Examples: > SELECT _FUNC_('2011-01-01');