Skip to content

Update README and SQL files to fix stale data and code #13

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENS
* Make the Cybersyn data shares available to everyone in the account:
* Switch role to `ACCOUNTADMIN`
* Navigate to `Data Products > Marketplace`
* Type `stock prices` in the search box at the top, scroll through the results, and select [Financial & Economic Essentials](https://app.snowflake.com/marketplace/listing/GZTSZAS2KF7/) (provided by Cybersyn).
* Type `stock prices` in the search box at the top, scroll through the results, and select [Finance & Economics](https://app.snowflake.com/marketplace/listing/GZTSZAS2KF7/snowflake-data-finance-economics?search=stock%20prices) (provided by Snowflake).
* Click `Get` and enter your contact information in the prompt window
* In the next window
* leave the default database name as-is: `FINANCIAL__ECONOMIC_ESSENTIALS`
* leave the default database name as-is: `Finance__Economics`
* choose to make the data available to the `PUBLIC` role, then click `Get`.
* For the `Visualize your data` streamlit app, make sure to add the following packages :
* snowflake.core
* snowflake-ml-python

## Lab Presentation ##
* Go through introductory presentation
Expand Down
1 change: 0 additions & 1 deletion streamlit/visualize_your_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from snowflake.snowpark.context import get_active_session

# Set global options and page configuration for Streamlit
st.set_option('deprecation.showPyplotGlobalUse', False)
st.set_page_config(layout="wide") # Set the layout of the page to wide mode

# Initialize session from Snowflake to perform database operations
Expand Down
14 changes: 7 additions & 7 deletions worksheets/ZERO_TO_CHAT_WITH_YOUR_DATA.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- Select user workspace
SET user_id = (SELECT ZEROIFNULL(REGEXP_SUBSTR(CURRENT_USER, '\\d+')));
SET user_namespace = (SELECT CONCAT('CHAT_WITH_YOUR_DATA.WORKSPACE_' || $user_id));
USE DATABASE CHAT_WITH_YOUR_DATA;
USE DATABASE CHAT_WITH_YOUR_DATA;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace

USE SCHEMA IDENTIFIER($user_namespace);

-- Create company_metadata table
Expand Down Expand Up @@ -142,7 +142,7 @@ SELECT
ts.value AS post_market_close,
(ts.value / LAG(ts.value, 1) OVER (PARTITION BY meta.primary_ticker ORDER BY ts.date))::DOUBLE AS daily_return,
AVG(ts.value) OVER (PARTITION BY meta.primary_ticker ORDER BY ts.date ROWS BETWEEN 4 PRECEDING AND CURRENT ROW) AS five_day_moving_avg_price
FROM Financial__Economic_Essentials.cybersyn.stock_price_timeseries ts
FROM Finance__Economics.cybersyn.stock_price_timeseries ts
INNER JOIN company_metadata meta
ON ts.ticker = meta.primary_ticker
WHERE ts.variable_name = 'Post-Market Close'
Expand All @@ -155,7 +155,7 @@ SELECT
ts.date,
ts.value AS nasdaq_volume,
(ts.value / LAG(ts.value, 1) OVER (PARTITION BY meta.primary_ticker ORDER BY ts.date))::DOUBLE AS volume_change
FROM Financial__Economic_Essentials.cybersyn.stock_price_timeseries ts
FROM Finance__Economics.cybersyn.stock_price_timeseries ts
INNER JOIN company_metadata meta
ON ts.ticker = meta.primary_ticker
WHERE ts.variable_name = 'Nasdaq Volume'
Expand All @@ -169,7 +169,7 @@ SELECT
ts.value AS post_market_close,
(ts.value / LAG(ts.value, 1) OVER (PARTITION BY meta.primary_ticker ORDER BY ts.date))::DOUBLE AS daily_return,
AVG(ts.value) OVER (PARTITION BY meta.primary_ticker ORDER BY ts.date ROWS BETWEEN 4 PRECEDING AND CURRENT ROW) AS five_day_moving_avg_price
FROM Financial__Economic_Essentials.cybersyn.stock_price_timeseries ts
FROM Finance__Economics.cybersyn.stock_price_timeseries ts
INNER JOIN company_metadata meta
ON ts.ticker = meta.primary_ticker
WHERE ts.variable_name = 'Post-Market Close'
Expand Down Expand Up @@ -264,7 +264,7 @@ SELECT company_name FROM company_metadata LIMIT 10;

-- Create the limited attributes view
CREATE OR REPLACE VIEW financial_entity_attributes_limited AS
SELECT * from financial__economic_essentials.cybersyn.financial_institution_attributes
SELECT * from finance__economics.cybersyn.financial_institution_attributes
WHERE VARIABLE IN (
'ASSET',
'ESTINS',
Expand All @@ -287,10 +287,10 @@ SELECT
to_double(ts.value) as value,
ts.unit,
att.definition
FROM financial__economic_essentials.cybersyn.financial_institution_timeseries AS ts
FROM finance__economics.cybersyn.financial_institution_timeseries AS ts
INNER JOIN financial_entity_attributes_limited att
ON (ts.variable = att.variable)
INNER JOIN financial__economic_essentials.cybersyn.financial_institution_entities AS ent
INNER JOIN finance__economics.cybersyn.financial_institution_entities AS ent
ON (ts.id_rssd = ent.id_rssd)
WHERE MONTH(date) = 12
AND DAY(date) = 31;
Expand Down
28 changes: 14 additions & 14 deletions zero_to_chat_with_your_data/zero_to_chat_with_your_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Under **Projects** on the left-hand panel, select the **Notebooks** tab.

![notebook](assets/notebook_1.png)

Heres a breakdown of what each section outlined in red in the Snowflake notebook:
Here's a breakdown of what each section outlined in red in the Snowflake notebook:

**Left Panel (Files and Databases)**:

Expand All @@ -143,7 +143,7 @@ Under **Projects** on the left-hand panel, select the ​**Dashboards​** tab.

### Data > Databases ###

Under **Data**, the **Databases**​ tab shows information about the databases you have created or have permission to access. You can create, clone, drop, or transfer ownership of databases, as well as load data in the UI. Notice that a `CHAT_WITH_YOUR_DATA` database already exists in your environment. You will also see the Cybersyn `FINANCIAL__ECONOMIC_ESSENTIALS` database which has been shared with you.
Under **Data**, the **Databases**​ tab shows information about the databases you have created or have permission to access. You can create, clone, drop, or transfer ownership of databases, as well as load data in the UI. Notice that a `CHAT_WITH_YOUR_DATA` database already exists in your environment. You will also see the Cybersyn `FINANCE__ECONOMICS` database which has been shared with you.

![databases tab](assets/3UIStory_6.png)

Expand Down Expand Up @@ -600,7 +600,7 @@ SELECT * FROM sec_filings_attributes_view LIMIT 20;

### Snowflake Data Marketplace ###

> **NOTE**: For this lab, we are going to use the `FINANCIAL__ECONOMIC_ESSENTIALS` database that has already been shared with your user account. However, the following are the step-by-step instructions to get the database from the marketplace should you need to.
> **NOTE**: For this lab, we are going to use the `FINANCE__ECONOMICS` database that has already been shared with your user account. However, the following are the step-by-step instructions to get the database from the marketplace should you need to.

Make sure you're using the `ACCOUNTADMIN` role and, navigate to **Data Products** > **Marketplace**:

Expand Down Expand Up @@ -635,7 +635,7 @@ If you chose **Query Data**, a new worksheet opens in a new browser tab/window:

Next:
1. Click **Data** > **Databases**.
2. Click the `Financial__Economic_Essentials` database.
2. Click the `Finance__Economics` database.
3. You can see details about the schemas, tables, and views that are available to query.

![covid19 databases](assets/10Share_cybersyn_db_info.png)
Expand Down Expand Up @@ -673,7 +673,7 @@ SELECT
ts.value AS post_market_close,
(ts.value / LAG(ts.value, 1) OVER (PARTITION BY meta.primary_ticker ORDER BY ts.date))::DOUBLE AS daily_return,
AVG(ts.value) OVER (PARTITION BY meta.primary_ticker ORDER BY ts.date ROWS BETWEEN 4 PRECEDING AND CURRENT ROW) AS five_day_moving_avg_price
FROM Financial__Economic_Essentials.cybersyn.stock_price_timeseries ts
FROM Finance__Economics.cybersyn.stock_price_timeseries ts
INNER JOIN company_metadata meta
ON ts.ticker = meta.primary_ticker
WHERE ts.variable_name = 'Post-Market Close';
Expand Down Expand Up @@ -732,7 +732,7 @@ Snowflake allows you to create clones, also known as "zero-copy clones" of table
_A popular use case for zero-copy cloning is to clone a production environment for use by Development & Testing teams to test and experiment without adversely impacting the production environment and eliminating the need to set up and manage two separate environments._

> **Zero-Copy Cloning**
A massive benefit of zero-copy cloning is that the underlying data is not copied. Only the metadata and pointers to the underlying data change. Hence, clones are zero-copy" and storage requirements are not doubled when the data is cloned. Most data warehouses cannot do this, but for Snowflake it is easy!
A massive benefit of zero-copy cloning is that the underlying data is not copied. Only the metadata and pointers to the underlying data change. Hence, clones are "zero-copy" and storage requirements are not doubled when the data is cloned. Most data warehouses cannot do this, but for Snowflake it is easy!

> Learn more about [Cloning](https://docs.snowflake.com/en/user-guide/object-clone)

Expand Down Expand Up @@ -950,7 +950,7 @@ Snowflake offers powerful, intelligent features based on Artificial Intelligence

- **Cortex Fine-tuning** : Cortex Fine-Tuning is a fully managed service that lets you fine-tune popular LLMs using your data, all within Snowflake.

- **Cortex Search** : Snowflakes fully managed search service for documents and other unstructured data, is designed to be that reliable retrieval partner in an enterprise RAG stack.
- **Cortex Search** : Snowflake's fully managed search service for documents and other unstructured data, is designed to be that reliable retrieval partner in an enterprise RAG stack.

- **Cortex Analyst** : Cortex Analyst is a fully-managed, LLM-powered Snowflake Cortex feature that helps you create applications capable of reliably answering business questions based on your structured data in Snowflake

Expand All @@ -965,7 +965,7 @@ Navigate to the `CHAT_WITH_MY_DATA` worksheet and execute:
```SQL
-- Create the limited attributes view
CREATE VIEW IF NOT EXISTS financial_entity_attributes_limited AS
SELECT * from financial__economic_essentials.cybersyn.financial_institution_attributes
SELECT * from finance__economics.cybersyn.financial_institution_attributes
WHERE VARIABLE IN (
'ASSET',
'ESTINS',
Expand All @@ -991,10 +991,10 @@ SELECT
to_double(ts.value) as value,
ts.unit,
att.definition
FROM financial__economic_essentials.cybersyn.financial_institution_timeseries AS ts
FROM finance__economics.cybersyn.financial_institution_timeseries AS ts
INNER JOIN financial_entity_attributes_limited att
ON (ts.variable = att.variable)
INNER JOIN financial__economic_essentials.cybersyn.financial_institution_entities AS ent
INNER JOIN finance__economics.cybersyn.financial_institution_entities AS ent
ON (ts.id_rssd = ent.id_rssd)
WHERE MONTH(date) = 12
AND DAY(date) = 31;
Expand Down Expand Up @@ -1197,7 +1197,7 @@ def get_system_prompt():

#### Completing User Queries ####

- Sends the users question to the Snowflake Cortex model to generate a response based on the prompt.
- Sends the user's question to the Snowflake Cortex model to generate a response based on the prompt.

```PYTHON
def complete(myquestion):
Expand All @@ -1209,7 +1209,7 @@ def complete(myquestion):

#### Creating the User Query Prompt and Retrieving Chat History ####

- Creates a prompt for the Snowflake Cortex model based on the users question and chat history.
- Creates a prompt for the Snowflake Cortex model based on the user's question and chat history.

```PYTHON
def create_prompt(myquestion):
Expand Down Expand Up @@ -1297,7 +1297,7 @@ After a couple of seconds, the app will respond with the requested chartt as wel

> Give me a list of all unique company names
```text
DATABASE: FINANCIAL__ECONOMIC_ESSENTIALS
DATABASE: FINANCE__ECONOMICS
SCHEMA: CYBERSYN
TABLE: COMPANY_INDEX
LIBRARY: plotly
Expand All @@ -1306,7 +1306,7 @@ LIBRARY: plotly

> Transform value to number, Extract the year and filter by 2024 , Select quote_currency_id and value, Aggregate and plot the result
```text
DATABASE: FINANCIAL__ECONOMIC_ESSENTIALS
DATABASE: FINANCE__ECONOMICS
SCHEMA: CYBERSYN
TABLE: FX_RATE_TIMESERIES
LIBRARY: plotly
Expand Down