Use SQL without Databases

use-sql-without-databases

We have some csv/xls files as the following shows:

SQL is suitable for handling those data, but the language depends on databases to work. We need to install a database and import the data into it to process. This results in bloated application system. Yet such a small task is not worth the effort. Is there a technology that can treat these files as data tables and use SQL to directly query them?

esProc SPL is just what you expect.

esProc SPL is an open-source software, which is offered in https://github.com/SPLWare/esProc.

It provides standard JDBC driver. By importing it in a Java application, we can perform SQL queries directly on files.

Class.forName("com.esproc.jdbc.InternalDriver");
Connection conn =DriverManager.getConnection("jdbc:esproc:local://");
PrepareStatement st = conn.prepareStatement("$select * from employee.txt where SALARY >=? and SALARY);
st.setObject(1, 3000);
st.setObject(2, 5000);
ResultSet result=st.execute();

We can also query a file in SQL from the command line:

esprocx.exe -R select Client,sum(Amount) from d:/Orders.csv group by Client

esProc supports SQL syntax similar to SQL92 standard:

select * from orders.xls where Amount>100 and Area='West' order by OrderDate desc
select Area, sum(Amount) from orders.xls having sum(Amount)>1000
select distinct Company from orders.xls where OrderDate>date('2012-7-1')

Joins:

select o.OrderId,o.Client,e.Name e.Dept from d:/Orders.csv o ,d:/Employees.csv e where o.SellerId=e.Eid
select o.OrderId,o.Client,e.Name e.Dept,e.EId from Orders.txt o left join Employees.txt e on o.SellerId=e.Eid

And subqueries and with statement:

select t.Client, t.s, ct.Name, ct.address from 
   (select Client ,sum(amount) s from Orders.csv group by Client) 
left join ClientTable ct on t.Client=ct.Client
select * from d:/Orders.txt o where o.sellerid in (select eid from Employees.txt)
with t as (select Client ,sum(amount) s from Orders.csv group by Client)
select t.Client, t.s, ct.Name, ct.address from t left join ClientTable ct on t.Client=ct.Client

In fact, esProc does not aim specifically to provide SQL syntax. It has its own SPL syntax and supports the database language based on SPL passingly. This explains its ability to execute SQL without databases.

With the support of SPL, SQL gets a broader range of application scenarios, including those with irregular-format files:

Text files separated by |:

select * from {file("Orders.txt").import@t(;"|")} where Amount>=100 and Client like 'bro' or OrderDate is null

Text files without the title row, where SPL uses ordinal numbers to represent field names:

select * from {file("Orders.txt").import()} where _4>=100 and _2 like 'bro' or _5 is null

Reading a certain sheet from an Excel file:

select * from {file("Orders.xlsx").xlsimport@t(;"sheet3")} where Amount>=100 and Client like 'bro' or OrderDate is null

Querying a JSON file:

select * from {json(file("data.json").read())} where Amount>=100 and Client like 'bro' or OrderDate is null

And handling JSON data downloaded from the web:

select * from {json(httpfile("http://127.0.0.1:6868/api/getData").read())} where Amount>=100 and Client like 'bro' or OrderDate is null

Besides relational databases, SPL can also directly access data coming from MongoDB, Kafka, etc. This forms its mixed computing ability over diverse sources.

Yet, SPL has more abilities than these. From the beginning, the software aims to provide more powerful and more convenient computational capability. SQL syntax has limits in phrasing logics and is more fit for simple scenarios.

Here is an example. To find the largest number of consecutively rising days for a stock, SQL needs a nested query, which is lengthy and hard to read:

select max(ContinuousDays) from (
    select count(*) ContinuousDays from (
        select sum(UpDownTag) over (order by TradeDate) NoRisingDays from (
            select TradeDate,case when Price>lag(price) over ( order by TradeDate)then 0 else 1 end UpDownTag from Stock ))
    group by NoRisingDays )

It is much simpler and easier to write the logic in SPL:

Stock.sort(TradeDate).group@i(Price<Price[-1]).max(~.len())

Apart from all these, esProc provides a WYSIWYG IDE, which enables much more conveniently debugging than SQL:

Read A programming language coding in a grid and get deeper understanding about SPL. The language can replace almost all database computing abilities with yet more powerful performance.

Download SPL here

Check GitHub Repo
Don’t forget to give us a star ⭐ on the repo

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
should-marketers-optimize-for-bing?-[data-+-expert-tips]

Should Marketers Optimize for Bing? [Data + Expert Tips]

Next Post
what-is-headless-seo?-–-whiteboard-friday

What Is Headless SEO? – Whiteboard Friday

Related Posts
harmonyos-next中密码类数据保护场景解析

HarmonyOS Next中密码类数据保护场景解析

本文旨在深入探讨华为鸿蒙HarmonyOS Next系统(截止目前 API12)在开发多语言电商平台方面的技术细节,基于实际开发实践进行总结。主要作为技术分享与交流载体,难免错漏,欢迎各位同仁提出宝贵意见和问题,以便共同进步。本文为原创内容,任何形式的转载必须注明出处及原作者。 在当今数字化时代,密码类数据的保护对于应用的安全性和用户体验至关重要。无论是登录账号、进行金融交易还是访问敏感信息,密码都起着关键的作用。HarmonyOS Next作为一款先进的操作系统,其提供的Asset Store Kit为密码类数据的安全存储和管理提供了强大的解决方案。 (一)引言 密码类数据保护的重要性    – 在移动应用领域,密码类数据是用户身份验证的核心凭证。一旦密码泄露,用户的账号安全将受到严重威胁,可能导致个人信息被窃取、财产遭受损失等严重后果。例如,在金融类应用中,如果用户的登录密码被泄露,黑客可能会非法访问用户的账户,进行转账、消费等操作。因此,确保密码类数据的安全性是应用开发者必须首要考虑的问题。 Asset Store Kit的关键作用    – HarmonyOS…
Read More