Path: blob/master/tutorials-and-examples/feature-tutorials/SqlToKql.ipynb
3253 views
SQL TO KQL Conversion (Experimental)
The sql_to_kql module is a simple converter to KQL based on moz_sql_parser. It is an experimental feature built to help us convert a few queries but we thought that it was useful enough to include in MSTICPy.
You must have msticpy installed along with the moz_sql_parser package to run this notebook:
It supports a subset of ANSI SQL-92 which includes the following:
SELECT (including column renaming and functions)
FROM (including from subquery)
WHERE (common string and int operations, LIKE, some common functions)
LIMIT
UNION, UNION ALL
JOIN - only tested for relatively simple join expressions
GROUP BY
SQL Comments (ignored)
It does not support HAVING, multiple SQL statements or anything complex like Common Table Expressions.
It does support a few additional Spark SQL extensions like RLIKE.
Caveat Emptor!
This module is included in MSTICPy in the hope that it might be useful to others. We do not intend to expand its capabilities.
It is also not guaranteed to produce perfectly-executing KQL - there will likely be things that you have to fix up in the output query. You will, for example, nearly always need change the names of the fields used since the source data tables are unlikely to exactly match the schema of your Kusto/Microsoft Sentinel target.
The module does include an elementary table name mapping function that we demonstrate below.