cloud-fan commented on code in PR #57634: URL: https://github.com/apache/spark/pull/57634#discussion_r3684791290
########## sql/core/src/test/scala/org/apache/spark/sql/TimestampNanosRenderingSuiteBase.scala: ########## @@ -0,0 +1,177 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.sql + +import java.time.{Instant, LocalDateTime} + +import org.apache.spark.SparkConf +// castToImpl: `spark.createDataFrame` is typed as the public sql.DataFrame, but `showString` is a +// classic-only method; this implicit narrows the receiver to classic.Dataset for that call. +import org.apache.spark.sql.classic.ClassicConversions.castToImpl +import org.apache.spark.sql.internal.SQLConf +import org.apache.spark.sql.test.SharedSparkSession +import org.apache.spark.sql.types._ + +/** + * End-to-end `show()` / `collect()` rendering tests over the nanosecond-precision timestamp types + * `TIMESTAMP_NTZ(p)` / `TIMESTAMP_LTZ(p)` (`p` in `[7, 9]`). These ride on the nanos cast-to-string + * (`ToPrettyString` -> `ToStringBase`, which routes nanos through the Types Framework fraction + * formatter) and the nanos external encoders, so no production change is required. + * + * Two distinct surfaces are pinned, neither of which the golden SQL files can express: + * - `Dataset.show()` string rendering: the fractional second is rendered to the type's precision + * with sub-precision digits floored to zero and an all-zero fraction trimmed entirely. A value + * that only differs below the type's precision therefore renders identically -- the display is + * lossy at `p`, exactly as the stored value is. (The golden `.out` files render via + * `hiveResultString`, a different entry point onto the same formatter; `HiveResultSuite` covers + * that one. `show()` is what a user actually sees at the console.) + * - `collect()` external round-trip: NTZ comes back as `java.time.LocalDateTime` and LTZ as + * `java.time.Instant` (see `RowEncoder`), and `.getNano` preserves the sub-microsecond + * remainder floored to the type's precision -- so two values that share `epochMicros` but + * differ in `nanosWithinMicro` are distinguishable after a full driver round-trip. + * + * The nanosecond timestamp types are gated behind a preview flag enabled by default under tests + * (`Utils.isTesting`), so it is not set here. The session time zone is fixed to America/Los_Angeles + * (UTC-08:00, no DST on 2020-01-01) so the `TIMESTAMP_LTZ` (`Instant`) values render + * deterministically in wall-clock time. The two subclasses run every test with ANSI mode on/off. + */ +abstract class TimestampNanosRenderingSuiteBase extends SharedSparkSession { Review Comment: Please mix in `QueryTest` explicitly, as required for new SQL/DataFrame suites; relying on `SharedSparkSession`'s historical inheritance makes this suite depend on an implementation detail. ```suggestion abstract class TimestampNanosRenderingSuiteBase extends QueryTest with SharedSparkSession { ``` -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
