Skip to content

[SPARK-29870][SQL][FOLLOW-UP] Keep CalendarInterval's toString #26572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

HyukjinKwon
Copy link
Member

What changes were proposed in this pull request?

This is a followup of #26418. This PR removed CalendarInterval's toString with an unfinished changes.

Why are the changes needed?

  1. Ideally we should make each PR isolated and separate targeting one issue without touching unrelated codes.

  2. There are some other places where the string formats were exposed to users. For example:

    scala> sql("select interval 1 days as a").selectExpr("to_csv(struct(a))").show()
    +--------------------------+
    |to_csv(named_struct(a, a))|
    +--------------------------+
    |      "CalendarInterval...|
    +--------------------------+
    
  3. Such fixes:

     private def writeMapData(
        map: MapData, mapType: MapType, fieldWriter: ValueWriter): Unit = {
      val keyArray = map.keyArray()
    + val keyString = mapType.keyType match {
    +   case CalendarIntervalType =>
    +    (i: Int) => IntervalUtils.toMultiUnitsString(keyArray.getInterval(i))
    +   case _ => (i: Int) => keyArray.get(i, mapType.keyType).toString
    + }

    can cause performance regression due to type dispatch for each map.

Does this PR introduce any user-facing change?

Yes, see 2. case above.

How was this patch tested?

Manually tested.

@HyukjinKwon
Copy link
Member Author

cc @cloud-fan and @yaooqinn

@yaooqinn
Copy link
Member

LGTM, thanks for your follow-up.

private def appendUnit(sb: StringBuilder, value: Long, unit: String): Unit = {
if (value != 0) sb.append(value).append(' ').append(unit).append(' ')
}
def toMultiUnitsString(interval: CalendarInterval): String = interval.toString
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably add a comment saying that the toString implementation is the multi-units format.

@SparkQA
Copy link

SparkQA commented Nov 18, 2019

Test build #114009 has finished for PR 26572 at commit 81e8deb.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@@ -119,10 +119,6 @@ private[sql] class JacksonGenerator(
(row: SpecializedGetters, ordinal: Int) =>
gen.writeNumber(row.getDouble(ordinal))

case CalendarIntervalType =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't change behavior, right? same string comes out?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, as it will still call toString.

@HyukjinKwon
Copy link
Member Author

Last commit is comment-only (eefd457).
I locally checked ./dev/lint-scala which is only related to this change.

@HyukjinKwon
Copy link
Member Author

Merged to master.

@HyukjinKwon HyukjinKwon deleted the SPARK-29783 branch March 3, 2020 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants