Skip to content

Commit 87b3013

Browse files
committed
initial commit
1 parent bec953e commit 87b3013

36 files changed

Lines changed: 3699 additions & 0 deletions

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
target/
2+
.idea
3+
.idea/modules.xml
4+
.idea/jarRepositories.xml
5+
.idea/compiler.xml
6+
.idea/libraries/
7+
*.iws
8+
*.iml
9+
*.ipr
10+
.apt_generated
11+
.classpath
12+
.factorypath
13+
.project
14+
.settings
15+
.springBeans
16+
.sts4-cache
17+
/nbproject/private/
18+
/nbbuild/
19+
/dist/
20+
/nbdist/
21+
/.nb-gradle/
22+
build/
23+
!**/src/main/**/build/
24+
!**/src/test/**/build/
25+
.vscode/
26+
.DS_Store

README.md

Whitespace-only changes.

pom.xml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>io.github.mnesimiyilmaz</groupId>
8+
<artifactId>sql4json</artifactId>
9+
<version>0.0.1</version>
10+
<packaging>jar</packaging>
11+
<description>Filter, aggregate and select data from json using SQL like query.</description>
12+
<url>https://github.com/mnesimiyilmaz/sql4json</url>
13+
14+
<licenses>
15+
<license>
16+
<name>Apache License, Version 2.0</name>
17+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
18+
<distribution>repo</distribution>
19+
</license>
20+
</licenses>
21+
22+
<developers>
23+
<developer>
24+
<name>Mucahit Nesimi YILMAZ</name>
25+
<organizationUrl>https://github.com/mnesimiyilmaz</organizationUrl>
26+
</developer>
27+
</developers>
28+
29+
<distributionManagement>
30+
<repository>
31+
<id>github</id>
32+
<name>GitHub mnesimiyilmaz Apache Maven Packages</name>
33+
<url>https://maven.pkg.github.com/mnesimiyilmaz/sql4json</url>
34+
</repository>
35+
</distributionManagement>
36+
37+
<properties>
38+
<java.version>1.8</java.version>
39+
<maven.compiler.source>${java.version}</maven.compiler.source>
40+
<maven.compiler.target>${java.version}</maven.compiler.target>
41+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
42+
43+
<!--last version that supports java 1.8 :/-->
44+
<antlr.version>4.9.3</antlr.version>
45+
<lombok.version>1.18.30</lombok.version>
46+
<jackson.version>2.15.2</jackson.version>
47+
<junit.version>5.10.0</junit.version>
48+
</properties>
49+
50+
<dependencies>
51+
<dependency>
52+
<groupId>org.projectlombok</groupId>
53+
<artifactId>lombok</artifactId>
54+
<version>${lombok.version}</version>
55+
<scope>provided</scope>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>org.antlr</groupId>
60+
<artifactId>antlr4-runtime</artifactId>
61+
<version>${antlr.version}</version>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>com.fasterxml.jackson.dataformat</groupId>
66+
<artifactId>jackson-dataformat-xml</artifactId>
67+
<version>${jackson.version}</version>
68+
</dependency>
69+
70+
<dependency>
71+
<groupId>com.fasterxml.jackson.module</groupId>
72+
<artifactId>jackson-module-parameter-names</artifactId>
73+
<version>${jackson.version}</version>
74+
</dependency>
75+
76+
<dependency>
77+
<groupId>com.fasterxml.jackson.datatype</groupId>
78+
<artifactId>jackson-datatype-jsr310</artifactId>
79+
<version>${jackson.version}</version>
80+
</dependency>
81+
82+
<dependency>
83+
<groupId>com.fasterxml.jackson.datatype</groupId>
84+
<artifactId>jackson-datatype-jdk8</artifactId>
85+
<version>${jackson.version}</version>
86+
</dependency>
87+
88+
<dependency>
89+
<groupId>org.junit.jupiter</groupId>
90+
<artifactId>junit-jupiter-engine</artifactId>
91+
<version>${junit.version}</version>
92+
<scope>test</scope>
93+
</dependency>
94+
</dependencies>
95+
96+
<build>
97+
<plugins>
98+
<plugin>
99+
<groupId>org.apache.maven.plugins</groupId>
100+
<artifactId>maven-compiler-plugin</artifactId>
101+
<version>3.11.0</version>
102+
<configuration>
103+
<encoding>${project.build.sourceEncoding}</encoding>
104+
<source>${java.version}</source>
105+
<target>${java.version}</target>
106+
<annotationProcessorPaths>
107+
<path>
108+
<groupId>org.projectlombok</groupId>
109+
<artifactId>lombok</artifactId>
110+
<version>${lombok.version}</version>
111+
</path>
112+
</annotationProcessorPaths>
113+
</configuration>
114+
</plugin>
115+
<plugin>
116+
<groupId>org.antlr</groupId>
117+
<artifactId>antlr4-maven-plugin</artifactId>
118+
<version>${antlr.version}</version>
119+
<executions>
120+
<execution>
121+
<goals>
122+
<goal>antlr4</goal>
123+
</goals>
124+
</execution>
125+
</executions>
126+
</plugin>
127+
<plugin>
128+
<artifactId>maven-assembly-plugin</artifactId>
129+
<configuration>
130+
<descriptorRefs>
131+
<descriptorRef>jar-with-dependencies</descriptorRef>
132+
</descriptorRefs>
133+
</configuration>
134+
<executions>
135+
<execution>
136+
<id>simple-command</id>
137+
<phase>package</phase>
138+
<goals>
139+
<goal>attached</goal>
140+
</goals>
141+
</execution>
142+
</executions>
143+
</plugin>
144+
<plugin>
145+
<groupId>org.apache.maven.plugins</groupId>
146+
<artifactId>maven-source-plugin</artifactId>
147+
<version>3.3.0</version>
148+
<executions>
149+
<execution>
150+
<id>attach-sources</id>
151+
<goals>
152+
<goal>jar</goal>
153+
</goals>
154+
</execution>
155+
</executions>
156+
</plugin>
157+
</plugins>
158+
</build>
159+
160+
</project>
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
grammar SQL4Json;
2+
3+
sql4json
4+
: SELECT selectedColumns FROM rootNode (WHERE whereConditions)? (GROUP BY groupByColumns)? (HAVING havingConditions)? (ORDER BY orderByColumns)? (SEMI_COLON)? EOF
5+
;
6+
7+
rootNode
8+
: ROOT (DOT IDENTIFIER (DOT IDENTIFIER)*)?
9+
;
10+
11+
jsonColumn
12+
: IDENTIFIER (DOT IDENTIFIER)*
13+
;
14+
15+
params
16+
: value (COMMA value)*
17+
;
18+
19+
jsonColumnWithNonAggFunction
20+
: jsonColumn
21+
| NON_AGG_FUNCTION LPAREN jsonColumn (COMMA params)? RPAREN
22+
;
23+
24+
jsonColumnWithAggFunction
25+
: jsonColumnWithNonAggFunction
26+
| AGG_FUNCTION LPAREN (ASTERISK | jsonColumnWithNonAggFunction) RPAREN
27+
;
28+
29+
selectColumn
30+
: jsonColumnWithAggFunction (AS jsonColumn)?
31+
;
32+
33+
selectedColumns
34+
: ASTERISK
35+
| selectColumn (COMMA selectColumn)*
36+
;
37+
38+
value
39+
: STRING | NUMBER | BOOLEAN | NULL | VALUE_FUNCTION
40+
;
41+
42+
valueWithNonAggFunction
43+
: value
44+
| NON_AGG_FUNCTION LPAREN value (COMMA params)? RPAREN
45+
;
46+
47+
comparison
48+
: jsonColumnWithNonAggFunction COMPARISON_OPERATOR valueWithNonAggFunction
49+
;
50+
51+
like
52+
: jsonColumnWithNonAggFunction LIKE STRING
53+
;
54+
55+
isNull
56+
: jsonColumnWithNonAggFunction IS NULL
57+
;
58+
59+
isNotNull
60+
: jsonColumnWithNonAggFunction IS NOT NULL
61+
;
62+
63+
condition
64+
: comparison
65+
| like
66+
| isNull
67+
| isNotNull
68+
;
69+
70+
nestedCondition
71+
: LPAREN (condition | nestedCondition) (LOGICAL_OPERATOR (condition | nestedCondition))* RPAREN
72+
;
73+
74+
conditions
75+
: (condition | nestedCondition) (LOGICAL_OPERATOR (condition | nestedCondition))*
76+
;
77+
78+
whereConditions
79+
: conditions
80+
;
81+
82+
havingConditions
83+
: conditions
84+
;
85+
86+
groupByColumn
87+
: jsonColumnWithNonAggFunction
88+
;
89+
90+
groupByColumns
91+
: groupByColumn (COMMA groupByColumn)*
92+
;
93+
94+
orderByColumn
95+
: jsonColumnWithNonAggFunction (ORDER_DIRECTION)?
96+
;
97+
98+
orderByColumns
99+
: orderByColumn (COMMA orderByColumn)*
100+
;
101+
102+
SELECT: S E L E C T ;
103+
FROM: F R O M ;
104+
WHERE: W H E R E ;
105+
AS: A S;
106+
GROUP: G R O U P;
107+
BY: B Y;
108+
ORDER: O R D E R;
109+
HAVING: H A V I N G;
110+
LIKE: L I K E;
111+
IS: I S;
112+
NOT: N O T;
113+
ROOT: DOLLAR_SIGN R;
114+
ORDER_DIRECTION: ASC | DESC;
115+
NON_AGG_FUNCTION: STRING_FUNCTION | UTILITY_FUNCTION;
116+
STRING_FUNCTION: LOWER | UPPER;
117+
UTILITY_FUNCTION: COALESCE | TO_DATE;
118+
AGG_FUNCTION: AVG | SUM | COUNT | MIN | MAX;
119+
VALUE_FUNCTION: NOW;
120+
SEMI_COLON: ';';
121+
COMMA: ',';
122+
DOT: '.';
123+
ASTERISK: '*';
124+
LPAREN : '(' ;
125+
RPAREN : ')' ;
126+
STRING : '\'' ~[']* '\'';
127+
NUMBER: [0-9.]+;
128+
BOOLEAN: TRUE | FALSE;
129+
NULL: N U L L;
130+
COMPARISON_OPERATOR: GTE | LTE | NOT_EQUAL | GT | LT | EQUAL;
131+
LOGICAL_OPERATOR: AND | OR;
132+
IDENTIFIER: [A-Za-z0-9_-]+;
133+
ESC: [ \t\r\n]+ -> skip;
134+
135+
fragment DOLLAR_SIGN: '$';
136+
fragment COALESCE: C O A L E S C E;
137+
fragment NOW: N O W LPAREN RPAREN;
138+
fragment ASC: A S C;
139+
fragment DESC: D E S C;
140+
fragment AVG: A V G;
141+
fragment SUM: S U M;
142+
fragment COUNT: C O U N T;
143+
fragment MIN: M I N;
144+
fragment MAX: M A X;
145+
fragment LOWER: L O W E R;
146+
fragment UPPER: U P P E R;
147+
fragment TO_DATE: T O UNDER_SCORE D A T E;
148+
fragment TRUE: T R U E;
149+
fragment FALSE: F A L S E;
150+
fragment GTE: '>=';
151+
fragment LTE: '<=';
152+
fragment NOT_EQUAL: '!=';
153+
fragment GT: '>';
154+
fragment LT: '<';
155+
fragment EQUAL: '=';
156+
fragment AND: A N D;
157+
fragment OR: O R;
158+
fragment UNDER_SCORE: '_';
159+
fragment A:('a'|'A');
160+
fragment B:('b'|'B');
161+
fragment C:('c'|'C');
162+
fragment D:('d'|'D');
163+
fragment E:('e'|'E');
164+
fragment F:('f'|'F');
165+
fragment G:('g'|'G');
166+
fragment H:('h'|'H');
167+
fragment I:('i'|'I');
168+
fragment J:('j'|'J');
169+
fragment K:('k'|'K');
170+
fragment L:('l'|'L');
171+
fragment M:('m'|'M');
172+
fragment N:('n'|'N');
173+
fragment O:('o'|'O');
174+
fragment P:('p'|'P');
175+
fragment Q:('q'|'Q');
176+
fragment R:('r'|'R');
177+
fragment S:('s'|'S');
178+
fragment T:('t'|'T');
179+
fragment U:('u'|'U');
180+
fragment V:('v'|'V');
181+
fragment W:('w'|'W');
182+
fragment X:('x'|'X');
183+
fragment Y:('y'|'Y');
184+
fragment Z:('z'|'Z');

0 commit comments

Comments
 (0)