A Fabric data engineer at Wide World Importers is working in a Fabric Lakehouse. A Delta table named RawSales contains a SaleDate column of type string in the format 'YYYY-MM-DD'. Analysts querying the SQL analytics endpoint receive errors when trying to use date functions on SaleDate. What is the correct approach to fix this in a PySpark notebook?
- A. Use the Visual Query Editor to change the column type, which will modify the underlying Delta table schema
- B. Rename the column to SaleDateStr and add a new computed column using ALTER TABLE in the SQL analytics endpoint
- C. Use df.withColumn('SaleDate', col('SaleDate').cast('date')) and overwrite the Delta table✓ Correct
- D. Create a view on the SQL analytics endpoint that casts SaleDate to DATE using CAST(SaleDate AS DATE)
Explanation
Using PySpark to cast the column to 'date' type and overwriting the Delta table updates the actual schema and stored data, making the column natively usable with date functions via the SQL analytics endpoint. Creating a view that casts the column is a valid workaround but does not fix the underlying table schema; analysts querying the base table directly will still encounter issues. ALTER TABLE for adding computed columns is not supported in the Fabric Warehouse/SQL analytics endpoint in the same way as SQL Server, and renaming the column would break existing queries. The Visual Query Editor does not modify the underlying Delta table schema; it only generates transformation steps for ad-hoc output.