MaxGekk commented on code in PR #56266:
URL: https://github.com/apache/spark/pull/56266#discussion_r3342362941


##########
sql/api/src/main/scala/org/apache/spark/sql/types/ops/TimestampNanosTypeApiOps.scala:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.types.ops
+
+import org.apache.spark.SparkException
+import org.apache.spark.sql.AnalysisException
+import org.apache.spark.sql.catalyst.encoders.AgnosticEncoder
+import org.apache.spark.sql.errors.DataTypeErrorsBase
+import org.apache.spark.sql.types.{TimestampLTZNanosType, 
TimestampNTZNanosType}
+
+/**
+ * Client-side (spark-api) operations shared by the nanosecond timestamp types
+ * (TimestampNTZNanosType and TimestampLTZNanosType).
+ *
+ * Internal values are [[org.apache.spark.unsafe.types.TimestampNanosVal]] 
(epoch micros + nanos
+ * within the micro). The two concrete subclasses differ only in their 
DataType and SQL-literal
+ * prefix; storage and formatting are identical.
+ *
+ * SCOPE (SPARK-57207): this issue wires physical representation, literals, 
row accessors, and
+ * codegen class selection. String formatting is not yet implemented: format() 
throws an internal
+ * error so callers get a clear message rather than a debug string; dedicated 
fractional-second
+ * formatters land in a follow-up issue.
+ * Dataset encoders are out of scope (SPARK-57033 and related), so getEncoder 
reports the type as
+ * unsupported, matching the legacy RowEncoder behavior.
+ *
+ * @since 4.3.0
+ */
+abstract class TimestampNanosTypeApiOps extends TypeApiOps with 
DataTypeErrorsBase {
+
+  /** SQL literal prefix for this type, e.g. "TIMESTAMP_NTZ" or 
"TIMESTAMP_LTZ". */
+  protected def sqlTypeName: String
+
+  // ==================== String Formatting ====================
+
+  // String formatting of nanosecond timestamps is not yet implemented 
(follow-up after
+  // SPARK-57207). Throw an internal error so that callers see a clear message 
rather than a
+  // debug toString from TimestampNanosVal.
+  override def format(v: Any): String =
+    throw SparkException.internalError(
+      s"Formatting of ${dataType.typeName} is not yet implemented.")

Review Comment:
   Follow-up: the internal exception is gone. `format()` (and the codegen 
`castToStringCode` path) now raise a user-facing 
`UNSUPPORTED_FEATURE.TIMESTAMP_NANOS_TO_STRING` error instead of 
`SparkException.internalError`. And since the nanos types are now supported 
only with the Types Framework enabled (no legacy fallback), there is no 
framework on/off divergence: casting to string fails the same way regardless of 
the flag.



##########
sql/api/src/main/scala/org/apache/spark/sql/types/ops/TimestampNanosTypeApiOps.scala:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.types.ops
+
+import org.apache.spark.SparkException
+import org.apache.spark.sql.AnalysisException
+import org.apache.spark.sql.catalyst.encoders.AgnosticEncoder
+import org.apache.spark.sql.errors.DataTypeErrorsBase
+import org.apache.spark.sql.types.{TimestampLTZNanosType, 
TimestampNTZNanosType}
+
+/**
+ * Client-side (spark-api) operations shared by the nanosecond timestamp types
+ * (TimestampNTZNanosType and TimestampLTZNanosType).
+ *
+ * Internal values are [[org.apache.spark.unsafe.types.TimestampNanosVal]] 
(epoch micros + nanos
+ * within the micro). The two concrete subclasses differ only in their 
DataType and SQL-literal
+ * prefix; storage and formatting are identical.
+ *
+ * SCOPE (SPARK-57207): this issue wires physical representation, literals, 
row accessors, and
+ * codegen class selection. String formatting is not yet implemented: format() 
throws an internal
+ * error so callers get a clear message rather than a debug string; dedicated 
fractional-second
+ * formatters land in a follow-up issue.
+ * Dataset encoders are out of scope (SPARK-57033 and related), so getEncoder 
reports the type as
+ * unsupported, matching the legacy RowEncoder behavior.
+ *
+ * @since 4.3.0
+ */
+abstract class TimestampNanosTypeApiOps extends TypeApiOps with 
DataTypeErrorsBase {
+
+  /** SQL literal prefix for this type, e.g. "TIMESTAMP_NTZ" or 
"TIMESTAMP_LTZ". */
+  protected def sqlTypeName: String
+
+  // ==================== String Formatting ====================
+
+  // String formatting of nanosecond timestamps is not yet implemented 
(follow-up after
+  // SPARK-57207). Throw an internal error so that callers see a clear message 
rather than a
+  // debug toString from TimestampNanosVal.
+  override def format(v: Any): String =

Review Comment:
   Follow-up to my earlier note: you were right that `internalError` is not 
appropriate here, since CAST-to-STRING / `show()` / SQL-literal rendering are 
reachable from public APIs once the preview flags are enabled. I have replaced 
it with a user-visible `UNSUPPORTED_FEATURE.TIMESTAMP_NANOS_TO_STRING` error, 
raised from both the interpreted `format()` and the codegen `castToStringCode` 
paths via a shared `DataTypeErrors` helper, so the two eval modes stay 
consistent.



-- 
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]

Reply via email to