├── oceanbase_technical_demo.pdf ├── sales_import.csv ├── oceanbase_technical_demo.sql ├── README.md └── oceanbase_technical_demo.ipynb /oceanbase_technical_demo.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JNYH/OceanBase_technical_demo/HEAD/oceanbase_technical_demo.pdf -------------------------------------------------------------------------------- /sales_import.csv: -------------------------------------------------------------------------------- 1 | id,salesperson_id,date,volume 2 | 1,1,2021-01-01,9000 3 | 2,1,2022-01-01,10000 4 | 3,1,2023-01-01,19000 5 | 4,2,2021-01-01,9000 6 | 5,2,2022-01-01,15000 7 | 6,2,2023-01-01,12000 8 | 7,1,2021-01-01,5000 9 | 8,1,2022-01-01,16000 10 | 9,1,2023-01-01,8000 11 | 10,2,2021-01-01,19000 12 | 11,2,2022-01-01,2000 13 | 12,2,2023-01-01,18000 14 | 13,1,2021-01-01,15000 15 | 14,1,2022-01-01,4000 16 | 15,1,2023-01-01,12000 17 | 16,2,2021-01-01,5000 18 | 17,2,2022-01-01,5000 19 | 18,2,2023-01-01,18000 20 | 19,1,2021-01-01,19000 21 | 20,2,2022-01-01,19000 22 | -------------------------------------------------------------------------------- /oceanbase_technical_demo.sql: -------------------------------------------------------------------------------- 1 | -- Create a new DB 2 | CREATE DATABASE jamesdatabase; 3 | 4 | -- Create a new schema/table 5 | USE jamesdatabase; 6 | CREATE TABLE salespersons ( 7 | id INT PRIMARY KEY, 8 | name VARCHAR(50), 9 | email VARCHAR(50) 10 | ); 11 | 12 | -- Create sample data 13 | INSERT INTO salespersons (id, name, email) VALUES 14 | (1, 'Andy Ang', 'andy@email.com'), 15 | (2, 'Brenda Bing', 'brenda@email.com'); 16 | 17 | USE jamesdatabase; 18 | CREATE TABLE sales ( 19 | id INT PRIMARY KEY, 20 | salesperson_id INT, 21 | date DATE, 22 | volume DECIMAL(10,2) 23 | ); 24 | 25 | INSERT INTO sales (id, salesperson_id, date, volume) VALUES 26 | (1, 1, '2022-01-01', 10000.00), 27 | (2, 1, '2023-01-01', 19000.00), 28 | (3, 2, '2022-01-01', 15000.00), 29 | (4, 2, '2023-01-01', 12000.00), 30 | (5, 1, '2023-01-01', 500.00); 31 | 32 | -- 33 | -- demo: to import sample data from "sales_import.csv" 34 | -- 35 | 36 | CREATE INDEX idx_salesperson_id ON sales (salesperson_id); 37 | 38 | -- DML operations (INSERT/UPDATE/DELETE) 39 | INSERT INTO salespersons (id, name, email) VALUES (3, 'Chris Choo', 'chris@email.com'); 40 | UPDATE salespersons SET email = 'chris.choo@email.com' WHERE id = 3; 41 | DELETE FROM salespersons WHERE id = 3; 42 | 43 | -- Gather the database statistics through the SYS schema 44 | SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_NAME = 'sales'; 45 | SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_NAME = 'salespersons'; 46 | 47 | -- Analyze the database with a SQL query 48 | SELECT s.salesperson_id, sp.name, SUM(s.volume) AS total_volume 49 | FROM sales s 50 | JOIN salespersons sp ON s.salesperson_id = sp.id 51 | WHERE s.date = '2023-01-01' 52 | GROUP BY s.salesperson_id, sp.name; 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OceanBase technical demo 2 | 3 | Documentation Reference:
4 | https://hub.docker.com/r/oceanbase/oceanbase-ce
5 | https://github.com/oceanbase/oceanbase 6 | 7 | To download the Docker image of OceanBase:
8 | 9 | docker pull obpilot/oceanbase-ce 10 | 11 | When successful you will see:
12 | _Status: Downloaded newer image for oceanbase/oceanbase-ce:latest
_ 13 | 14 | To start the Docker container instance, run this: 15 | 16 | docker run -itd -m 10G -p 2883:2883 --name oceanbase-ce obpilot/oceanbase-ce:latest 17 | 18 | To execute the container in the Bash environment: 19 | 20 | docker exec -it oceanbase-ce bash 21 | 22 | (Skip this - optional) To execute the container in the SQL environment: 23 | 24 | docker exec -it oceanbase-ce2 ob-mysql sys 25 | 26 | To start the demo environment (Bash command): 27 | 28 | obd cluster list 29 | obd cluster start obdemo 30 | 31 | After this, connect to the OceanBase database using DBeaver.
32 | Reference [link](https://youtu.be/Yanz-Brvd04). 33 | 34 | Go to DBeaver -> Database -> New Database Connection -> MySQL -> next 35 | * **Server Host**: 127.0.0.1 36 | * **Port**: 2883 37 | * **Database**: OceanBase 38 | * **Username**: root 39 | * **Password**: rootPWD123 40 | * Click on **Test Connection** -> OK -> Finish 41 | * SQL Editor -> Open SQL Script -> CREATE DATABASE jamesdatabase; 42 | * (right-click) Databases -> Refresh 43 | * (right-click) jamesdatabase -> Set as default 44 | 45 | Refer to [oceanbase_technical_demo.sql](https://github.com/JNYH/OceanBase_technical_demo/blob/main/oceanbase_technical_demo.sql) for more Data Definition Language (DDL) statements. 46 | 47 | --- 48 | Refer to my YouTube video for the above demo in full: https://youtu.be/RrAiDz9BbtE 49 | -------------------------------------------------------------------------------- /oceanbase_technical_demo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "Defaulting to user installation because normal site-packages is not writeable\n", 13 | "Requirement already satisfied: pip in c:\\users\\jnyh\\appdata\\roaming\\python\\python38\\site-packages (23.2)\n", 14 | "Collecting pip\n", 15 | " Obtaining dependency information for pip from https://files.pythonhosted.org/packages/50/c2/e06851e8cc28dcad7c155f4753da8833ac06a5c704c109313b8d5a62968a/pip-23.2.1-py3-none-any.whl.metadata\n", 16 | " Using cached pip-23.2.1-py3-none-any.whl.metadata (4.2 kB)\n", 17 | "Using cached pip-23.2.1-py3-none-any.whl (2.1 MB)\n" 18 | ] 19 | }, 20 | { 21 | "name": "stderr", 22 | "output_type": "stream", 23 | "text": [ 24 | "ERROR: To modify pip, please run the following command:\n", 25 | "c:\\program files\\python38\\python.exe -m pip install --upgrade pip\n", 26 | "\n", 27 | "[notice] A new release of pip is available: 23.2 -> 23.2.1\n", 28 | "[notice] To update, run: python.exe -m pip install --upgrade pip\n" 29 | ] 30 | } 31 | ], 32 | "source": [ 33 | "!pip install --upgrade pip" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 2, 39 | "metadata": {}, 40 | "outputs": [ 41 | { 42 | "name": "stdout", 43 | "output_type": "stream", 44 | "text": [ 45 | "Defaulting to user installation because normal site-packages is not writeable\n", 46 | "Requirement already satisfied: PyMySQL in c:\\users\\jnyh\\appdata\\roaming\\python\\python38\\site-packages (1.1.0)\n" 47 | ] 48 | }, 49 | { 50 | "name": "stderr", 51 | "output_type": "stream", 52 | "text": [ 53 | "\n", 54 | "[notice] A new release of pip is available: 23.2 -> 23.2.1\n", 55 | "[notice] To update, run: python.exe -m pip install --upgrade pip\n" 56 | ] 57 | } 58 | ], 59 | "source": [ 60 | "!pip install PyMySQL" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": null, 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [ 69 | "#Env Python 3.8.2\n", 70 | "import pymysql" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 5, 76 | "metadata": {}, 77 | "outputs": [ 78 | { 79 | "name": "stdout", 80 | "output_type": "stream", 81 | "text": [ 82 | "(1, 1, datetime.date(2021, 1, 1), Decimal('9000.00'))\n", 83 | "(2, 1, datetime.date(2022, 1, 1), Decimal('10000.00'))\n", 84 | "(3, 1, datetime.date(2023, 1, 1), Decimal('19000.00'))\n", 85 | "(4, 2, datetime.date(2021, 1, 1), Decimal('9000.00'))\n", 86 | "(5, 2, datetime.date(2022, 1, 1), Decimal('15000.00'))\n", 87 | "(6, 2, datetime.date(2023, 1, 1), Decimal('12000.00'))\n", 88 | "(7, 1, datetime.date(2021, 1, 1), Decimal('5000.00'))\n", 89 | "(8, 1, datetime.date(2022, 1, 1), Decimal('16000.00'))\n", 90 | "(9, 1, datetime.date(2023, 1, 1), Decimal('8000.00'))\n", 91 | "(10, 2, datetime.date(2021, 1, 1), Decimal('19000.00'))\n", 92 | "(11, 2, datetime.date(2022, 1, 1), Decimal('2000.00'))\n", 93 | "(12, 2, datetime.date(2023, 1, 1), Decimal('18000.00'))\n", 94 | "(13, 1, datetime.date(2021, 1, 1), Decimal('15000.00'))\n", 95 | "(14, 1, datetime.date(2022, 1, 1), Decimal('4000.00'))\n", 96 | "(15, 1, datetime.date(2023, 1, 1), Decimal('12000.00'))\n", 97 | "(16, 2, datetime.date(2021, 1, 1), Decimal('5000.00'))\n", 98 | "(17, 2, datetime.date(2022, 1, 1), Decimal('5000.00'))\n", 99 | "(18, 2, datetime.date(2023, 1, 1), Decimal('18000.00'))\n", 100 | "(19, 1, datetime.date(2021, 1, 1), Decimal('19000.00'))\n", 101 | "(20, 2, datetime.date(2022, 1, 1), Decimal('19000.00'))\n" 102 | ] 103 | } 104 | ], 105 | "source": [ 106 | "#Connect to the OceanBase database in Docker (after set up in DBeaver)\n", 107 | "conn = pymysql.connect(\n", 108 | " host=\"127.0.0.1\",\n", 109 | " port=2883,\n", 110 | " user=\"root\",\n", 111 | " passwd=\"rootPWD123\",\n", 112 | " db=\"jamesdatabase\"\n", 113 | ")\n", 114 | "\n", 115 | "try:\n", 116 | " with conn.cursor() as cur:\n", 117 | " cur.execute('SELECT * FROM sales')\n", 118 | " ans = cur.fetchall()\n", 119 | " for line in ans:\n", 120 | " print(line)\n", 121 | "\n", 122 | "finally:\n", 123 | " conn.close()" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": null, 129 | "metadata": {}, 130 | "outputs": [], 131 | "source": [] 132 | } 133 | ], 134 | "metadata": { 135 | "kernelspec": { 136 | "display_name": "Python 3", 137 | "language": "python", 138 | "name": "python3" 139 | }, 140 | "language_info": { 141 | "codemirror_mode": { 142 | "name": "ipython", 143 | "version": 3 144 | }, 145 | "file_extension": ".py", 146 | "mimetype": "text/x-python", 147 | "name": "python", 148 | "nbconvert_exporter": "python", 149 | "pygments_lexer": "ipython3", 150 | "version": "3.8.2" 151 | }, 152 | "orig_nbformat": 4 153 | }, 154 | "nbformat": 4, 155 | "nbformat_minor": 2 156 | } 157 | --------------------------------------------------------------------------------