cloud-fan commented on code in PR #50112: URL: https://github.com/apache/spark/pull/50112#discussion_r1979431491
########## sql/core/src/main/scala/org/apache/spark/sql/jdbc/MySQLDialect.scala: ########## @@ -54,10 +54,31 @@ private case class MySQLDialect() extends JdbcDialect with SQLConfHelper with No override def visitExtract(field: String, source: String): String = { field match { case "DAY_OF_YEAR" => s"DAYOFYEAR($source)" - case "YEAR_OF_WEEK" => s"EXTRACT(YEAR FROM $source)" + // The second argument of WEEK is mode, which controls the first day of the week, the range + // of return value, config of week 1 (with a Sunday in this year, with 4 or more days this + // year, with a Monday in this year). + // The mode 3 means the first day of the week is Monday, the range of return value is 1-53 + // and week 1 is the first week with 4 or more days this year. In the other word, mode 3 + // has the same semantics as ISO week. + case "WEEK" => s"WEEK($source, 3)" + // MySQL doesn't support extract the ISO year. We use the case statements shown below to + // get it. + // CASE + // WHEN WEEK(date, 3) = 1 AND MONTH(date) = 12 THEN YEAR(date) + 1 + // WHEN WEEK(date, 3) >= 52 AND MONTH(date) = 1 THEN YEAR(date) - 1 + // ELSE YEAR(date) Review Comment: This looks fragile, shall we reject such EXTRACT to be pushed down? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org