-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notebook modified for Singlestore Now Raffle #117
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,11 @@ | |
"id": "dfc73c1e-9918-4d0a-ab22-4187a9c47678", | ||
"metadata": {}, | ||
"source": [ | ||
"<img src=https://raw.githubusercontent.com/singlestore-labs/spaces-notebooks/master/notebooks/atlas-and-kai/images/mongo-db-singlestoredb.png width=\"100%\">" | ||
"<img src=https://raw.githubusercontent.com/singlestore-labs/spaces-notebooks/master/notebooks/atlas-and-kai/images/mongo-db-singlestoredb.png width=\"100%\">\n", | ||
"\n", | ||
"The data set used in this competition/demo contains some E-commerce data revolving around customers and products that they have purchased. In this notebook, we will run a few queries using SingleStore Kai which will allow us to migrate MongoDB data and run MongoDB queries directly through SingleStore. To create your entry for the raffle, please open and complete the following form: https://forms.gle/n8KjTpJgPL29wFHV9\n", | ||
"\n", | ||
"If you have any issues while completing the form, please reach out to a SingleStore team member at the event." | ||
] | ||
}, | ||
{ | ||
|
@@ -45,7 +49,9 @@ | |
"id": "1c7f4c37-2c1d-4507-9564-de2bea190005", | ||
"metadata": {}, | ||
"source": [ | ||
"## Install libraries and import modules" | ||
"## Install libraries and import modules\n", | ||
"\n", | ||
"First, we will need to import the necessary dependencies into our notebook environment. This includes some python libraries needed to run our queries." | ||
] | ||
}, | ||
{ | ||
|
@@ -58,6 +64,15 @@ | |
"!pip install pymongo pandas ipywidgets --quiet" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"id": "58c2085f-d9f4-4faa-b787-2e0cf952d0b1", | ||
"metadata": {}, | ||
"source": [ | ||
"To ensure that we have a database we can use, we will then make sure that a database exists. If it doesn't we will have the notebook create one for us." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
|
@@ -75,6 +90,15 @@ | |
" %sql CREATE DATABASE {{database_to_use}}" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"id": "033b3e8b-d445-41de-b682-77d66f98aed8", | ||
"metadata": {}, | ||
"source": [ | ||
"Next, let's run the code that will actually import the needed dependencies, including `pymongo`, that will be used to connect to SingleStore and our Mongo instance where the initial data is stored." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
|
@@ -97,7 +121,8 @@ | |
"metadata": {}, | ||
"source": [ | ||
"## Connect to Atlas and SingleStore Kai endpoints\n", | ||
"We are using a shared tier on the backend for Atlas" | ||
"\n", | ||
"Next, we will connect to the MongoDB Atlas instance using a Mongo client. We will need to connect to this instance to get our initial data, currently stored in Mongo." | ||
] | ||
}, | ||
{ | ||
|
@@ -115,15 +140,25 @@ | |
"mongotxs = mydbmongodb[\"txs\"]" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"id": "52c51825-19ac-4512-87b5-619fb0b48a67", | ||
"metadata": {}, | ||
"source": [ | ||
"Then, we will need to connect to the SingleStore Kai API which will allow us to import and access the Mongo data we will move over from Mongo Atlas." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "20e25f4a-a6ce-4e3a-80c5-c56002945c7e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"db_to_use = database_to_use\n", | ||
"s2clientmongodb = pymongo.MongoClient(connection_url_kai)\n", | ||
"s2dbmongodb = s2clientmongodb[database_to_use]\n", | ||
"s2dbmongodb = s2clientmongodb[db_to_use]\n", | ||
"s2mongoitems = s2dbmongodb[\"items\"]\n", | ||
"s2mongocusts = s2dbmongodb[\"custs\"]\n", | ||
"s2mongotxs = s2dbmongodb[\"txs\"]" | ||
|
@@ -135,7 +170,9 @@ | |
"id": "36c6162c-e0a2-404b-8d9f-9af8df8b8cea", | ||
"metadata": {}, | ||
"source": [ | ||
"## Copy Atlas collections into SingleStore Kai" | ||
"## Copy Atlas collections into SingleStore Kai\n", | ||
"\n", | ||
"As our next step, we need to get our MongoDB data hosted in Atlas over to SingleStore. For this, we will run the following code that will then replicate the selected Mongo collections into our SingleStore instance. This will make the MongoDB data available in SingleStore, allowing us to migrate away from MongoDB and to perform all of our data storage and queries in a single database instead of having multiple data silos." | ||
] | ||
}, | ||
{ | ||
|
@@ -160,7 +197,9 @@ | |
"id": "ca4dbc9b-f96a-46c1-a4ac-aa761e0d19ec", | ||
"metadata": {}, | ||
"source": [ | ||
"## Total quantity of products sold across all products" | ||
"## QUERY 1: Total quantity of products sold across all products\n", | ||
"\n", | ||
"Our first query on the newly migrated data will be to retrieve the total quanitity of products across every product within our dataset. As you'll see, even though we are running in SingleStore, we can still use Mongo query syntax using SingleStore Kai." | ||
] | ||
}, | ||
{ | ||
|
@@ -193,13 +232,25 @@ | |
"print(\"Total Product Quantity Sold is\",total_quantity)" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"id": "17c39c6d-5f5c-4712-86d4-57ab70f185ed", | ||
"metadata": {}, | ||
"source": [ | ||
"#### ACTION ITEM!\n", | ||
"Take the output from this query and put it into the **ANSWER NUMBER 1** field in the Google Form." | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"id": "58f643e0-0205-4cf7-97de-dcd93bef0a64", | ||
"metadata": {}, | ||
"source": [ | ||
"## Top selling Product" | ||
"## QUERY 2: Top selling Product\n", | ||
"\n", | ||
"Our next query will be to find the top selling product within our data. Once again, we are issuing a Mongo query against our SingleStore instance. If we had an application integrated with MongoDB but wanted to migrate to SingleStore, we could do so without having to rewrite the queries within our application!" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: MongoDB query |
||
] | ||
}, | ||
{ | ||
|
@@ -235,11 +286,22 @@ | |
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"id": "7efdb5cb-502f-46e0-9464-a62ab60beace", | ||
"metadata": {}, | ||
"source": [ | ||
"### ACTION ITEM!\n", | ||
"Take the output from this query and put it into the **ANSWER NUMBER 2** field in the Google Form." | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"id": "e45de51e-f54b-4788-8fb3-2aadc9143533", | ||
"metadata": {}, | ||
"source": [ | ||
"## Top selling Location" | ||
"## QUERY 3: Top selling Location" | ||
] | ||
}, | ||
{ | ||
|
@@ -290,14 +352,30 @@ | |
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"id": "153c9dd5-1804-42c6-b55e-ce043ee07a84", | ||
"metadata": {}, | ||
"source": [ | ||
"### ACTION ITEM!\n", | ||
"Take the output from this query and put it into the **ANSWER NUMBER 3** field in the Google Form." | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"id": "93934fde-c22e-4bda-992f-ed01dc83283c", | ||
"metadata": {}, | ||
"source": [ | ||
"## Clean up" | ||
"## Clean up and submit!\n", | ||
"\n", | ||
"**Make sure to click submit on your Google Form to make sure you've been entered into the SingleStore NOW 2024 raffle!**\n", | ||
"\n", | ||
"Additionally, if you'd like to clean up your instance, you can run the statement below. To learn more about SingleStore, please connect with one of our SingleStore reps here at the conference!" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"id": "599ca6e3-3847-467a-8a33-8f91e52a9cd1", | ||
"metadata": {}, | ||
|
@@ -325,7 +403,7 @@ | |
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "9635adf8-8137-4637-b94d-22835ba8112d", | ||
"id": "760cef98-671d-4754-bab4-67dc6f38c209", | ||
"metadata": {}, | ||
"source": [ | ||
"<div id=\"singlestore-footer\" style=\"background-color: rgba(194, 193, 199, 0.25); height:2px; margin-bottom:10px\"></div>\n", | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: MongoDB query syntax