<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Saad Chaudhry on Medium]]></title>
        <description><![CDATA[Stories by Saad Chaudhry on Medium]]></description>
        <link>https://medium.com/@saad.bsit?source=rss-6d3d9d5d89------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*tzpJJlpM_GFpBlhD</url>
            <title>Stories by Saad Chaudhry on Medium</title>
            <link>https://medium.com/@saad.bsit?source=rss-6d3d9d5d89------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 09:41:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saad.bsit/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Glue Crawler optimization/alternative | Athena use case]]></title>
            <link>https://medium.datadriveninvestor.com/glue-crawler-optimization-alternative-athena-use-case-15cc5bdd94d6?source=rss-6d3d9d5d89------2</link>
            <guid isPermaLink="false">https://medium.com/p/15cc5bdd94d6</guid>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[aws-glue]]></category>
            <category><![CDATA[athena]]></category>
            <dc:creator><![CDATA[Saad Chaudhry]]></dc:creator>
            <pubDate>Mon, 09 Mar 2020 10:29:08 GMT</pubDate>
            <atom:updated>2020-06-15T12:37:11.908Z</atom:updated>
            <content:encoded><![CDATA[<p>The aim of this blog is to see different alternatives to Glue Crawler in order to query data from S3 using AWS Athena. Here we will discuss a few alternatives where we can avoid crawlers, however these can be tuned as per use case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*Unu8mdMDigHGXLhLPdeYyA.png" /><figcaption>Photo By <a href="https://medium.com/@aliatakan">Ali Atakan</a> on <a href="https://medium.com/">Medium</a></figcaption></figure><p>“Amazon Athena is a query service that is used to query data that reside on AWS S3. Athena allows you to run standard SQL queries to query data from S3.”</p><p>“AWS <strong>Glue crawler</strong> is used to connect to a data store, progresses through a priority list of the classifiers used to extract the schema of the data and other statistics, and inturn populate the <strong>Glue</strong> Data Catalog with the help of the metadata.”</p><p>Crawlers are needed to analyze data in specified S3 location and generate/update <strong>Glue Data Catalog</strong> which basically is a meta-store for actual data (similar to <a href="https://cwiki.apache.org/confluence/display/Hive/Design#Design-Metastore">Hive metastore</a>). In other words it persists information about physical location of data, its schema, format and partitions which makes it possible to query actual data via Athena or to load it in Glue jobs.</p><p>So with these great perks, it also has a cost factor which is:<br>* <strong>$0.44 per DPU-Hour,</strong> billed per second, with a 10-minute minimum per crawler run.<br>For more information about pricing visit this <a href="https://aws.amazon.com/glue/pricing/">link</a>.</p><p><strong>Example:</strong><br>Consider a Big data project, in which crawlers are massively used when the pipelines are scheduled or running as per required with loads of data coming in residing on S3. For every pipeline run, <strong>new partitions</strong> of data are formed and this information needs to be updated in Glue Data Catalog in order to query data on those partitions using Athena.</p><p>We know AWS recommended way for above use case is running Glue Crawler,<br><strong>What are the other ways?</strong></p><p>Athena DDL statements, you can avoid crawler and create external tables:<br>create external table Student(col1 string, col2 string) partitioned by (dept string) location &#39;ANY_S3_LOCATION&#39;;</p><p><strong>For example for CSV file:</strong></p><pre>CREATE EXTERNAL TABLE `student`(<br> `code` string, <br> `state` string)<br>PARTITIONED BY ( <br> `process` string)<br>ROW FORMAT DELIMITED <br> FIELDS TERMINATED BY ‘,’ <br>STORED AS INPUTFORMAT <br> ‘org.apache.hadoop.mapred.TextInputFormat’ <br>OUTPUTFORMAT <br> ‘org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat’<br>LOCATION<br> ‘s3://bucket/tablefolder/’<br>TBLPROPERTIES ( <br> ‘classification’=’csv’, <br> ‘columnsOrdered’=’true’, <br> ‘compressionType’=’none’, <br> ‘delimiter’=’,’, <br> ‘typeOfData’=’file’)</pre><p>Suppose currently it contains two partitions:</p><pre>1) s3://bucket/student/process=1/</pre><pre>2) s3://bucket/student/process=2/</pre><p>To add a new partition, you can simply run an alter table command:</p><pre>ALTER TABLE student ADD PARTITION (process = ‘3’) LOCATION ‘s3://bucket/student/process=3/’</pre><p>The other way to update partition information is to simply load partition using:</p><pre>MSCK REPAIR TABLE student;</pre><p>Above given commands can also be executed in supported programming environments for example python:</p><pre><em>athena = boto3.client(‘athena’)<br>response = athena.start_query_execution(<br> QueryString = “MSCK REPAIR TABLE </em>student<em>”,<br> QueryExecutionContext={<br> ‘Database’: ‘somedb’<br> },<br> ResultConfiguration = {<br> ‘OutputLocation’: “s3://bucket/</em>student<em>/”<br> })</em></pre><p>Or for Alter Table operation you can get list of partitions and run create_partition/batch_create_partition for new partitions.</p><pre>response = glue_client.get_partitions(<br> DatabaseName=’hira-glue-database’,<br> TableName=’glue_testa’<br>)<br>partition_list = response[‘Partitions’]</pre><p>Create new partition:</p><pre>create_partition_response = client.batch_create_partition(<br>        DatabaseName=l_database,<br>        TableName=l_table,<br>        PartitionInputList=each_input<br>    )</pre><pre>There is a limit of 100 partitions in a single api call Or for other queries like alter table.</pre><pre>params = {</pre><pre>‘region’: ‘eu-central-1’,</pre><pre>‘database’: ‘databasename’,</pre><pre>‘bucket’: ‘your-bucket-name’,</pre><pre>‘path’: ‘temp/athena/output’,</pre><pre>‘query’: ‘SELECT * FROM tablename LIMIT 100’</pre><pre>}</pre><pre>response = client.start_query_execution(</pre><pre>QueryString=params[“query”],</pre><pre>QueryExecutionContext={ ‘Database’: params[‘database’] },</pre><pre>ResultConfiguration={ ‘OutputLocation’: ‘s3://’ + params[‘bucket’] + ‘/’ + params[‘path’] }</pre><pre>)</pre><p><strong>Note:</strong></p><p>“ There’s no charge for DDL queries or for partition detection.”</p><p>“Athena does not individually charge you for these requests, but S3 GET charges do apply. Also, MSCK will scan all the partitions. If you are syncing partitions, its better to use Alter Table commands.”</p><p>“ MSCK REPAIR TABLE gets <strong>super slow</strong> once you have many partitions. Slow to the point where you might not even be able to run it anymore, since your queries are limited to 30 min.”</p><p><strong>Conclusion:</strong></p><blockquote>In short, in the use cases where we have static or non-frequent changing schema we can opt for Athena DDL in place of Glue Crawlers for cost efficiency, however for frequently changing schema Crawler will be architecturally a better choice.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15cc5bdd94d6" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/glue-crawler-optimization-alternative-athena-use-case-15cc5bdd94d6">Glue Crawler optimization/alternative | Athena use case</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>