pyspark.sql.functions.timestamp_nanos#
- pyspark.sql.functions.timestamp_nanos(col)[source]#
Creates a nanosecond-precision timestamp (
TIMESTAMP_LTZ(9)) from the number of nanoseconds since the UTC epoch.Added in version 4.3.0.
- Parameters:
- col
Columnor column name a column of
BIGINTorDECIMALnanosecond values since the UTC epoch. A column that evaluates to an integral or decimal.
- col
- Returns:
Columna
TIMESTAMP_LTZ(9)column representing the corresponding point in time. Returns a column that evaluates to a timestamp.
See also
Examples
>>> import pyspark.sql.functions as sf >>> spark.conf.set("spark.sql.session.timeZone", "UTC") >>> spark.conf.set("spark.sql.timestampNanosTypes.enabled", "true") >>> df = spark.createDataFrame([(1577885075123456789,)], ['nanos']) >>> df.select(sf.timestamp_nanos('nanos')).show(truncate=False) +-----------------------------+ |timestamp_nanos(nanos) | +-----------------------------+ |2020-01-01 13:24:35.123456789| +-----------------------------+
>>> df.select(sf.timestamp_nanos(sf.lit(None).cast('bigint'))).show() +-------------------------------------+ |timestamp_nanos(CAST(NULL AS BIGINT))| +-------------------------------------+ | NULL| +-------------------------------------+
>>> spark.conf.unset("spark.sql.timestampNanosTypes.enabled") >>> spark.conf.unset("spark.sql.session.timeZone")