Skip to content
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

[SPARK-31710][SQL]Add compatibility flag to cast long to timestamp #28568

Closed
wants to merge 11 commits into from

Conversation

GuoPhilipse
Copy link
Member

What changes were proposed in this pull request?
As we know,long datatype is interpreted as milliseconds when conversion to timestamp in hive, while long is interpreted as seconds when conversion to timestamp in spark, we have been facing error data during migrating hive sql to spark sql. with compatibility flag we can fix this error,

Why are the changes needed?
we have many sqls runing in product, so we need a compatibility flag to make them migrating smoothly ,meanwhile do not change the user behavior in spark.

Does this PR introduce any user-facing change?
if user use this patch ,then user should set this paramter ,
if not, user do not need to do anything.

How was this patch tested?
unit test added

As we know,long datatype is interpreted as milliseconds when conversion to timestamp in hive, while long is interpreted as seconds when conversion to timestamp  in spark, we have many sqls runing in product, so we need  a compatibility flag to make them migrating smoothly ,meanwhile do not change the user behavior in spark.
As we know,long datatype is interpreted as milliseconds when conversion to timestamp in hive, while long is interpreted as seconds when conversion to timestamp  in spark, we have many sqls runing in product, so we need  a compatibility flag to make them migrating smoothly ,meanwhile do not change the user behavior in spark.
As we know,long datatype is interpreted as milliseconds when conversion to timestamp in hive, while long is interpreted as seconds when conversion to timestamp  in spark, we have many sqls runing in product, so we need  a compatibility flag to make them migrating smoothly ,meanwhile do not change the user behavior in spark.
…710-3

[SPARK-31710][SQL]Add compatibility flag to cast long to timestamp
…710-2

[SPARK-31710][SQL]Add compatibility flag to cast long to timestamp
…710-1

[SPARK-31710][SQL]Add compatibility flag to cast long to timestamp
@AmplabJenkins
Copy link

Can one of the admins verify this patch?

As we know,long datatype is interpreted as milliseconds when conversion to timestamp in hive, while long is interpreted as seconds when conversion to timestamp in spark, we have been facing error data during migrating hive sql to spark sql. with compatibility flag we can fix this error,
As we know,long datatype is interpreted as milliseconds when conversion to timestamp in hive, while long is interpreted as seconds when conversion to timestamp in spark, we have been facing error data during migrating hive sql to spark sql. with compatibility flag we can fix this error,
…710-4

[SPARK-31710][SQL]Add compatibility flag to cast long to timestamp
[SPARK-31710][SQL]Add compatibility flag to cast long to timestamp
@bart-samwel
Copy link

@cloud-fan @MaxGekk FYI

There's also PR #28534, which tries to solve the same thing using explicit functions.

To be honest, I'm not a big fan of using compatibility flags unless we're actually planning to deprecate the old behavior and change the behavior by default. Realistically, the next time we can change the default behavior is in Spark 4.0, which is likely to be several years out. And until then, throughout the Spark 3.x line, you may have Spark deployments out there where some query unexpectedly has different semantics than on other Spark deployments. The behavior change also doesn't stick if you then port that same workload over to other deployments of Spark, and given that it's not made explicit in the queries what they mean, and there's no errors, you may silently produce incorrect results after changing the deployment.

If anything, I'd be in favor of:

  • Doing the thing from PR [SPARK-31797][SQL] Adds TIMESTAMP_SECONDS, TIMESTAMP_MILLIS and TIMESTAMP_MICROS functions #28534 (adding TIMESTAMP_FROM_SECONDS etc.).
  • If we really care enough to change the behavior (and hence break existing workloads), we should use a legacy compatibility flag that disables this CAST by default, and to let people choose between the (legacy) Spark behavior or the (new) Hive behavior. With the strong advice in the "this is disabled" error message to migrate to the functions above instead and to leave the setting at "disabled". Then people can shoot themselves in the foot if they really want to, but then at least we told them so.

@GuoPhilipse
Copy link
Member Author

GuoPhilipse commented May 18, 2020 via email

@cloud-fan
Copy link
Contributor

we need same sql to run on hive/spark during migrating,if spark failed or behaviored less expected. so with a compatibility flag ,as you said, we can easily migrate them and no need to change user's sqls

We did something similar before, with the pgsql dialect. This project was canceled, because it's too much effort to keep 2 systems having exactly the same behaviors. And people may keep adding other dialects, which could increase maintenance costs dramatically.

Hive is a bit different as Spark already provides a lot of Hive compatibility. But still, it's not the right direction for Spark to provide 100% compatibility with another system.

For this particular case, I agree with @bart-samwel that we can fail by default for cast long to timestamp, and provide a legacy config to allow it with spark or hive behavior. This is a non-standard and weird behavior to allow cast long to timestamp, so for long-term we do want to forbid it, with clear error message to suggest using TIMESTAMP_MILLIS or TIMESTAMP_MICROS functions.

@bart-samwel
Copy link

@GuoPhilipse I agree that if you want to do the smooth migration like that, then you need to have all queries using a subset of the language that works in both systems. It's a luxury to have that, but it's nice to have. If you had the new functions AND the legacy config, then you would be in a good place. First migrate, then move over to the new functions after migration. So I propose to do both things. @cloud-fan do you agree?

@GuoPhilipse
Copy link
Member Author

GuoPhilipse commented May 19, 2020 via email

@HyukjinKwon
Copy link
Member

HyukjinKwon commented May 22, 2020

Let me close this for now, see also #28593

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants