Skip to content

Commit

Permalink
Adding MSSQL quickstart (#190)
Browse files Browse the repository at this point in the history
* Adding MSSQL quickstart

* Fixing capitalization

* Making secret name more consistent

* Making `.env` consistent across all quickstarts

* Removing AI model

* Improving MSSQL quickstart

* Removing extra newline

* Modifying MSSQL quickstart to be simpler

* Updating query and expected results
  • Loading branch information
slyons authored Sep 22, 2024
1 parent 36d0ce6 commit b32a688
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.DS_Store
acceleration/indexes/large_eth_traces.parquet
acceleration/indexes/spicepod.yaml
.env
.env.local
File renamed without changes.
2 changes: 1 addition & 1 deletion github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This quickstart will use [spiceai/spiceai](https://github.com/spiceai/spiceai) r
- Spice is installed (see the [Getting Started](https://docs.spiceai.org/getting-started) documentation).
- GitHub personal access token, [Learn more](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic) how to create one.

**Step 1.** Copy the `.env.example` file into a new `.env` file in this directory, and set the `GITHUB_TOKEN` environment variable to your personal access token.
**Step 1.** Copy the `.env` file into a new `.env.local` file in this directory, and set the `GITHUB_TOKEN` environment variable to your personal access token.

```env
GITHUB_TOKEN=<your_github_token>
Expand Down
2 changes: 2 additions & 0 deletions mssql/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SPICE_MSSQL_CONNECTION_STRING1="Server=tcp:localhost,11433;Initial Catalog=AdventureWorks;Persist Security Info=False;User ID=sa;Password=Password123@;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;Connection Timeout=30;"
SPICE_MSSQL_CONNECTION_STRING2="Server=tcp:localhost,11533;Initial Catalog=AdventureWorks;Persist Security Info=False;User ID=sa;Password=Password123@;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;Connection Timeout=30;"
81 changes: 81 additions & 0 deletions mssql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# MSSQL Connector Quickstart

This quickstart is meant to get you up and running with Spice's MSSQL data connector. It runs two instances of MSSQL server: 2019 and 2022. Both
instances are accessible from within Spice to demonstrate that you can query across multiple servers.

## Pre-requisites

- Spice is installed (see the [Getting Started](https://docs.spiceai.org/getting-started) documentation).
- Docker running on your system

## Steps

1. Start the MSSQL instances using `docker compose up -d`. In a production scenario you'd want to use [secrets](https://docs.spiceai.org/components/secret-stores) to protect your secrets
2. Start up Spice using `spice run`
3. In another shell, fire up the Spice SQL REPL using `spice sql`

## Example Queries

### Verify that the row counts in the 2019 server matches the 2022 server

```sql
SELECT
count_2019,
count_2022,
count_2019=count_2022 AS equal
FROM (
SELECT
COUNT(*) AS count_2019,
MAX(count_2022) AS count_2022
FROM Sales.Customer
JOIN (
SELECT
COUNT(*) AS count_2022
FROM Sales.Customer2022
) ON 1=1
)
```

Output:

```shell
+------------+------------+-------+
| count_2019 | count_2022 | equal |
+------------+------------+-------+
| 19820 | 19820 | true |
+------------+------------+-------+
```

### Order information per customer

```sql
SELECT c."CustomerID",
MAX(CAST("OrderDate" AS DATE)) AS LatestOrderDate,
ROUND(AVG("TotalDue"), 2) AS AverageOrderValue,
COUNT("SalesOrderID") AS TotalNumberOfOrders
FROM Sales.Customer c
LEFT OUTER JOIN Sales.SalesOrderHeader soh
ON c."CustomerID" = soh."CustomerID"
GROUP BY c."CustomerID"
ORDER BY TotalNumberOfOrders DESC
LIMIT 10
```

Output:

```shell
+------------+-----------------+-------------------+---------------------+
| CustomerID | latestorderdate | averageordervalue | totalnumberoforders |
+------------+-----------------+-------------------+---------------------+
| 11176 | 2014-06-29 | 52.09 | 28 |
| 11091 | 2014-06-10 | 46.94 | 28 |
| 11330 | 2014-06-24 | 46.51 | 27 |
| 11300 | 2014-06-02 | 61.41 | 27 |
| 11711 | 2014-06-28 | 45.17 | 27 |
| 11331 | 2014-06-26 | 54.4 | 27 |
| 11287 | 2014-06-30 | 47.76 | 27 |
| 11185 | 2014-06-28 | 66.15 | 27 |
| 11276 | 2014-06-24 | 40.45 | 27 |
| 11200 | 2014-06-22 | 59.89 | 27 |
+------------+-----------------+-------------------+---------------------+
```
28 changes: 28 additions & 0 deletions mssql/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
services:
mssql1:
image: "slyons/adventureworks:latest-2019"
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=Password123@
restart: unless-stopped
ports:
- "11433:1433"
healthcheck:
test: [ "CMD", "./ready.sh"]
interval: 5s
timeout: 5s
retries: 5
mssql2:
image: "slyons/adventureworks:latest-2022"
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=Password123@
restart: unless-stopped
ports:
- "11533:1433"
healthcheck:
test: [ "CMD", "./ready.sh"]
interval: 5s
timeout: 5s
retries: 5

25 changes: 25 additions & 0 deletions mssql/spicepod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: v1beta1
kind: Spicepod
name: spicepod-mssql

datasets:
- from: mssql:Sales.Customer
name: Sales.Customer
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING1 }
acceleration:
enabled: true

- from: mssql:Sales.Customer
name: Sales.Customer2022
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING2 }
acceleration:
enabled: true

- from: mssql:Sales.SalesOrderHeader
name: Sales.SalesOrderHeader
params:
mssql_connection_string: ${ secrets:SPICE_MSSQL_CONNECTION_STRING2 }
acceleration:
enabled: true

0 comments on commit b32a688

Please sign in to comment.