每当我运行特定的代码时,我不断地收到以下错误信息:Azure Databricks

huangapple go评论67阅读模式
英文:

when i run a particular code i repeatedly getting the following error Azure Databricks

问题

I'll provide the translation of the code and the error message as requested:

start_date_str = dbutils.widgets.get("startdate")
start_date = to_date(lit(start_date_str), 'yyyy-MM-dd')

enddate = (spark
    .range(1)
    .select(date_add(start_date, 365 * 10).alias("enddate"))
    .collect()[0]["enddate"]
)

(
  spark.sql(f"select explode(sequence(to_date('{start_date}'), to_date('{enddate}'), interval 1 day)) as calendarDate")
    .createOrReplaceTempView('dates')
)

Error Message:

如何解决这个错误

ParseException: 
[PARSE_SYNTAX_ERROR] Syntax error at or near 'to_date'(line 1, pos 41)

== SQL ==
select explode(sequence(to_date('Column'), to_date('2009-12-29'), interval 1 day)) as calendarDate

(Note: The code and error message are provided in a way that maintains the code's integrity and error message in Chinese as requested.)

英文:
start_date_str = dbutils.widgets.get("startdate")
start_date = to_date(lit(start_date_str), 'yyyy-MM-dd')

enddate = (spark
    .range(1)
    .select(date_add(start_date, 365 * 10).alias("enddate"))
    .collect()[0]["enddate"]
)

(
  spark.sql(f"select explode(sequence(to_date('{start_date}'), to_date('{enddate}'), interval 1 day)) as calendarDate")
    .createOrReplaceTempView('dates')
)

HOW TO SOLVE THIS ERROR

ParseException: 
[PARSE_SYNTAX_ERROR] Syntax error at or near 'to_date'(line 1, pos 41)

== SQL ==
select explode(sequence(to_date('Column'), to_date('2009-12-29'), interval 1 day)) as calendarDate

(I want a correct code for this.)

答案1

得分: 0

Most probably this is caused by this piece of code: to_date('{start_date}').

The problem is that start_date is the column object so when you print it inside the string you get it represented as Column<'to_date(2022-01-01, yyyy-MM-dd)'> that lead to the error.

instead you can change to_date('{start_date}') to to_date('{start_date_str}', 'yyyy-MM-dd')

英文:

Most probably this is caused by this piece of code: to_date('{start_date}').

The problem is that start_date is the column object so when you print it inside the string you get it represented as Column<'to_date(2022-01-01, yyyy-MM-dd)'> that lead to the error.

instead you can change to_date('{start_date}') to to_date('{start_date_str}', 'yyyy-MM-dd')

huangapple
  • 本文由 发表于 2023年2月24日 17:25:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75554761.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定