{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "60b87c23-996d-4c80-8846-f30e6bf9ebfc",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Token successfully refreshed.\n"
     ]
    }
   ],
   "source": [
    "%update_token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "d2038e9a-9c82-4898-b121-babc4dd156b2",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import warnings\n",
    "warnings.filterwarnings(\"ignore\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "78a98f8c-1752-45ea-a42f-bf37d3862f39",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<span style=\"None\">Running query in &#x27;presto://ezpresto-sts-mst-0.ezpresto-svc-hdl.ezpresto.svc.cluster.local:8081&#x27;</span>"
      ],
      "text/plain": [
       "Running query in 'presto://ezpresto-sts-mst-0.ezpresto-svc-hdl.ezpresto.svc.cluster.local:8081'"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "select * from cache.retail.retailagg1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "    <thead>\n",
       "        <tr>\n",
       "            <th>store</th>\n",
       "            <th>year</th>\n",
       "            <th>country</th>\n",
       "            <th>totqty</th>\n",
       "            <th>totsales</th>\n",
       "        </tr>\n",
       "    </thead>\n",
       "    <tbody>\n",
       "        <tr>\n",
       "            <td>Store D</td>\n",
       "            <td>2021</td>\n",
       "            <td>Czech Republic</td>\n",
       "            <td>1415065</td>\n",
       "            <td>20763310.75</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>Store D</td>\n",
       "            <td>2019</td>\n",
       "            <td>Swiss</td>\n",
       "            <td>29247150</td>\n",
       "            <td>394023854.99</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>Store E</td>\n",
       "            <td>2021</td>\n",
       "            <td>Swiss</td>\n",
       "            <td>29714055</td>\n",
       "            <td>400286738.09</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>Store A</td>\n",
       "            <td>2023</td>\n",
       "            <td>Swiss</td>\n",
       "            <td>33516058</td>\n",
       "            <td>451288092.37</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>Store D</td>\n",
       "            <td>2023</td>\n",
       "            <td>Swiss</td>\n",
       "            <td>46174112</td>\n",
       "            <td>621087039.29</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>Store E</td>\n",
       "            <td>2019</td>\n",
       "            <td>Czech Republic</td>\n",
       "            <td>1392899</td>\n",
       "            <td>24136123.33</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>Store A</td>\n",
       "            <td>2020</td>\n",
       "            <td>Czech Republic</td>\n",
       "            <td>2155248</td>\n",
       "            <td>32678250.64</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>Store B</td>\n",
       "            <td>2020</td>\n",
       "            <td>Swiss</td>\n",
       "            <td>69268812</td>\n",
       "            <td>958354298.13</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>Store C</td>\n",
       "            <td>2022</td>\n",
       "            <td>Swiss</td>\n",
       "            <td>38640558</td>\n",
       "            <td>550076306.28</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>Store B</td>\n",
       "            <td>2023</td>\n",
       "            <td>Swiss</td>\n",
       "            <td>28926638</td>\n",
       "            <td>389724220.29</td>\n",
       "        </tr>\n",
       "    </tbody>\n",
       "</table>\n",
       "<span style='font-style:italic;font-size:11px'><code>ResultSet</code> : to convert to pandas, call <a href='https://jupysql.ploomber.io/en/latest/integrations/pandas.html'><code>.DataFrame()</code></a> or to polars, call <a href='https://jupysql.ploomber.io/en/latest/integrations/polars.html'><code>.PolarsDataFrame()</code></a></span><br>\n",
       "<span style=\"font-style:italic;text-align:center;\">Truncated to displaylimit of 10</span><br><span style=\"font-style:italic;text-align:center;\">If you want to see more, please visit <a href=\"https://jupysql.ploomber.io/en/latest/api/configuration.html#displaylimit\">displaylimit</a> configuration</span>"
      ],
      "text/plain": [
       "+---------+------+----------------+----------+--------------+\n",
       "|  store  | year |    country     |  totqty  |   totsales   |\n",
       "+---------+------+----------------+----------+--------------+\n",
       "| Store D | 2021 | Czech Republic | 1415065  | 20763310.75  |\n",
       "| Store D | 2019 |     Swiss      | 29247150 | 394023854.99 |\n",
       "| Store E | 2021 |     Swiss      | 29714055 | 400286738.09 |\n",
       "| Store A | 2023 |     Swiss      | 33516058 | 451288092.37 |\n",
       "| Store D | 2023 |     Swiss      | 46174112 | 621087039.29 |\n",
       "| Store E | 2019 | Czech Republic | 1392899  | 24136123.33  |\n",
       "| Store A | 2020 | Czech Republic | 2155248  | 32678250.64  |\n",
       "| Store B | 2020 |     Swiss      | 69268812 | 958354298.13 |\n",
       "| Store C | 2022 |     Swiss      | 38640558 | 550076306.28 |\n",
       "| Store B | 2023 |     Swiss      | 28926638 | 389724220.29 |\n",
       "+---------+------+----------------+----------+--------------+"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%sql\n",
    "select * from cache.retail.retailagg1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "51a46f64-e18a-4a4c-9b43-ebacacdb2057",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<span style=\"None\">Running query in &#x27;presto://ezpresto-sts-mst-0.ezpresto-svc-hdl.ezpresto.svc.cluster.local:8081&#x27;</span>"
      ],
      "text/plain": [
       "Running query in 'presto://ezpresto-sts-mst-0.ezpresto-svc-hdl.ezpresto.svc.cluster.local:8081'"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "(select * from cache.retail.retailagg1)\n"
     ]
    }
   ],
   "source": [
    "output = %sql (select * from cache.retail.retailagg1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "5b9ec60c-739f-41cb-81c3-143dee5f50e4",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "sql.run.resultset.ResultSet"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(output)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "a542a51a-b1f1-47d2-aaf9-023a15080a57",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.frame.DataFrame"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = output.DataFrame()\n",
    "type(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "76614a4b-6696-470a-be9d-f57ab8fa48e2",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 50 entries, 0 to 49\n",
      "Data columns (total 5 columns):\n",
      " #   Column    Non-Null Count  Dtype \n",
      "---  ------    --------------  ----- \n",
      " 0   store     50 non-null     object\n",
      " 1   year      50 non-null     int64 \n",
      " 2   country   50 non-null     object\n",
      " 3   totqty    50 non-null     int64 \n",
      " 4   totsales  50 non-null     object\n",
      "dtypes: int64(2), object(3)\n",
      "memory usage: 2.1+ KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "a1e8d574-0268-42ea-a78d-b0a62e9b36cb",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>store</th>\n",
       "      <th>year</th>\n",
       "      <th>country</th>\n",
       "      <th>totqty</th>\n",
       "      <th>totsales</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>Store A</td>\n",
       "      <td>2021</td>\n",
       "      <td>Czech Republic</td>\n",
       "      <td>1617376</td>\n",
       "      <td>23730424.94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>Store B</td>\n",
       "      <td>2021</td>\n",
       "      <td>Czech Republic</td>\n",
       "      <td>704409</td>\n",
       "      <td>10338684.56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>Store C</td>\n",
       "      <td>2019</td>\n",
       "      <td>Czech Republic</td>\n",
       "      <td>1403037</td>\n",
       "      <td>23444291.23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>Store D</td>\n",
       "      <td>2020</td>\n",
       "      <td>Czech Republic</td>\n",
       "      <td>2522428</td>\n",
       "      <td>36377005.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>Store C</td>\n",
       "      <td>2023</td>\n",
       "      <td>Czech Republic</td>\n",
       "      <td>2076871</td>\n",
       "      <td>32298143.98</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      store  year         country   totqty     totsales\n",
       "45  Store A  2021  Czech Republic  1617376  23730424.94\n",
       "46  Store B  2021  Czech Republic   704409  10338684.56\n",
       "47  Store C  2019  Czech Republic  1403037  23444291.23\n",
       "48  Store D  2020  Czech Republic  2522428  36377005.10\n",
       "49  Store C  2023  Czech Republic  2076871  32298143.98"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d60fadd2-c889-41ee-8087-cad54fac8f6f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
