Okay so I am trying to write a database from pyspark to an azure sql database, but am running into an issue with datetime out of bounds values. I am aware of the difference in range of values for datetime and datetime.
My table is defined as followed:
CREATE TABLE [dbo].[DimTour]
(
[TourSk] BIGINT NOT NULL,
[TourBk] INT NOT NULL,
[TourType] VARCHAR(20) NOT NULL,
[RequestedDateTimeUTC] DATETIME2 NOT NULL,
[ScheduledDateTimeUTC] DATETIME2 NOT NULL,
[TourStatus] VARCHAR(20) NOT NULL,
CONSTRAINT [PK_DimTour] PRIMARY KEY CLUSTERED([TourSk] ASC)
);
When I first upload this table to azure the date types are Datetime2 and the data read into my dataframe from the data source is in Datetime2 format. However, when I try to upload the dataframe to the sql database I get the following error: "The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value." And then when I go look at my sql database table the type has switched from datetime2 to datetime. I am aware that this error stems from the 0001 years, but why is the data ever attempting to convert to datetime and how can I fix this?
Here is how I am writing the data:
dimTour.write.mode('Overwrite').jdbc(url=jdbcUrl, table='dbo.DimTour', properties=connectionProperties)