In this example we use datediff to calculate the diference in day from 'today' and others dates.
contacts = (contacts#days since last event.withColumn('daysSinceLastEvent', datediff(lit(today),'lastEvent'))#days since deployment.withColumn('daysSinceLastDeployment', datediff(lit(today),'lastDeploymentEnd'))#days since online training.withColumn('daysSinceLastTraining', datediff(lit(today),'lastTraining'))#days since last RC login.withColumn('daysSinceLastRollCallLogin', datediff(lit(today),'adx_identity_lastsuccessfullogin'))#days since last EMS login.withColumn('daysSinceLastEMSLogin', datediff(lit(today),'vms_lastuserlogin')) )
Output
SMA returns the EWI SPRKPY1019 over the line where datediff is used, so you can use to identify where to fix.
from pyspark.sql.functions import datediff#EWI: SPRKPY1019 => pyspark.sql.functions.datediff has a workaround, see documentation for more infocontacts = (contacts#days since last event.withColumn('daysSinceLastEvent', datediff(lit(today),'lastEvent'))#days since deployment.withColumn('daysSinceLastDeployment', datediff(lit(today),'lastDeploymentEnd'))#days since online training.withColumn('daysSinceLastTraining', datediff(lit(today),'lastTraining'))#days since last RC login.withColumn('daysSinceLastRollCallLogin', datediff(lit(today),'adx_identity_lastsuccessfullogin'))#days since last EMS login.withColumn('daysSinceLastEMSLogin', datediff(lit(today),'vms_lastuserlogin')) )
SMA convert pyspark.sql.functions.datediff onto snowflake.snowpark.functions.daydiff that also calculates the diference in days between two dates.
Action: Import snowflake.snowpark.functions, which contains an implementation for datediff function that requires an extra parameter for date time part and allows more versatility on calculate differences between dates.
from snowflake.snowpark import Sessionfrom snowflake.snowpark.functions import datediffcontacts = (contacts#days since last event.withColumn('daysSinceLastEvent', datediff('day', lit(today),'lastEvent'))#days since deployment.withColumn('daysSinceLastDeployment', datediff('day',lit(today),'lastDeploymentEnd'))#days since online training.withColumn('daysSinceLastTraining', datediff('day', lit(today),'lastTraining'))#days since last RC login.withColumn('daysSinceLastRollCallLogin', datediff('day', lit(today),'adx_identity_lastsuccessfullogin'))#days since last EMS login.withColumn('daysSinceLastEMSLogin', datediff('day', lit(today),'vms_lastuserlogin')) )