diff --git a/.gitignore b/.gitignore index 94ad4cc..a36f355 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .DS_Store acceleration/indexes/large_eth_traces.parquet acceleration/indexes/spicepod.yaml -.env \ No newline at end of file +.env.local \ No newline at end of file diff --git a/github/.env.example b/github/.env similarity index 100% rename from github/.env.example rename to github/.env diff --git a/github/README.md b/github/README.md index 3a3e496..1f64938 100644 --- a/github/README.md +++ b/github/README.md @@ -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= diff --git a/mssql/.env b/mssql/.env new file mode 100644 index 0000000..9153f42 --- /dev/null +++ b/mssql/.env @@ -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;" \ No newline at end of file diff --git a/mssql/README.md b/mssql/README.md new file mode 100644 index 0000000..9956de8 --- /dev/null +++ b/mssql/README.md @@ -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 | ++------------+-----------------+-------------------+---------------------+ +``` \ No newline at end of file diff --git a/mssql/compose.yml b/mssql/compose.yml new file mode 100644 index 0000000..c8ddbc4 --- /dev/null +++ b/mssql/compose.yml @@ -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 + \ No newline at end of file diff --git a/mssql/spicepod.yaml b/mssql/spicepod.yaml new file mode 100644 index 0000000..ee05682 --- /dev/null +++ b/mssql/spicepod.yaml @@ -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 \ No newline at end of file