将日期 'yyyy-mm-dd' 从 Widget 转换为时间戳错误
Casting date 'yyyy-mm-dd' from a Widget to a timestamp error
我有一个名为 'filedate' 的小部件,您可以在其中指定日期,如果您以 'yyyy-mm-dd' 格式输入日期,我的示例将使用“2019-10-01”。
我通过以下方式从小部件中获取值:
val fileloaddate = dbutils.widgets.get("filedate")
如果我打印文件加载日期,它显示 2019-10-01,我需要在查询中使用它,所以如果我执行 'select to_timestamp(${fileloaddate}, "yyyy-mm-dd")' 它会出错,因为它将变量视为 '((2019 - 8) -18).如果我将字符串转换为日期,例如
select to_timestamp(to_date(${prundate}), "yyyy-mm-dd")
错误为'无法解析'CAST(((2019 - 8) - 18) AS DATE)'
select to_timestamp(to_date('2019-10-01'), "yyyy-mm-dd")
工作正常。我用谷歌搜索了答案,但似乎看不出我做错了什么。
谢谢
Azure DataBrick you can use getArgument to convert date into desire output
dbutils.widgets.text("x","2018-09-12")
select to_timestamp(to_date(getArgument("x")), "yyyy-mm-dd")
希望对您有所帮助
如果 Scala 被禁用,那么您需要使用旧方法从小部件中检索 sql 参数
.
select * 来自数据库 where parameter='$file'
对于sql,我可以将日期作为文本传递
%sql
创建小部件 'StartDate' DEFAULT 'YYYY-MM-DD'(这只是提醒用户以 sql 查询可以使用的格式输入日期的文本)
select * 来自 my_table 在“$StartDate”和“$EndDate”之间
https://docs.databricks.com/notebooks/widgets.html#legacy-input
https://docs.databricks.com/notebooks/widgets.html
我有一个名为 'filedate' 的小部件,您可以在其中指定日期,如果您以 'yyyy-mm-dd' 格式输入日期,我的示例将使用“2019-10-01”。
我通过以下方式从小部件中获取值:
val fileloaddate = dbutils.widgets.get("filedate")
如果我打印文件加载日期,它显示 2019-10-01,我需要在查询中使用它,所以如果我执行 'select to_timestamp(${fileloaddate}, "yyyy-mm-dd")' 它会出错,因为它将变量视为 '((2019 - 8) -18).如果我将字符串转换为日期,例如
select to_timestamp(to_date(${prundate}), "yyyy-mm-dd")
错误为'无法解析'CAST(((2019 - 8) - 18) AS DATE)'
select to_timestamp(to_date('2019-10-01'), "yyyy-mm-dd")
工作正常。我用谷歌搜索了答案,但似乎看不出我做错了什么。
谢谢
Azure DataBrick you can use getArgument to convert date into desire output
dbutils.widgets.text("x","2018-09-12")
select to_timestamp(to_date(getArgument("x")), "yyyy-mm-dd")
希望对您有所帮助
如果 Scala 被禁用,那么您需要使用旧方法从小部件中检索 sql 参数 . select * 来自数据库 where parameter='$file'
对于sql,我可以将日期作为文本传递
%sql 创建小部件 'StartDate' DEFAULT 'YYYY-MM-DD'(这只是提醒用户以 sql 查询可以使用的格式输入日期的文本)
select * 来自 my_table 在“$StartDate”和“$EndDate”之间
https://docs.databricks.com/notebooks/widgets.html#legacy-input https://docs.databricks.com/notebooks/widgets.html