{"id":18419683,"url":"https://github.com/teradata/teddy-retailers-query-service","last_synced_at":"2026-03-19T04:17:10.409Z","repository":{"id":177218488,"uuid":"657507087","full_name":"Teradata/teddy-retailers-query-service","owner":"Teradata","description":null,"archived":false,"fork":false,"pushed_at":"2023-07-25T10:18:40.000Z","size":3353,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-21T06:06:29.456Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Teradata.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-23T08:02:10.000Z","updated_at":"2023-07-05T20:28:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"d5b214ff-56eb-4c17-8640-cbd023706478","html_url":"https://github.com/Teradata/teddy-retailers-query-service","commit_stats":null,"previous_names":["teradata/teddy-retailers-query-service"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Teradata/teddy-retailers-query-service","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Teradata%2Fteddy-retailers-query-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Teradata%2Fteddy-retailers-query-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Teradata%2Fteddy-retailers-query-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Teradata%2Fteddy-retailers-query-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Teradata","download_url":"https://codeload.github.com/Teradata/teddy-retailers-query-service/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Teradata%2Fteddy-retailers-query-service/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28992633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T20:57:35.821Z","status":"ssl_error","status_checked_at":"2026-02-01T20:57:29.580Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T04:17:54.908Z","updated_at":"2026-02-01T22:01:29.989Z","avatar_url":"https://github.com/Teradata.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introduction\n\nThis project showcases the utilization of Teradata Query Service to efficiently retrieve data from a Teradata Vantage Instance within a WebApp.\n\n## What is Teradata Query Service\n\n[Teradata Query Service](https://docs.teradata.com/r/Teradata-Query-Service-Installation-Configuration-and-Usage-Guide-for-Customers/April-2022/Overview/Teradata-Query-Service) is a middleware that provides a REST API that allows the execution of standard SQL statements against a Teradata Vantage instance without managing client-side drivers.\n\nQueries can be executed from web pages, mobile devices, or scripting language using HTTP as the wire protocol and JSON as the data interchange format. \n\nQuery Service provides APIs for:\n\n*   Configure Teradata-supported systems\n*   Submit SQL queries and access responses\n*   Create database sessions\n*   Access database and object metadata\n\n## Use Cases\n\nQuery Service is a suitable tool in cases when working with a Teradata driver is not practical or feasible.\n\nExamples:\n* A web or mobile application that communicates with services that expose their own APIs. \n\t* This projects illustrates this specific use case.\n* Working with Low Code tools that allow HTTP calls but not the installation of libraries.\n* Execution of SQL Queries from the browser.\n\t* Teradata web-based SQL editors \n\n## About the Project - Teddy Retailers Web Application\n### Context\nAs mentioned, this project illustrates the first use case mentioned above. Teddy Retailers is a retailer of common household items.\nTeddy Retailers Web Application connects to services that manage it's inventory (ERP system) through an specific endpoint. A recent request has been made to introduce a new marketing strategy aimed at rewarding frequent customers through a discount program.\n\nA frequent customer is defined as a customer with a total lifetime value above a certain threshold and that has ordered from Teddy Retailers in the \nlast 200 days.\n\nThe discount percentage varies according to Customer Lifetime Value as follows:\n- 10% to customers with a Customer Lifetime Value \u003e= 1500 USD\n-  5% to customers with a Customer Lifetime Value \u003c 1500 USD and \u003e= 1000 USD\n\nA query to Teradata Data Warehouse is needed to determine the Customer Lifetime Value and the date of the most recent order placed by a specific customer. We leverage Teradata Query Service to quickly set an endpoint that will allow the execution of this query with minimum overhead.\n\n### Implementation\n\n\u003cdiv align=\"center\"\u003e\n\n![Architecture](./img/about_project.PNG)\n\n\u003c/div\u003e\n\n- A Flask based web application that queries the Teradata database using Teradata Query Service.\n- Order data and price information is mocked through a service that displays mocked data from a JSON file. This endpoint is queried from the frontend.\n- Mock data regarding Customer Lifetime Value is loaded to a Teradata Vantage Instance from Object Storage in Google Cloud.\n- Query Service is the base of a service to query the Teradata Vantage Instance for Customer Lifetime Value data.\n\n## Prerequisites\n\n- Code IDE\n- [Python 3.7 minimum](https://www.python.org/downloads/)\n- [ClearScape Analytics Experience Account](https://clearscape.teradata.com/sign-in?utm_source=github\u0026utm_medium=readme\u0026utm_campaign=query-service)\n\n## Steps for running the project\n\n### Step 1: ClearScape Setup\n\nSign in to your [ClearScape Analytics Experience account](https://clearscape.teradata.com/sign-in?utm_source=github\u0026utm_medium=readme\u0026utm_campaign=query-service) to create and access database with Query Service.  \n\n\u003cdiv align=\"center\"\u003e\n\n![Sign In](/img/sign_in.PNG)\n\n\u003c/div\u003e\n\nOnce you have signed in, click on **CREATE ENVIRONMENT**\n\n\u003cdiv align=\"center\"\u003e\n\n![Create Environment](/img/create_env.PNG)\n\n\u003c/div\u003e\n\nThen, you need to provide -\n* An _environment name_\n\n  * A contextual name like 'Demo'       \n\n* A _Database password_\n\n  * A password of your choice\n  * \u003eNote it down for using it later in the code\n\n* _Region_\n\n  * Select one from the dropdown\n\n\u003cdiv align=\"center\"\u003e\n\n![environment values](/img/env_values.PNG)\n\n\u003c/div\u003e\n\nIt will open a new page showing your environment in Teradata Vantage on ClearScape Analytics Experience.\n\n\u003cdiv align=\"center\"\u003e\n\n![environment running](/img/final_page.PNG)\n\n\u003c/div\u003e\n\nCongratulations you are all set to work with Teradata Query Service!\n\n\n### Step 2: Create .env file\n\nAfter you have cloned the project, create `.env` file inside it.\n\n\u003cdiv align=\"center\" style=\"width:200px; height:200px\"\u003e\n\n![.env structure](/img/env_stru.PNG)\n\n\u003c/div\u003e\n\nFor connecting with the created ClearScape Analytics Experience environment, we need to provide -\n* Host URL,\n* User name, and\n* Database password\n\nCopy the _Host_ and _Username_ from the Step 1 and _Password_ is the database password we provided when created the environment.\n\nYour .env file will look like this -\n\n``` bash\n# Environment Values\nTD_HOST='HOST' # Host URL\nTD_USER='demo_user' # default user name\nTD_PASSWORD='DATABASE_PASSWORD' # your database password\n```\n\n\u003e Replace **HOST** and **DATABASE_PASSWORD** with your values\n\n### Step 3: Load Mock Data to Teradata Vantage Instance\n\nThe most important step is to upload the sample data to the environment.\n\nRun the query below in a database client properly connected to your Teradata Vantage instance.\n\n``` sql\nCREATE DATABASE teddy_retailers_warehouse\nAS PERMANENT = 110e6;\nCREATE TABLE teddy_retailers_warehouse.customers_tlv AS\n\t(\n\t\tSELECT CAST(customer_id as CHAR(5)) as customer_id, email, bought_items, tlv, last_ordered  FROM \n\t\t(\n\t    \tLOCATION='/gs/storage.googleapis.com/clearscape_analytics_demo_data/DEMO_dbtAdvanced/customers_tlv.csv'\n\t\t) as d\n)  WITH DATA;\n```\nThe `customer_tlv.csv` file has following information -\n* _customer_id_\n* _email_\n* _bought_items_\n* _tlv_\n* _last_ordered_\n\nThe CSV data is used here to calculate discount for customers based on their previous orders. It mocks data already ingested from relevant source systems and transformed in the Data Warehouse. \u003cbr\u003e\n\n\u003e The [`orders.json`](/mock_data/orders.json) file contains product details and serves as the basis to generate customer current order.\n\n\n### Step 4: Python virtual environment and requirements\n\nCreate a [Python virtual environment](https://docs.python.org/3/library/venv.html) and install the dependencies required for this project -\n\n\n``` bash\n$ pip install -r requirements.txt\n```\n\nYou have everything required to run this project on your local machine.\n\n### Step 5: Run the Project\n\nThe project is based on Flask, a micro web framework written in Python. \u003cbr\u003e\n\nCopy and paste below command to run the project -\n\n``` bash\n flask --app .\\teddy_qs.py run\n ```\nCopy the address, http://127.0.0.1:5000 and paste it in your browser\n\n \u003cdiv align=\"center\"\u003e\n\n![Flask run](/img/flask_run.PNG)\n\n\u003c/div\u003e\n\nThe browser should show \"Teddy Retailers - Your Order\" page. You can click on `Select a Customer` and get the information of different customers.\n\n \u003cdiv align=\"center\"\u003e\n\n![Flask run](/img/result.PNG)\n\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteradata%2Fteddy-retailers-query-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteradata%2Fteddy-retailers-query-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteradata%2Fteddy-retailers-query-service/lists"}