# Parsing SQL queries using ruby; any recommended gem package?

**URL:** <https://discuss.elastic.co/t/parsing-sql-queries-using-ruby-any-recommended-gem-package/284132>\
**Category:** Logstash\
**Created:** [September 14, 2021, 2:44am UTC](https://discuss.elastic.co/t/parsing-sql-queries-using-ruby-any-recommended-gem-package/284132 "2021-09-14T02:44:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SHINRA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shinra/32/46751_2.png) [@SHINRA](https://discuss.elastic.co/u/SHINRA)\
**Post date:** [September 14, 2021, 2:44am UTC](https://discuss.elastic.co/t/parsing-sql-queries-using-ruby-any-recommended-gem-package/284132/1 "2021-09-14T02:44:08Z")

</div>

Hi,

I'm new to Ruby language and I thought I could still do a simple task of normalizing + parsing SQL query using some third party library; but I had no luck finding any that works to my intention.

Here's what I'm trying to do:

Query like below

```auto
select 
     table_1.userId as col_0_0_ 
from tbUserTable table_1 
     where table_1.createdDate between '2021-05-23 00:00:00.0' and '2021-05-23 23:59:59.999' 
group by table_1.userId; 

```

will transform into JSON like below

```auto

{
"select": 
    {"value": "table_1.userId", "name": "col_0_0_"}, 
"from": 
     {
          "value": "tbUserTable",
          "name": "table_1"}, 
"where": {
          "between": ["table_1.createdDate", 0, 0]
}, 
"groupby": {"value": "table_1.userId"}
     }
}

```

**Also please note that the parameters inside WHERE condition has been normalized to 0, 0.**

If there is any Ruby Gem package that I could use on Logstash ruby filter that anybody's aware of, I'd love to know!

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 12, 2021, 2:45am UTC](https://discuss.elastic.co/t/parsing-sql-queries-using-ruby-any-recommended-gem-package/284132/2 "2021-10-12T02:45:08Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
