Running a Magic 8-ball 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 runs a Magic 8-Ball. This sample creates an app that adds requires a question as input and returns an answer to the question. The code for this sample is in magic8ball.py The inputs and outputs are shown below.
Inputs
| Parameter | Description |
|---|---|
txt |
The input question on which you would like answered |
Outputs
| Parameter | Description |
|---|---|
result |
The answer of the Magic 8-ball |
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.yamlandmagic8ball.pyfiles are located:mssqlctl app create --spec ./magic8ball -
Check the deployment by running the following command:
mssqlctl app list -n magic8ball -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 magic8ball -v [version] --input txt="Will it rain tomorrow?"You should get output like the example below. The answer to your question are returned as
result.{ "changedFiles": [], "consoleOutput": "", "errorMessage": "", "outputFiles": {}, "outputParameters": { "result": "You may rely on it" }, "success": true } -
You can clean up the sample by running the following commands:
# delete app mssqlctl app delete --name magic8ball --version [version]
Sample details
Please refer to magic8ball.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 magic8ball method in the magic8ball.py file, accepting a str input called txt (the question that you ask the Magic 8-ball) and returning a str output named result.
name: magic8ball
version: v2
runtime: Python
src: ./magic8ball.py
entrypoint: magic8ball
replicas: 1
poolsize: 1
inputs:
txt: str
output:
result: str
Related Links
For more information, see these articles:
How to deploy and app on SQL Server 2019 big data cluster (preview)