SQL Parsers for BigData, built with antlr4
npm install bq-dt-sql-parserSparkSqlParser.ts to include support for recursive queries, allowing better parsing and analysis of complex queries in Spark.
bash
use npm
npm i dt-sql-parser --save
use yarn
yarn add dt-sql-parser
`
Usage
We recommend learning the fundamentals before continuing. The dt-sql-parser library provides SQL classes for different types of SQL.
`javascript
import { MySQL, FlinkSQL, SparkSQL, HiveSQL, PostgreSQL, TrinoSQL, ImpalaSQL } from 'dt-sql-parser';
`
Before using syntax validation, code completion, and other features, it is necessary to instantiate the parser for the relevant SQL type. For instance, one can consider using MySQL as an example:
`javascript
const mysql = new MySQL();
`
The following usage examples will utilize MySQL, but the parser for other SQL types works similarly.
$3
`javascript
import { MySQL } from 'dt-sql-parser';
const mysql = new MySQL();
const incorrectSql = 'selec id,name from user1;';
const errors = mysql.validate(incorrectSql);
console.log(errors);
`
$3
Now, dt-sql-parser supports Recursive Queries in SparkSQL, allowing better handling of queries using WITH RECURSIVE.
`javascript
import { SparkSQL } from 'dt-sql-parser';
const spark = new SparkSQL();
const recursiveQuery =
;
const errors = spark.validate(recursiveQuery);
console.log(errors.length === 0 ? "Valid SQL" : errors);
``