Since the ST_GeomFromText is not the part of org.apache.spark.sql.functions so it will not recognise it internally.I need to first define the UDF for this function. means I
I think you should use a library like GeoSpark for that. I don't see that the function ST_Geomfromtext is there but it works for other formats like WKT https://datasystemslab.github.io/GeoSpark/api/sql/GeoSparkSQL-Constructor/#st_geomfromwkt. There are lots of other options and functions already implemented on geometrical data types, which I believe they will make your life much easier to calculate areas, crossing points, intersections, etc (for example) if you have to do it.
I am not sure what DB are you using (Postgis, SQL Server Spacial, etc.) but the definition of that function ST_Geomfromtext may slightly differ among them but WKT should be same as it's a standard definition of geometry
Hope this helps