织梦CMS - 轻松建站从此开始!

欧博ABG官网-欧博官方网址-会员登入

How to print 欧博the result of current

时间:2025-12-07 22:53来源: 作者:admin 点击: 3 次
In Spark, column expressions (e.g. current_date()) do not show results until they are put into dataframes as columns and then the dataframe is instruc

In Spark, column expressions (e.g. current_date()) do not show results until they are put into dataframes as columns and then the dataframe is instructed to be shown.

Consider the following examples:

spark.range(1) - creating a dataframe
.select(F.current_date()) - selecting a column created using function current_date
.show() - printing the dataframe

from pyspark.sql import functions as F spark.range(1).select(F.current_date()).show() # +--------------+ # |current_date()| # +--------------+ # | 2023-08-04| # +--------------+

spark.sql("select current_date()") - creating both dataframe and column using SQL expression
.show() - printing the dataframe

spark.sql("select current_date()").show() # +--------------+ # |current_date()| # +--------------+ # | 2023-08-04| # +--------------+

.head() - accessing the dataframe's first row (as a pyspark.sql.types.Row object)
[0] - accessing the first element ("column") of the row

spark.sql("select current_date()").head()[0] # datetime.date(2023, 8, 4)

In Databricks, display(df) should also work, but for this you must create the df, e.g.:

display(spark.sql("select current_date()"))

(责任编辑:)
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:
发布者资料
查看详细资料 发送留言 加为好友 用户等级: 注册时间:2025-12-14 03:12 最后登录:2025-12-14 03:12
栏目列表
推荐内容