You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inconsistent Signedness Of Legacy Parquet Timestamps Written By Spark #7958
@alamb@comphead
i'm not familiar with parquet parser, i assume that time casting is dealed by timestamp casting but not to_timestamp function.
The behaviors for casting and to_timestamp are now different after #7844 merged
And that datatype supports a precision field which specifies millis/micros/nanos?
So I presume this error only happens when reading an INT field and casting? If so, I'd 100% be on board copying the behavior of these other well known databases. Folks who stored their data properly as Timestamps shouldn't be affected. It would be a breaking change to those who just stored as an INT, but I think now is the time to make that change since datetime support is relatively new... it will only get harder to change going forward.
changed the title [-]`to_timestamp()` wrong value reading from parquet[/-][+]Wrong timestamp type read while from parquet file created by spark[/+]on Oct 30, 2023
Apache projects like Hive and Spark still incorrectly treats the first 16 bytes, hence it returned what users thought was the correct value, but in fact it is incorrect.
That is the reason of having the difference. However DuckDB also works as Spark. To provide the compatibility support we may want introduce some config param in DF and treat INT96 like Spark.
I think it would be worthwhile writing up a description of any proposed change first. It isn't necessarily clear to me how one handles this correctly, or even if we can't simply follow Snowflake's example and close this as "won't fix".
changed the title [-]Wrong timestamp type read while from parquet file created by spark[/-][+]Inconsistent Signedness Of Legacy Parquet Timestamps Written By Spark[/+]on Nov 22, 2023
Thanks @edmondop please hold up on this.
I'm fixing some timestamp literals issues and we will have discussion on timestamp precision in DF, so this ticket will depend on actions above.
Activity
comphead commentedon Oct 27, 2023
@waitingkuo let me know your thoughts
comphead commentedon Oct 27, 2023
DuckDB, Spark, PG by default treats timestamp type as microseconds
https://duckdb.org/docs/sql/data_types/timestamp.html
https://spark.apache.org/docs/3.1.3/api/java/org/apache/spark/sql/types/TimestampType.html#:~:text=The%20timestamp%20type%20represents%20a,TimestampType%20to%20refer%20the%20type.
https://www.postgresql.org/docs/current/datatype-datetime.html
alamb commentedon Oct 27, 2023
How does one do this? Can you provide an example of such a file or the commands needed to create such a file?
comphead commentedon Oct 27, 2023
ts.snappy.zip
Attaching a parquet file.
I created this in spark
waitingkuo commentedon Oct 29, 2023
@alamb @comphead
i'm not familiar with parquet parser, i assume that time casting is dealed by timestamp casting but not to_timestamp function.
The behaviors for
castingandto_timestampare now different after #7844 mergedcomphead commentedon Oct 29, 2023
@waitingkuo thanks
to_timestamp(1)is consistent with PG, DuckDB, Spark.1::timestampthis syntax is not known for any engine above, is it supposed to do the same asto_timestamp(1), correct?waitingkuo commentedon Oct 30, 2023
Timestampin SQL maps toTimestamp(Nanosecond, tz)for now.https://github.com/apache/arrow-datafusion/blob/9b45967edc6dba312ea223464dad3e66604d2095/datafusion/sql/src/planner.rs#L346
So far,
1::timestampin datafusion treatint 1as1 nswhich is same as pyarrow@alamb @avantgardnerio @liukun4515 any thoughts about this?
avantgardnerio commentedon Oct 30, 2023
Parquet has a proper Timestamp field, correct? https://learn.microsoft.com/en-us/common-data-model/sdk/parquet-to-cdm-datatype
And that datatype supports a
precisionfield which specifies millis/micros/nanos?So I presume this error only happens when reading an
INTfield and casting? If so, I'd 100% be on board copying the behavior of these other well known databases. Folks who stored their data properly asTimestamps shouldn't be affected. It would be a breaking change to those who just stored as anINT, but I think now is the time to make that change since datetime support is relatively new... it will only get harder to change going forward.alamb commentedon Oct 30, 2023
I agree
I took a look at what
ts.snappy.parquetcontains:It seem to use a different type and has extra metadata that is not present in an equivalent file created by datafusion:
The field is not read as a timestamp at all 🤔
And the metadata / type information is different than spark:
$ parquet-tools schema -d ts-df.parquet message arrow_schema { required int64 a; } creator: datafusion version 32.0.0 file schema: arrow_schema -------------------------------------------------------------------------------- a: REQUIRED INT64 R:0 D:0 row group 1: RC:1 TS:63 OFFSET:4 -------------------------------------------------------------------------------- a: INT64 ZSTD DO:4 FPO:35 SZ:81/63/0.78 VC:1 ENC:RLE,PLAIN,RLE_DICTIONARY ST:[min: -62125747200, max: -62125747200, num_nulls not defined][-]`to_timestamp()` wrong value reading from parquet[/-][+]Wrong timestamp type read while from parquet file created by spark[/+]comphead commentedon Oct 30, 2023
Looks like the analysis shows DF has a bunch of issues with timestamp type
select cast(1 as timestamp);should be1970-01-01T00:00:01not1970-01-01T00:00:00.0000000011::timestampshould be consistent withto_timestamp(1)which works correctly nowcomphead commentedon Nov 2, 2023
arrow-rstreats INT96 Parquet type asTimestamp(NanoSecond)https://github.com/apache/arrow-rs/blob/master/parquet/src/arrow/schema/primitive.rs#L97
Interesting explanation in Snowflake of the same issue
https://community.snowflake.com/s/article/TIMESTAMP-function-returns-wrong-date-time-value-from-Parquet-file
Key takeaways
That is the reason of having the difference. However DuckDB also works as Spark. To provide the compatibility support we may want introduce some config param in DF and treat INT96 like Spark.
What are your thoughts? @alamb @waitingkuo @tustvold @viirya
tustvold commentedon Nov 2, 2023
I agree with the conclusion in the snowflake document, we should follow the specification and be consistent with other compliant implementations.
As an aside this type has been deprecated for almost a decade, why is spark still using it...
viirya commentedon Nov 6, 2023
Spark community tried (https://issues.apache.org/jira/browse/SPARK-27528) to change default Parquet timestamp type to TIMESTAMP_MICROS but the change was reverted back to INT96 later for ecosystem compatibility (https://issues.apache.org/jira/browse/SPARK-31639).
alamb commentedon Nov 20, 2023
Added to list on #7958
edmondop commentedon Nov 22, 2023
Can I give a shoot at this?
tustvold commentedon Nov 22, 2023
I think it would be worthwhile writing up a description of any proposed change first. It isn't necessarily clear to me how one handles this correctly, or even if we can't simply follow Snowflake's example and close this as "won't fix".
Perhaps @comphead might be able to help out here?
[-]Wrong timestamp type read while from parquet file created by spark[/-][+]Inconsistent Signedness Of Legacy Parquet Timestamps Written By Spark[/+]comphead commentedon Nov 22, 2023
Thanks @edmondop please hold up on this.
I'm fixing some timestamp literals issues and we will have discussion on timestamp precision in DF, so this ticket will depend on actions above.