how to call database specific function when reading writing thru jdbc

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

how to call database specific function when reading writing thru jdbc

kyunam
For example, in SQL Server, when reading, I want to call a built-in function: STAsText()

SELECT id, shape.STAsText() FROM SpatialTable

val df = _sparkSession
        .read
        .jdbc(url, "dbo.SpatialTable", props)
        .select("shape.STAsText()")  // No, this doesn't work.
        .as("shape")

Also when writing, I want to be able to call a built-in function: STGeomFromText like this:
INSERT INTO SpatialTable (GeomCol1) VALUES (geometry::STGeomFromText('POLYGON ((0 0, 150 0, 150 150, 0 150, 0 0))', 0));

How would go about doing this?

Thanks,
Kyunam