メインコンテンツまでスキップ

タイムスタンプを試す

colformatで解析してタイムスタンプを生成します。この関数は、ANSI SQL モードが有効かどうかに関係なく、無効な入力に対しては常に null を返します。結果のデータ型は構成spark.sql.timestampTypeの値と一致しています。

対応する Databricks SQL 関数については、 try_to_timestamp関数を参照してください。

構文

Python
from pyspark.sql import functions as dbf

dbf.try_to_timestamp(col=<col>, format=<format>)

パラメーター

パラメーター

Type

説明

col

pyspark.sql.Column または str

変換する列の値。

format

literal string, optional

タイムスタンプ値を変換するために使用する形式。

パラメーター

Type

説明

col

pyspark.sql.Column または str

変換する列の値。

format

literal string, optional

タイムスタンプ値を変換するために使用する形式。

Python
from pyspark.sql import functions as dbf
df = spark.createDataFrame([('1997-02-28 10:30:00',)], ['t'])
df.select(dbf.try_to_timestamp(df.t)).show()
df = spark.createDataFrame([('1997-02-28 10:30:00',)], ['t'])
df.select(dbf.try_to_timestamp(df.t, dbf.lit('yyyy-MM-dd HH:mm:ss'))).show()
origin = spark.conf.get("spark.sql.ansi.enabled")
spark.conf.set("spark.sql.ansi.enabled", "true")
try:
df = spark.createDataFrame([('malformed',)], ['t'])
df.select(dbf.try_to_timestamp(df.t)).show()
finally:
spark.conf.set("spark.sql.ansi.enabled", origin)
このページの見出し