{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d25b0462",
   "metadata": {},
   "source": [
    "### Snowflake"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "df264b39",
   "metadata": {},
   "source": [
    "![image.png](https://github.com/hksahil/Python-101/blob/master/Images/symbol.PNG?raw=true)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "69cf2075",
   "metadata": {},
   "source": [
    "- Datawarehouse\n",
    "- Saas\n",
    "- Inbuilt scalable Computing power\n",
    "- Uses cloud to store the data in the Backend\n",
    "    - If AWS - S3\n",
    "    - If Azure - Azure Blob Storage\n",
    "- Automatic Caching of results in Caching layer\n",
    "- Can be connected to JDBC,ODBC drivers as well"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e666d73c",
   "metadata": {},
   "source": [
    "### How Data is processed under the Hood in Snowflake"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4bea5d2",
   "metadata": {},
   "source": [
    "- You can Check the Execution Plan of the Query\n",
    "    - Click on History>Query ID\n",
    "        - Execution Plan opens with Details and PRofile Page"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "affc8bfd",
   "metadata": {},
   "source": [
    "### Creating a Database"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1b5e22b6",
   "metadata": {},
   "source": [
    "`CREATE DATABASE First_DB`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b93310bf",
   "metadata": {},
   "source": [
    "- It will create empty database"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bd08f6cf",
   "metadata": {},
   "source": [
    "### Creating a Table in our Database"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "22286f3f",
   "metadata": {},
   "source": [
    "`CREATE TABLE First_Table(\n",
    "First_name String,\n",
    "address String\n",
    ");`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e416d118",
   "metadata": {},
   "source": [
    "- Refresh the Database\n",
    "- It will create\n",
    "    - Look into Public>Tables (Public is schema)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e0c95d66",
   "metadata": {},
   "source": [
    "### Loading the Data into the Table"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e9ffaac3",
   "metadata": {},
   "source": [
    "- You need to switch to Staging area and connect to S3 bucket using URL (can be csv)\n",
    "- Create the Staging Area\n",
    "    - `CREATE OR REPLACE staging_area URL='http://demo'`\n",
    "- Load the data\n",
    "    - `COPY INTO FIRST_TABLE FROM url file_format=(type-csv field_delimiter=',' skip_header=1)`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "07438fa7",
   "metadata": {},
   "source": [
    "### Querying our Table"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dd0601d8",
   "metadata": {},
   "source": [
    "`Select *  from First_Table`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a4afce92",
   "metadata": {},
   "source": [
    " ### Limitation of Snowflake"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b2de16cd",
   "metadata": {},
   "source": [
    "- If multiple queries,you can't check the syntax errors until the execution is done"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}