Spark SQL interpretiert ein datetime.date -Objekt als mathematische Formel oder Ganzzahl in der AnweisungPython

Python-Programme
Anonymous
 Spark SQL interpretiert ein datetime.date -Objekt als mathematische Formel oder Ganzzahl in der Anweisung

Post by Anonymous »

Ich habe ein Problem in Spark SQL gestoßen. Es interpretiert ein datetime.date Objekt als mathematische Formel oder Ganzzahl in einer SQL-Anweisung, die ich schreibe.

Code: Select all

currentDateAndTime = datetime.now()
current_month = currentDateAndTime.strftime("%m")
current_year = currentDateAndTime.strftime("%Y")

first_day_of_month = date(int(current_year), int(current_month), 1)
print(first_day_of_month)
type(first_day_of_month)
< /code>
und Sie erhalten: < /p>
2022-10-01 datetime.date

Wenn ich dann
machedf = spark.sql("""
SELECT * FROM table_A
WHERE IncidentCreatedDate < {}
""".format(first_day_of_month))
< /code>
Ich erhalte einen Fehler mit der Aufschrift < /p>
AnalysisException: cannot resolve '(table_A.`IncidentCreatedDate` < ((2022 - 10) - 1))' due to data type mismatch: differing types in '(tableA.`IncidentCreatedDate` < ((2022 - 10) - 1))' (date and int).; ...
< /code>
Möglicherweise gibt es einen Tippfehler in allem oben, weil ich alles auf einem anderen Laptop ausgeben musste überall sonst.)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post