Ask Your Question
1

How to execute an R function in a HANA database using SQL?

asked 2022-12-31 11:00:00 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-10-15 15:00:00 +0000

plato gravatar image

To execute an R function in a HANA database using SQL, you need to follow these steps:

  1. Ensure that the HANA database has the R server installed and configured.

  2. Create an R script that contains the function you want to execute. Save the script with a .r extension.

  3. Load the R script into the HANA database using the FILE_PUT function. For example:

FILE_PUT('my_script.r', '/usr/sap/HDB/home/my_script.r');

This will upload the R script to the HANA database server.

  1. Create a stored procedure in HANA that executes the R function. For example:
CREATE PROCEDURE my_r_function()
LANGUAGE RLANG AS
BEGIN
    result <- my_r_function_in_file('/usr/sap/HDB/home/my_script.r');
END;

This stored procedure calls the function specified in the R script 'my_script.r', and stores the result in the variable 'result'.

  1. Finally, you can call the stored procedure using a SQL query. For example:
CALL my_r_function();

This will execute the R function in the HANA database and return the result.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-12-31 11:00:00 +0000

Seen: 9 times

Last updated: Oct 15 '22