<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Emirhan Güven</title>
    <description>The latest articles on DEV Community by Emirhan Güven (@azorkai).</description>
    <link>https://dev.to/azorkai</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4104121%2F3f1ecced-ea9a-452b-9399-17e5ccffea36.jpg</url>
      <title>DEV Community: Emirhan Güven</title>
      <link>https://dev.to/azorkai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/azorkai"/>
    <language>en</language>
    <item>
      <title>Four traps in querying 1.79M Overture Maps records with DuckDB</title>
      <dc:creator>Emirhan Güven</dc:creator>
      <pubDate>Tue, 01 Sep 2026 10:18:27 +0000</pubDate>
      <link>https://dev.to/azorkai/four-traps-in-querying-179m-overture-maps-records-with-duckdb-4231</link>
      <guid>https://dev.to/azorkai/four-traps-in-querying-179m-overture-maps-records-with-duckdb-4231</guid>
      <description>&lt;p&gt;We needed a business directory for Turkey inside our CRM, so we went to&lt;br&gt;
&lt;a href="https://overturemaps.org/" rel="noopener noreferrer"&gt;Overture Maps&lt;/a&gt; places: open, CDLA-Permissive, no API key,&lt;br&gt;
no quota, ~1.8M Turkish records sitting in public GeoParquet on S3.&lt;/p&gt;

&lt;p&gt;Reading it turned out to be the easy part. Here are the four things that actually cost us&lt;br&gt;
time, and the numbers that came out the other end.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. A join against remote parquet does not stream
&lt;/h2&gt;

&lt;p&gt;The obvious query is one statement: read the places theme, read the divisions theme, keep&lt;br&gt;
the rows whose point falls inside a Turkish province.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Do not do this against S3.&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;read_parquet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'s3://.../theme=places/*/*'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hive_partitioning&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;
&lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;regions&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;ST_Within&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;geometry&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;geom&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;country&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'TR'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;DuckDB materialises that join before it emits a single row. Ours sat at &lt;strong&gt;2.5 GB of RAM&lt;br&gt;
and produced nothing after fifteen minutes&lt;/strong&gt;, with no way to tell whether it was making&lt;br&gt;
progress.&lt;/p&gt;

&lt;p&gt;The fix is boring and works: &lt;strong&gt;two stages&lt;/strong&gt;. Stage one pulls the country down with a plain&lt;br&gt;
bounding box and zero spatial work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TEMP&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;places_tr&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="k"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;primary&lt;/span&gt;        &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;primary&lt;/span&gt;   &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;category&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="n"&gt;websites&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;          &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;website&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="n"&gt;bbox&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ymin&lt;/span&gt;            &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;lat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="n"&gt;bbox&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;xmin&lt;/span&gt;            &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;lon&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="n"&gt;geometry&lt;/span&gt;             &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;geom&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;read_parquet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'s3://.../theme=places/*/*'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hive_partitioning&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;bbox&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;xmin&lt;/span&gt; &lt;span class="k"&gt;BETWEEN&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="mi"&gt;45&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;bbox&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ymin&lt;/span&gt; &lt;span class="k"&gt;BETWEEN&lt;/span&gt; &lt;span class="mi"&gt;35&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;
  &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="k"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;primary&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
  &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;operating_status&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="n"&gt;operating_status&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'closed'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A rectangle over Turkey also sweeps in slivers of Greece, Bulgaria and Georgia. That is&lt;br&gt;
fine, stage two throws them out. Stage two then loops province by province, so each join&lt;br&gt;
touches one polygon and a few thousand candidate rows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;places_tr&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tr_regions&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;region_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'İzmir'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;ST_Within&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;geom&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;geom&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every step is bounded and you can watch it progress. Same result, and the whole run&lt;br&gt;
finishes instead of hanging.&lt;/p&gt;
&lt;h2&gt;
  
  
  2. 81 provinces, more than 81 polygons
&lt;/h2&gt;

&lt;p&gt;Turkey has 81 provinces. Overture's divisions theme hands you more rows than that: Adana,&lt;br&gt;
Antalya and Artvin each arrive twice, as separate geometries. If you loop over the raw&lt;br&gt;
rows you process those provinces (and their companies) twice.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TEMP&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;tr_regions&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;region_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ST_Union_Agg&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;geom&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;geom&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;primary&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;region_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;geometry&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;geom&lt;/span&gt;
  &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;read_parquet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'.../theme=divisions/*/*'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hive_partitioning&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;country&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'TR'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;subtype&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'region'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="k"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;primary&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;region_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ST_Union_Agg&lt;/code&gt; merges the duplicates into one polygon per name. One line, and it removes a&lt;br&gt;
whole class of double-counting bugs downstream.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. The address field will not tell you the province
&lt;/h2&gt;

&lt;p&gt;This is the one worth knowing before you plan anything. Overture's address &lt;code&gt;region&lt;/code&gt; field&lt;br&gt;
is &lt;strong&gt;null on roughly 92% of Turkish records&lt;/strong&gt;, and inconsistent on the rest. There is no&lt;br&gt;
salvaging it. Province has to be assigned geographically, from coordinates.&lt;/p&gt;

&lt;p&gt;And it has to be a real point-in-polygon test, not a bounding box. Province bounding boxes&lt;br&gt;
overlap heavily; picking the smallest containing box puts &lt;strong&gt;central İzmir in Manisa&lt;/strong&gt; and&lt;br&gt;
&lt;strong&gt;central Antalya in Burdur&lt;/strong&gt;. We found that the entertaining way.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Lone surrogates will abort your bulk insert
&lt;/h2&gt;

&lt;p&gt;Loading the results into Postgres with Npgsql's binary &lt;code&gt;COPY&lt;/code&gt;, the batch died on real&lt;br&gt;
company names. The cause: &lt;strong&gt;lone surrogates&lt;/strong&gt;, half of an emoji pair, usually from a&lt;br&gt;
truncated source record. Npgsql's UTF-8 encoder throws on those and takes the whole batch&lt;br&gt;
with it.&lt;/p&gt;

&lt;p&gt;Two details that cost us a second round trip:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Truncating a string to a column width can &lt;em&gt;split&lt;/em&gt; a valid surrogate pair, so sanitising
has to run &lt;strong&gt;after&lt;/strong&gt; truncation, not before.&lt;/li&gt;
&lt;li&gt;Null bytes need dropping outright; Postgres rejects them in text columns.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What it bought
&lt;/h2&gt;

&lt;p&gt;Querying Overture's S3 parquet directly from a Turkish host: &lt;strong&gt;277 seconds&lt;/strong&gt; for a single&lt;br&gt;
province. The same query against the local Postgres catalogue: &lt;strong&gt;15 ms&lt;/strong&gt;. That is the&lt;br&gt;
difference between a feature and a batch job.&lt;/p&gt;

&lt;h2&gt;
  
  
  And then the actual finding
&lt;/h2&gt;

&lt;p&gt;With 1,786,700 businesses loaded, we asked how many of them have a website. The field says&lt;br&gt;
&lt;strong&gt;684,496, or 38.3%&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So we requested every one of those addresses. &lt;strong&gt;413,777 answered.&lt;/strong&gt; The rest time out,&lt;br&gt;
refuse the connection, or sit on an expired domain.&lt;/p&gt;

&lt;p&gt;The honest national figure is &lt;strong&gt;23.2%&lt;/strong&gt;: roughly one Turkish business in four can be&lt;br&gt;
reached on the web at all. Meanwhile 542,323 businesses publish a phone number and no&lt;br&gt;
website whatsoever.&lt;/p&gt;

&lt;p&gt;The same gap shows up in the socials array, in the other direction: Overture has Facebook&lt;br&gt;
on 95.3% of Turkish records but Instagram on only ~14k, an artefact of when the source&lt;br&gt;
listings were assembled. Crawling the company websites we could reach found Instagram on&lt;br&gt;
about 36% of them, taking the count to 232,928. &lt;strong&gt;Treat a populated field as a claim, not&lt;br&gt;
a measurement.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The data is open
&lt;/h2&gt;

&lt;p&gt;Everything above is published under CC BY 4.0, province and sector breakdowns included:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Report and tables: &lt;a href="https://crmsolid.com/research/turkey-business-digital-report" rel="noopener noreferrer"&gt;crmsolid.com/research/turkey-business-digital-report&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;CSV, JSON and the SQL that produces the figures: &lt;a href="https://github.com/CRM-Solid/turkey-business-digital-data" rel="noopener noreferrer"&gt;github.com/CRM-Solid/turkey-business-digital-data&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Archived with a DOI: &lt;a href="https://doi.org/10.5281/zenodo.22217770" rel="noopener noreferrer"&gt;10.5281/zenodo.22217770&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are working with Overture in another country, I would genuinely like to know&lt;br&gt;
whether the &lt;code&gt;region&lt;/code&gt; field is as empty there as it is here.&lt;/p&gt;

</description>
      <category>duckdb</category>
      <category>sql</category>
      <category>opendata</category>
      <category>dotnet</category>
    </item>
  </channel>
</rss>
