{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[](https://github.com/aws/aws-sdk-pandas)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 29 - S3 Select"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "AWS SDK for pandas supports [Amazon S3 Select](https://aws.amazon.com/blogs/aws/s3-glacier-select/), enabling applications to use SQL statements in order to query and filter the contents of a single S3 object. It works on objects stored in CSV, JSON or Apache Parquet, including compressed and large files of several TBs.\n",
    "\n",
    "With S3 Select, the query workload is delegated to Amazon S3, leading to lower latency and cost, and to higher performance (up to 400% improvement). This is in comparison with other awswrangler operations such as `read_parquet` where the S3 object is downloaded and filtered on the client-side.\n",
    "\n",
    "This feature has a number of limitations however:\n",
    "\n",
    "- The maximum length of a record in the input or result is 1 MB\n",
    "- The maximum uncompressed row group size is 256 MB (Parquet only)\n",
    "- It can only emit nested data in JSON format\n",
    "- Certain SQL operations are not supported (e.g. ORDER BY)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Read multiple Parquet files from an S3 prefix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "
\n",
       "\n",
       "
\n",
       "  \n",
       "    \n",
       "      | \n",
       " | marketplace\n",
       " | customer_id\n",
       " | review_id\n",
       " | product_id\n",
       " | product_parent\n",
       " | star_rating\n",
       " | helpful_votes\n",
       " | total_votes\n",
       " | vine\n",
       " | verified_purchase\n",
       " | review_headline\n",
       " | review_body\n",
       " | review_date\n",
       " | year\n",
       " | 
\n",
       "  \n",
       "  \n",
       "    \n",
       "      | 0\n",
       " | US\n",
       " | 52670295\n",
       " | RGPOFKORD8RTU\n",
       " | B0002CZPPG\n",
       " | 867256265\n",
       " | 5\n",
       " | 105\n",
       " | 107\n",
       " | N\n",
       " | N\n",
       " | Excellent Gift Idea\n",
       " | I wonder if the other reviewer actually read t...\n",
       " | 2005-02-08\n",
       " | 2005\n",
       " | 
\n",
       "    \n",
       "      | 1\n",
       " | US\n",
       " | 29964102\n",
       " | R2U8X8V5KPB4J3\n",
       " | B00H5BMF00\n",
       " | 373287760\n",
       " | 5\n",
       " | 0\n",
       " | 0\n",
       " | N\n",
       " | Y\n",
       " | Five Stars\n",
       " | convenience is the name of the game.\n",
       " | 2015-05-03\n",
       " | 2015\n",
       " | 
\n",
       "    \n",
       "      | 2\n",
       " | US\n",
       " | 25173351\n",
       " | R15XV3LXUMLTXL\n",
       " | B00PG40CO4\n",
       " | 137115061\n",
       " | 5\n",
       " | 0\n",
       " | 0\n",
       " | N\n",
       " | Y\n",
       " | Birthday Gift\n",
       " | This gift card was handled with accuracy in de...\n",
       " | 2015-05-03\n",
       " | 2015\n",
       " | 
\n",
       "    \n",
       "      | 3\n",
       " | US\n",
       " | 12516181\n",
       " | R3G6G7H8TX4H0T\n",
       " | B0002CZPPG\n",
       " | 867256265\n",
       " | 5\n",
       " | 6\n",
       " | 6\n",
       " | N\n",
       " | N\n",
       " | Love 'em.\n",
       " | Gotta love these iTunes Prepaid Card thingys. ...\n",
       " | 2005-10-15\n",
       " | 2005\n",
       " | 
\n",
       "    \n",
       "      | 4\n",
       " | US\n",
       " | 38355314\n",
       " | R2NJ7WNBU16YTQ\n",
       " | B00B2TFSO6\n",
       " | 89375983\n",
       " | 5\n",
       " | 0\n",
       " | 0\n",
       " | N\n",
       " | Y\n",
       " | Five Stars\n",
       " | perfect\n",
       " | 2015-05-03\n",
       " | 2015\n",
       " | 
\n",
       "  \n",
       "
\n",
       "
\n",
       "\n",
       "
\n",
       "  \n",
       "    \n",
       "      | \n",
       " | question\n",
       " | product_description\n",
       " | image_url\n",
       " | label\n",
       " | 
\n",
       "  \n",
       "  \n",
       "    \n",
       "      | 0\n",
       " | Will the volca sample get me a girlfriend?\n",
       " | Korg Amplifier Part VOLCASAMPLE\n",
       " | http://ecx.images-amazon.com/images/I/81I1XZea...\n",
       " | 1\n",
       " | 
\n",
       "    \n",
       "      | 1\n",
       " | Can u communicate with spirits even on Saturday?\n",
       " | Winning Moves Games Classic Ouija\n",
       " | http://ecx.images-amazon.com/images/I/81kcYEG5...\n",
       " | 1\n",
       " | 
\n",
       "    \n",
       "      | 2\n",
       " | I won't get hunted right?\n",
       " | Winning Moves Games Classic Ouija\n",
       " | http://ecx.images-amazon.com/images/I/81kcYEG5...\n",
       " | 1\n",
       " | 
\n",
       "    \n",
       "      | 3\n",
       " | I have a few questions.. Can you get possessed...\n",
       " | Winning Moves Games Classic Ouija\n",
       " | http://ecx.images-amazon.com/images/I/81kcYEG5...\n",
       " | 1\n",
       " | 
\n",
       "    \n",
       "      | 4\n",
       " | Has anyone asked where the treasure is? What w...\n",
       " | Winning Moves Games Classic Ouija\n",
       " | http://ecx.images-amazon.com/images/I/81kcYEG5...\n",
       " | 1\n",
       " | 
\n",
       "  \n",
       "
\n",
       "
\n",
       "\n",
       "
\n",
       "  \n",
       "    \n",
       "      | \n",
       " | family_name\n",
       " | contact_details\n",
       " | name\n",
       " | links\n",
       " | gender\n",
       " | image\n",
       " | identifiers\n",
       " | other_names\n",
       " | sort_name\n",
       " | images\n",
       " | given_name\n",
       " | birth_date\n",
       " | id\n",
       " | 
\n",
       "  \n",
       "  \n",
       "    \n",
       "      | 0\n",
       " | Biden\n",
       " | [{'type': 'twitter', 'value': 'joebiden'}]\n",
       " | Joseph Biden, Jr.\n",
       " | [{'note': 'Wikipedia (ace)', 'url': 'https://a...\n",
       " | male\n",
       " | https://theunitedstates.io/images/congress/ori...\n",
       " | [{'identifier': 'B000444', 'scheme': 'bioguide...\n",
       " | [{'lang': None, 'name': 'Joe Biden', 'note': '...\n",
       " | Biden, Joseph\n",
       " | [{'url': 'https://theunitedstates.io/images/co...\n",
       " | Joseph\n",
       " | 1942-11-20\n",
       " | 64239edf-8e06-4d2d-acc0-33d96bc79774\n",
       " | 
\n",
       "  \n",
       "
\n",
       "