stevomitric commented on code in PR #56602:
URL: https://github.com/apache/spark/pull/56602#discussion_r3441416885


##########
sql/api/src/main/scala/org/apache/spark/sql/functions.scala:
##########
@@ -8199,6 +8199,16 @@ object functions {
    */
   def unix_micros(e: Column): Column = Column.fn("unix_micros", e)
 
+  /**
+   * Returns the number of nanoseconds since 1970-01-01 00:00:00 UTC for a 
nanosecond-precision
+   * timestamp (`TIMESTAMP_LTZ(p)` / `TIMESTAMP_NTZ(p)`, `p` in `[7, 9]`). The 
result is a
+   * lossless `DECIMAL(21, 0)`.
+   *
+   * @group datetime_funcs
+   * @since 4.3.0
+   */
+  def unix_nanos(e: Column): Column = Column.fn("unix_nanos", e)

Review Comment:
   Nit: "Spark Connect out of scope" isn't quite right — functions.scala is in 
sql/api, so the Scala Connect client gets unix_nanos automatically. Only 
PySpark + R are deferred.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala:
##########
@@ -854,6 +855,57 @@ case class UnixMicros(child: Expression) extends 
TimestampToLongBase {
     copy(child = newChild)
 }
 
+// scalastyle:off line.contains.tab
+@ExpressionDescription(
+  usage = "_FUNC_(timestamp) - Returns the number of nanoseconds since 
1970-01-01 00:00:00 UTC.",
+  examples = """
+    Examples:
+      > SET spark.sql.timestampNanosTypes.enabled=true;
+      spark.sql.timestampNanosTypes.enabled    true
+      > SELECT _FUNC_(TIMESTAMP_NTZ '2008-12-25 15:30:00.123456789');
+       1230219000123456789
+  """,
+  group = "datetime_funcs",
+  since = "4.3.0")
+// scalastyle:on line.contains.tab
+case class UnixNanos(child: Expression)
+  extends UnaryExpression with ExpectsInputTypes {
+  override def nullIntolerant: Boolean = true
+
+  // Accepts only the nanosecond-precision timestamp types TIMESTAMP_LTZ(p) / 
TIMESTAMP_NTZ(p)
+  // (p in [7, 9]); the microsecond timestamp types are intentionally not 
supported here.

Review Comment:
   Nit: "intentionally not supported here" reads as permanent — the body calls 
micros a follow-up. Maybe "deferred follow-up" instead.



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