Skip to content

build: Add better SQL Test Infrastructure #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: SQL Parser Error
about: Create a report to help us improve
title: 'Parser Version : RDBMS : Failing feature description'
labels: 'Parser Error', 'Feature Request', 'Documentation', 'Java API', 'RDBMS support'
assignees: ''

---

**Failing SQL Feature**
- Brief description of the failing SQL feature
- Example: `WITH ROLLUP` can't be parsed

**SQL Example**
- Simplified Query Example, focusing on the failing feature
```sql
-- Replace with your ACTUAL example
select 1
from dual
```

**Software Information**
- Parser version
- Database (e.g. Oracle, MS SQL Server, H2, PostgreSQL, IBM DB2 )

**Tips**
Please write in English and avoid Screenshots (as we can't copy and paste content from it).
30 changes: 30 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
java: [8, 11]
name: Java ${{ matrix.java }} building ...

steps:
- uses: actions/checkout@v3
- name: Set up Java ${{ matrix.java }}
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml
31 changes: 31 additions & 0 deletions .github/workflows/sphinx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Sphinx Pages
on: [push, workflow_dispatch]
permissions: write-all
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v4
- name: Install XSLT Processor
run: sudo apt-get install xsltproc sphinx-common
- name: Install dependencies
run: pip install sphinx_rtd_theme sphinx-book-theme myst_parser sphinx-prompt sphinx_substitution_extensions sphinx_issues sphinx_tabs pygments
- name: Checkout project sources
uses: actions/checkout@v2
with:
ref: main
fetch-depth: 0
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Run build with Gradle Wrapper
run: gradle sphinx
- name: Deploy
uses: actions/configure-pages@v2
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
# Upload entire repository
path: 'build/site/sphinx'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.ipr
*.iws
target/
build/
/var
/*/var/
/presto-product-tests/**/var/
Expand All @@ -25,3 +26,8 @@ benchmark_outputs
.mvn/timing.properties
.editorconfig
node_modules
nb-configuration.xml
gradle/
.gradle/
gradlew
gradlew.bat
54 changes: 52 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
# SQL Language Frontend
# Java SQL:2016 Language Frontend

A Modern SQL frontend based on SQL16 with extensions for streaming, graph, rich types, etc, including parser, resolver, rewriters, etc.
[Visit our Website.](https://manticore-projects.github.io/sql/index.html)

![Build Status](https://github.com/manticore-projects/sql/actions/workflows/maven.yml/badge.svg)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.facebook.presto/presto-coresql/badge.svg)](http://maven-badges.herokuapp.com/maven-central/com.facebook.presto/presto-coresql)
[![Javadocs](https://www.javadoc.io/badge/com.facebook.presto/presto-coresql.svg)](https://www.javadoc.io/doc/com.facebook.presto/presto-coresql)

A Modern SQL frontend based on the SQL16 Standard with extensions for streaming, graph, rich types.

* Comprehensive support for statements:

- QUERY: ``SELECT ...``
- DML: ``INSERT ... INTO ...`` ``UPDATE ...`` ``MERGE ... INTO ...`` ``DELETE ... FROM ...``
- DDL: ``CREATE ...`` ``ALTER ...`` ``DROP ...``

* Nested Expressions (e.g. Sub-Selects)
* ``WITH`` clauses
* De-Parser for a Statement AST Node, which writes a SQL from Java Objects
* Rewriter
* Linter

## How to use it

1) Maven Repository

```xml
<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-coresql</artifactId>
<version>0.1</version>
</dependency>
```

2) Parsing and Unparsing a SQL Statement

```java
import com.facebook.coresql.parser.AstNode;
import com.facebook.coresql.parser.ParserHelper;
import com.facebook.coresql.parser.Unparser;

String sqlStr = "select 1 from dual where a=b";
AstNode ast = ParserHelper.parseStatement(sqlStr);
String unparsedSqlStr = Unparser.unparse(ast);
```

3) Compile latest version from source

```shell
git clone https://github.com/kaikalur/sql.git
cd sql
mvn install
```
214 changes: 214 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
import se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask
import java.nio.charset.Charset

plugins {
id 'java'
id "ca.coglinc2.javacc" version "latest.release"
id "com.github.spotbugs" version "latest.release"
id 'checkstyle'

// download the RR tools which have no Maven Repository
id "de.undercouch.download" version "latest.release"

id "se.bjurr.gitchangelog.git-changelog-gradle-plugin" version "latest.release"
}

allprojects {
repositories {
mavenLocal()
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
}

def getVersion = { boolean considerSnapshot ->
def major = 0
def minor = 0
def patch = 0
def commit = ""
def snapshot =""
new ByteArrayOutputStream().withStream { os ->
exec {
workingDir "$projectDir"
args = [
"--no-pager"
, "describe"
, "--tags"
, "--always"
, "--dirty=-SNAPSHOT"
]
executable "git"
standardOutput = os
}
def matcher = os.toString() =~ /(\d*)\.(\d*)-(\d*)-([a-zA-Z\d]*)/
matcher.find()

major = matcher[0][1]
minor = matcher[0][2]
patch = matcher[0][3]
commit = matcher[0][4]

if (considerSnapshot && os.toString().trim().endsWith("-SNAPSHOT")) {
minor++
snapshot = "-SNAPSHOT"
}
}
return "${major}.${minor}${snapshot}"
}
group = 'com.facebook.presto'
version = getVersion(true)
description = 'Java SQL:2016 compliant Parser Suite'

java {
withSourcesJar()
withJavadocJar()
}

test {
useJUnitPlatform()
// set heap size for the test JVM(s)
minHeapSize = "128m"
maxHeapSize = "1G"
jvmArgs << [
'-Djunit.jupiter.execution.parallel.enabled=true',
'-Djunit.jupiter.execution.parallel.config.strategy=dynamic',
'-Djunit.jupiter.execution.parallel.mode.default=concurrent'
]

finalizedBy check
}

checkstyle {
sourceSets = [sourceSets.main, sourceSets.test]
}

task renderRR() {
dependsOn ':presto-coresql-parser:compileJavacc'
doLast {
// these WAR files have been provided as a courtesy by Gunther Rademacher
// and belong to the RR - Railroad Diagram Generator Project
// https://github.com/GuntherRademacher/rr
//
// Hosting at manticore-projects.com is temporary until a better solution is found
// Please do not use these files without Gunther's permission
download.run {
src 'http://manticore-projects.com/download/convert.war'
dest "$buildDir/rr/convert.war"
overwrite false
}

download.run {
src 'http://manticore-projects.com/download/rr.war'
dest "$buildDir/rr/rr.war"
overwrite false
}

javaexec {
standardOutput = new FileOutputStream("$buildDir/rr/syntax.ebnf")
main = "-jar"
args = [
"$buildDir/rr/convert.war",
"${project(':presto-coresql-parser').buildDir}/generated/jjtree/com/facebook/coresql/parser/parser.jj"
]
}

javaexec {
main = "-jar"
args = [
"$buildDir/rr/rr.war",
"-noepsilon",
"-color:#4D88FF",
"-offset:0",
"-width:800",
//"-png",
//"-out:target/rr/PRESTO_SQL_PARSERCC.zip",
"-out:$buildDir/rr/syntax.xhtml",
"$buildDir/rr/syntax.ebnf"
]
}

//@todo: a Java based solution may be more appropriate here
exec {
commandLine "sh", "-c", "xsltproc sphinx/xhtml2rst.xsl $buildDir/rr/syntax.xhtml > sphinx/src/syntax.rst"
}
}
}

task gitChangelogTask(type: GitChangelogTask) {
fromRepo = file("$projectDir")
file = new File("${projectDir}/sphinx/src/changelog.rst")
//fromRef = "4.0"
//toRef = "1.1";
templateContent ="""
************************
Changelog
************************


{{#tags}}
{{#ifMatches name "^Unreleased.*"}}
Latest Changes since |PRESTO_SQL_PARSER_VERSION|
{{/ifMatches}}
{{#ifMatches name "^(?!Unreleased).*"}}
Version {{name}}
{{/ifMatches}}
=============================================================

{{#issues}}

{{#commits}}
{{#ifMatches messageTitle "^(?!Merge).*"}}
* **{{{messageTitle}}}**

{{authorName}}, {{commitDate}}
{{/ifMatches}}
{{/commits}}

{{/issues}}
{{/tags}}
"""
}

task sphinx(type: Exec) {
dependsOn(gitChangelogTask, renderRR)

String PROLOG = """
.. |_| unicode:: U+00A0
:trim:

.. |PRESTO_SQL_PARSER_EMAIL| replace:: [email protected]
.. |PRESTO_SQL_PARSER_VERSION| replace:: ${getVersion(false)}
.. |PRESTO_SQL_PARSER_SNAPSHOT_VERSION| replace:: ${getVersion(true)}
.. |PRESTO_SQL_PARSER_STABLE_VERSION_LINK| raw:: html

<a href='https://github.com/prestodb/sql/archive/refs/tags/${getVersion(false)}.jar'>${project.name}-${getVersion(false)}.jar</a>

.. |PRESTO_SQL_PARSER_SNAPSHOT_VERSION_LINK| raw:: html

<a href='https://github.com/prestodb/sql/archive/refs/tags/${getVersion(true)}.jar'>${project.name}-${getVersion(true)}.jar</a>

"""

args = [
"-Dproject=Presto SQL Parser"
, "-Dcopyright=Sreeni Viswanadha, 2022"
, "-Dauthor=Sreeni Viswanadha"
, "-Drelease=${getVersion(false)}"
, "-Drst_prolog=$PROLOG"
, "sphinx/src"
, "$buildDir/site/sphinx"
]

executable "sphinx-build"

//store the output instead of printing to the console:
standardOutput = new ByteArrayOutputStream()

//extension method stopTomcat.output() can be used to obtain the output:
ext.output = {
return standardOutput.toString()
}
}

Loading