3.7 KiB
Running a basic Python script 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 Python app, which shows how to run a Python script in SQL Server big data cluster. This sample creates an app that adds two whole numbers and returns the result. The code for this sample is in add.py. The inputs and outputs are shown below.
Inputs
| Parameter | Description |
|---|---|
x |
The first whole number to add |
y |
The second whole number to add |
Outputs
| Parameter | Description |
|---|---|
result |
The result of adding x and y |
Before you begin
To run this sample, you need the following prerequisites.
Software prerequisites:
- SQL Server big data cluster CTP 2.3 or later.
azdata. Refer to installing azdata document on setting up theazdataand 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
controller-svc-externalin your cluster. If you are not familiar withazdatayou can refer to the documentation and then return to this sample.azdata login -e https://<ip-address-of-controller-svc-external>:30080 -u <user-name> -
Deploy the application by running the following command, specifying the folder where your
spec.yamlandadd.pyfiles are located:azdata app create --spec ./addpy -
Check the deployment by running the following command:
azdata app list -n addpy -v [version]Once the app is listed as
Readyyou can continue to the next step. -
Test the app by running the following command:
azdata app run -n addpy -v [version] --input x=3,y=5You should get output like the example below. The result of adding 3+5 are returned as
result.{ "changedFiles": [], "consoleOutput": "", "errorMessage": "", "outputFiles": {}, "outputParameters": { "result": 8 }, "success": true } -
Any app you create is also accessible using a RESTful web service that is Swagger compliant. See: Consume an app deployed on SQL Server Big Data Clusters using a RESTful web service.
-
You can clean up the sample by running the following commands:
# delete app azdata app delete --name addpy --version [version]
Sample details
Please refer to add.py for the code for this sample.
Spec file
Here is the spec file for this application. As you can see the sample uses the Python runtime and calls the add method in the add.py file, accepting two integer inputs named x and y and returning an integer output named result.
name: addpy
version: v1
runtime: Python
src: ./add.py
entrypoint: add
replicas: 1
poolsize: 1
inputs:
x: int
y: int
output:
result: int
Related Links
For more information, see these articles: