<?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: Alberto Robertson</title>
    <description>The latest articles on DEV Community by Alberto Robertson (@alberto_robertson).</description>
    <link>https://dev.to/alberto_robertson</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2727589%2F29d1cde6-f3d3-44e1-af22-094aa1a8e860.jpg</url>
      <title>DEV Community: Alberto Robertson</title>
      <link>https://dev.to/alberto_robertson</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alberto_robertson"/>
    <language>en</language>
    <item>
      <title>Running SQL on files with the esProc is very convenient, on par with duckDB</title>
      <dc:creator>Alberto Robertson</dc:creator>
      <pubDate>Sun, 26 Jan 2025 06:05:51 +0000</pubDate>
      <link>https://dev.to/alberto_robertson/running-sql-on-files-with-the-esproc-is-very-convenient-on-par-with-duckdb-37cm</link>
      <guid>https://dev.to/alberto_robertson/running-sql-on-files-with-the-esproc-is-very-convenient-on-par-with-duckdb-37cm</guid>
      <description>&lt;p&gt;esProc SPL, to query CSV, JSON, Excel and other files, you can use it directly after installation, which is very convenient.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fopmiwdg4f4nmrqmk8zfu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fopmiwdg4f4nmrqmk8zfu.png" alt="source" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Query orders with sales volume greater than 1 from CSV:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$select * from D:/data/orders.csv where quantity&amp;gt;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The results of each step are saved in a cell, and the next step can be based on the above results to continue querying. For example, if you also want to calculate the sales of each product with a sales volume greater than 1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$select product,sum(amount) from {A1} group by product
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result of the previous step can be referenced using {cell name}.&lt;/p&gt;

&lt;p&gt;Of course, a single SQL statement can also implement this task, but what if both of these results are what you want? What if we need to calculate the number of orders with a unit price of 100 or more in orders with sales volume greater than 1? Moreover, for some complex calculations, the excessively long SQL may appear blurry. With this ’ SQL step-by-step mechanism ’, it is easy to reuse and simplify calculations.&lt;/p&gt;

&lt;p&gt;In addition to being used in IDEs, it also offer the JDBC driver and can be integrated in applications to serve as an embedded database.&lt;/p&gt;

&lt;p&gt;A slight drawback is that the SQL provided by esProc is not comprehensive enough, it is only a subset of SQL92. There are no problems with regular ones, including subqueries and WITH. However, EXISTS is not yet supported, and there is no window function available.&lt;/p&gt;

&lt;p&gt;For tasks that require more complex SQL to support, esProc provides a more powerful native language SPL.&lt;/p&gt;

&lt;p&gt;For example, this SQL statement uses the KEEP function unique to ORACLE, and using SQL of other databases would be more cumbersome:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT department_id, 
MIN(salary) KEEP (DENSE_RANK FIRST ORDER BY commission_pct) worst, 
MAX(salary) KEEP (DENSE_RANK LAST ORDER BY commission_pct) best 
FROM employees 
GROUP BY department_id 
ORDER BY department_id
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SPL has good support for order-related calculations, and it is relatively simple to write:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdouyj6nklexc9icrb1pj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdouyj6nklexc9icrb1pj.png" alt="SPL code" width="800" height="116"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Symbols like ~ often appear in SPL code, which can be confusing at first glance. This is a unique syntax of SPL, and once understood, it becomes very convenient.&lt;/p&gt;

&lt;p&gt;In esProc, SQL and SPL syntax can also be used in combination. Regardless of how the results are calculated earlier, they are saved in the cells and can continue to be calculated using SQL later. The more common mixed usage pattern is to handle irregular formats and data sources.&lt;/p&gt;

&lt;p&gt;For example, colon separated text:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$select * from {file("d:/Orders.txt").import@t(;":")}
where Amount&amp;gt;=100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Writing SPL code into {} can be used as a table.&lt;br&gt;
Read the specified sheet in Excel:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$select * from {file("D:/Orders.xlsx").xlsimport@t(;"sheet3")}
where Amount&amp;gt;=100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read Restful data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$select * from {json(httpfile("http://127.0.0.1:6868/api/getData").read())}
where Amount&amp;gt;=100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If SQL can handle it, use SQL. If SQL can’t do it or you can’t work it out, use SPL. It’s a completely seamless mix, which is superior than DuckDB, which relies on Python for complex calculations.&lt;/p&gt;

&lt;p&gt;esProc is open source, and its source code is available here: &lt;a href="https://github.com/SPLWare/esProc" rel="noopener noreferrer"&gt;esProcSPL&lt;/a&gt;&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>programming</category>
      <category>esproc</category>
      <category>duckdb</category>
    </item>
  </channel>
</rss>
