0

I'm first reading lower bound and upper bound using a:

select max(timestamp) ,min(timestamp) from table name

extracting Row row=query.collectasList().get(0).getString(0) as lowerbound and upperbound respectively then passing lowerbound and upper bound


spark.read("jdbc")
  .option("url", url)
  .option("dbtable", "sample")
  .option("user", user)
  .option("driver","com.sqlserver")
  .option("password", password)
  .option("numPartitions", 100)
  .option("partitionColumn", "timestamp")
  .option("lowerBound", lowerbound)
  .option("upperBound", upperbound )
lowerbound and upperbound format "2022-02-09 17:13:22.353"

I understand lowerbound and upper bound has to be string but when passed I'm facing the below issue can you please help? Facing this issue Lost task 6.0 in stage 1.0 (TID 7, , executor 1):

com.microsoft.sqlserver.jdbc.SQLServerException: Conversion failed when converting date and/or time from character string. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java

Dale K
  • 25,246
  • 15
  • 42
  • 71
user2515163
  • 41
  • 2
  • 8
  • ISO 8601 is the safest date format for SQL Server. See eg https://stackoverflow.com/questions/813238/tsql-datetime-iso-8601 – David Browne - Microsoft Feb 09 '22 at 23:26
  • You're missing a `T`. If you're on an SQL Server using `DMY` format, e.g. `set dateformat dmy; select cast('2022-02-09 17:13:22.353' as datetime);`, then your string will incorrectly be interepreted at 02-Sep-2022. This exchange will cause the error message in your question when months 13 through 31 are involved. Using a proper ISO format including the `T` will not experience that issue, e.g.: `set dateformat dmy; select cast('2022-02-09T17:13:22.353' as datetime);` – AlwaysLearning Feb 10 '22 at 02:24

0 Answers0