4.1 KiB
Running a R script that returns a data frame in SQL Server big data cluster
Contents
About this sample
Before you begin
Run this sample
Sample details
Related links
About this sample
This is a sample R app, which shows how to run a R script in SQL Server big data cluster. This sample creates an app that simulates the rolling of dice. The code for this sample is in roll-dice.R. The inputs and outputs are shown below.
Inputs
| Parameter | Description |
|---|---|
x |
The number of dice to roll |
Outputs
| Parameter | Description |
|---|---|
result |
Data frame containing the results of the dice rolls: "Blue": [2], "Green": [6], "Red": [1] |
Before you begin
To run this sample, you need the following prerequisites.
Software prerequisites:
- SQL Server big data cluster CTP 2.3 or later.
mssqlctl. Refer to installing mssqlctl document on setting up themssqlctland connecting to a SQL Server 2019 big data cluster.
Run this sample
-
Clone or download this sample on your computer.
-
Log in to the SQL Server big data cluster using the command below using the IP address of the
endpoint-service-proxyin your cluster. If you are not familiar withmssqltctlyou can refer to the documentation and then return to this sample.mssqlctl login -e https://<ip-address-of-endpoint-service-proxy>:30777 -u <user-name> -p <password> -
Deploy the application by running the following command, specifying the folder where your
spec.yamlandroll-dice.Rfiles are located:mssqlctl app create --spec ./RollDice -
Check the deployment by running the following command:
mssqlctl app list -n roll-dice -v [version]Once the app is listed as
Readyyou can continue to the next step. -
Test the app by running the following command:
mssqlctl app run -n roll-dice -v [version] --input x=3You should get output like the example for three dice below. The results of the dice rolled are in the
resultdata frame:{ "changedFiles": [], "consoleOutput": "", "errorMessage": "", "outputFiles": {}, "outputParameters": { "result": { "Blue": [ 2 ], "Green": [ 6 ], "Red": [ 1 ] } }, "success": true }RESTful web service. Note that any app you create is also accessible using a RESTful web service that is Swagger compliant. See step 6 in the Addpy sample for detailed instructions on how to call the web service.
-
You can clean up the sample by running the following commands:
# delete app mssqlctl app delete --name roll-dice --version [version]
Sample details
Please refer to roll-dice.R for the code for this sample.
Spec file
Here is the spec file for this application. As you can see the sample uses the R runtime and calls the rollEm method in the roll-dice.R file, accepting an integer input named x for the number of dice and providing an data frame named result as the output.
name: roll-dice
version: v1
runtime: R
src: ./roll-dice.R
entrypoint: rollEm
replicas: 1
poolsize: 1
inputs:
x: integer
output:
result: data.frame
Related Links
For more information, see these articles:
How to deploy and app on SQL Server 2019 big data cluster (preview)