RSqLParser – tool to parse your SQL queries.

[This article was first published on R – FordoX, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

A slow performing query is a ticking bomb which can lead to explosion i.e a huge performance overhead in your application, any time specially when there is load on database servers. And knowing the its and bits of your SQL query is of utmost importance in diffusing the bomb.

This is not the only scenario when knowing your SQL is important. From your slow query logs, you might want to find the most used tables and time when a particular table gets maximum hits to do some analysis. This information probably can help you decide upon  a time for you to take dumps or fire alter queries on the table.

Say for instance, you have a relatively large SQL query embedded in your application code which has probably more than tens of bind variables scattered here and there. For debugging purpose, you might want to replace those variable with your chosen values and fire them in a particular SQL execution tool which does not support dynamic bind variable replacement.

To cater to all the needs, I felt there is a need of SQL parser in R and came up with this package – RSqlParser inspired by Java’s JSqlParser. This tool will come handy for carrying out many analysis on SQL queries.

With this package, you can design your free tool to identify the reasons for your poorly performing queries or to address your various other use cases.

RSqlParser is a non-validating SQL parser. It expects syntactically correct SQL statements. It can be used to get various components of SQL statements.

Currently, it supports only SELECT statements.

library(RSqlParser)

Methods

There are currently 4 methods in the package:

get_all_bind_variables: Get the bind variables in sql.
get_all_select_cols_with_alias: Get the names of the selected columns in the sql
get_all_subqueries: Get the subqueries in sql.
get_all_tables_with_alias: Get the names of the tables with alias present in
the sql

There are many more methods waiting to be released in upcoming versions of the package. Not only that, in upcoming versions, package should be able to parse all DML and DDL statements.

Till then, if you are facing any issue using the package, please let me know.

To leave a comment for the author, please follow the link and comment on their blog: R – FordoX.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)