Skip to content

Commit ec4c9c6

Browse files
committed
add support of a Google Spanner Interleaved table, commit timestamp options and array types
1 parent 60a7d10 commit ec4c9c6

File tree

18 files changed

+423
-164
lines changed

18 files changed

+423
-164
lines changed

pom.xml

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@
3737
<version>4.13.1</version>
3838
<scope>test</scope>
3939
</dependency>
40+
<dependency>
41+
<groupId>org.junit.jupiter</groupId>
42+
<artifactId>junit-jupiter-api</artifactId>
43+
<version>5.7.1</version>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.junit.jupiter</groupId>
48+
<artifactId>junit-jupiter-engine</artifactId>
49+
<version>5.7.1</version>
50+
<scope>test</scope>
51+
</dependency>
4052
<dependency>
4153
<groupId>org.mockito</groupId>
4254
<artifactId>mockito-core</artifactId>
@@ -182,7 +194,7 @@
182194
<groupId>org.javacc.plugin</groupId>
183195
<artifactId>javacc-maven-plugin</artifactId>
184196
<version>3.0.3</version>
185-
197+
186198
<executions>
187199
<execution>
188200
<id>javacc</id>
@@ -191,15 +203,15 @@
191203
<goal>jjtree-javacc</goal>
192204
</goals>
193205
</execution>
194-
206+
195207
<!-- execute JJTree explicitely in order to generate the *.jj file needed for JJDoc -->
196208
<execution>
197209
<id>jjtree</id>
198210
<phase>generate-sources</phase>
199211
<goals>
200212
<goal>jjtree</goal>
201213
</goals>
202-
</execution>
214+
</execution>
203215
</executions>
204216
<dependencies>
205217
<dependency>
@@ -383,7 +395,7 @@
383395
<useStandardDocletOptions>true</useStandardDocletOptions>
384396
<maxmemory>800m</maxmemory>
385397
<doclint>none</doclint>
386-
398+
387399
<!-- Doclint does not work on the Test Sources
388400
<doclint>all,-missing</doclint>
389401
<excludePackageNames>net.sf.jsqlparser.parser</excludePackageNames>
@@ -403,10 +415,10 @@
403415
<artifactId>maven-jxr-plugin</artifactId>
404416
<version>3.0.0</version>
405417
</plugin>
406-
418+
407419
<!-- Cobertura is broken with Java 1.8 and there is not fix
408420
please refer to https://github.com/cobertura/cobertura/issues/248
409-
421+
410422
<plugin>
411423
<groupId>org.codehaus.mojo</groupId>
412424
<artifactId>cobertura-maven-plugin</artifactId>
@@ -417,13 +429,13 @@
417429
</configuration>
418430
</plugin>
419431
-->
420-
432+
421433
<plugin>
422434
<groupId>org.codehaus.mojo</groupId>
423435
<artifactId>findbugs-maven-plugin</artifactId>
424436
<version>3.0.5</version>
425437
</plugin>
426-
438+
427439
<!-- Obsolete or Unused
428440
<plugin>
429441
<groupId>org.apache.maven.plugins</groupId>
@@ -433,60 +445,60 @@
433445
</configuration>
434446
</plugin>
435447
-->
436-
448+
437449
<!-- JJDoc report generating the BNF documentation -->
438450
<plugin>
439451
<groupId>org.codehaus.mojo</groupId>
440452
<artifactId>javacc-maven-plugin</artifactId>
441453
<version>2.6</version>
442454
<configuration>
443-
<!--
455+
<!--
444456
/**
445457
* A flag to specify the output format for the generated documentation. If set to <code>true</code>, JJDoc will
446458
* generate a plain text description of the BNF. Some formatting is done via tab characters, but the intention is to
447459
* leave it as plain as possible. Specifying <code>false</code> causes JJDoc to generate a hyperlinked HTML document
448460
* unless the parameter {@link #bnf} has been set to <code>true</code>. Default value is <code>false</code>.
449-
*
461+
*
450462
* @parameter expression="${text}"
451463
*/
452464
-->
453465
<text>false</text>
454-
466+
455467
<!--
456468
/**
457469
* A flag whether to generate a plain text document with the unformatted BNF. Note that setting this option to
458470
* <code>true</code> is only effective if the parameter {@link #text} is <code>false</code>. Default value is
459471
* <code>false</code>.
460-
*
472+
*
461473
* @parameter expression="${bnf}"
462474
* @since 2.6
463475
*/
464476
-->
465477
<bnf>false</bnf>
466-
478+
467479
<!--
468480
/**
469481
* This option controls the structure of the generated HTML output. If set to <code>true</code>, a single HTML
470482
* table for the entire BNF is generated. Setting it to <code>false</code> will produce one table for every
471483
* production in the grammar.
472-
*
484+
*
473485
* @parameter expression="${oneTable}" default-value=true
474486
*/
475487
-->
476488
<oneTable>false</oneTable>
477-
489+
478490
<!--
479491
/**
480492
* The hypertext reference to an optional CSS file for the generated HTML documents. If specified, this CSS file
481493
* will be included via a <code>&lt;link&gt;</code> element in the HTML documents. Otherwise, the default style will
482494
* be used.
483-
*
495+
*
484496
* @parameter expression="${cssHref}"
485497
* @since 2.5
486-
*/
498+
*/
487499
-->
488500
<!-- <cssHref></cssHref> -->
489-
501+
490502
<outputDirectory>${project.reporting.outputDirectory}</outputDirectory>
491503
</configuration>
492504
</plugin>

src/main/java/net/sf/jsqlparser/expression/ExpressionVisitorAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public void visit(NamedExpressionList namedExpressionList) {
370370

371371
@Override
372372
public void visit(MultiExpressionList multiExprList) {
373-
for (ExpressionList list : multiExprList.getExprList()) {
373+
for (ExpressionList list : multiExprList.getExpressionLists()) {
374374
visit(list);
375375
}
376376
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2021 JSQLParser
6+
* %%
7+
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
8+
* #L%
9+
*/
10+
package net.sf.jsqlparser.expression;
11+
12+
import net.sf.jsqlparser.schema.Table;
13+
14+
import java.util.Collections;
15+
import java.util.List;
16+
17+
public class SpannerInterleaveIn {
18+
19+
public enum OnDelete {
20+
CASCADE,
21+
NO_ACTION
22+
}
23+
24+
private Table table;
25+
private OnDelete onDelete;
26+
27+
public SpannerInterleaveIn() {
28+
29+
}
30+
31+
public SpannerInterleaveIn(Table table, OnDelete action) {
32+
setTable(table);
33+
setOnDelete(action);
34+
}
35+
36+
public SpannerInterleaveIn(List<String> nameParts) {
37+
this(new Table(nameParts), null);
38+
}
39+
40+
public SpannerInterleaveIn(String tableName) {
41+
this(Collections.singletonList(tableName));
42+
}
43+
44+
public Table getTable() {
45+
return table;
46+
}
47+
48+
public void setTable(Table table) {
49+
this.table = table;
50+
}
51+
52+
public OnDelete getOnDelete() {
53+
return onDelete;
54+
}
55+
56+
public void setOnDelete(OnDelete action) {
57+
this.onDelete = action;
58+
}
59+
60+
@Override
61+
public String toString() {
62+
return "INTERLEAVE IN PARENT " + getTable().getName() +
63+
(getOnDelete() == null ? "" : " ON DELETE " + (getOnDelete() == OnDelete.CASCADE ? "CASCADE" : "NO ACTION"));
64+
}
65+
66+
public SpannerInterleaveIn withTable(Table table) {
67+
this.setTable(table);
68+
return this;
69+
}
70+
71+
public SpannerInterleaveIn withOnDelete(OnDelete action) {
72+
this.setOnDelete(action);
73+
return this;
74+
}
75+
}

src/main/java/net/sf/jsqlparser/expression/operators/relational/ItemsListVisitorAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void visit(ExpressionList expressionList) {
3131

3232
@Override
3333
public void visit(MultiExpressionList multiExprList) {
34-
for (ExpressionList list : multiExprList.getExprList()) {
34+
for (ExpressionList list : multiExprList.getExpressionLists()) {
3535
visit(list);
3636
}
3737
}

src/main/java/net/sf/jsqlparser/statement/create/table/CreateTable.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.List;
1616
import java.util.Optional;
1717

18+
import net.sf.jsqlparser.expression.SpannerInterleaveIn;
1819
import net.sf.jsqlparser.schema.Table;
1920
import net.sf.jsqlparser.statement.Statement;
2021
import net.sf.jsqlparser.statement.StatementVisitor;
@@ -35,6 +36,7 @@ public class CreateTable implements Statement {
3536
private boolean selectParenthesis;
3637
private boolean ifNotExists = false;
3738
private RowMovement rowMovement;
39+
private SpannerInterleaveIn interleaveIn = null;
3840

3941
@Override
4042
public void accept(StatementVisitor statementVisitor) {
@@ -175,18 +177,21 @@ public String toString() {
175177
sql += ")";
176178
}
177179
String options = PlainSelect.getStringList(tableOptionsStrings, false, false);
178-
if (options != null && options.length() > 0) {
180+
if (!options.isEmpty()) {
179181
sql += " " + options;
180182
}
181183

182184
if (rowMovement != null) {
183185
sql += " " + rowMovement.getMode().toString() + " ROW MOVEMENT";
184186
}
185187
if (select != null) {
186-
sql += " AS " + (selectParenthesis ? "(" : "") + select.toString() + (selectParenthesis ? ")" : "");
188+
sql += " AS " + (selectParenthesis ? "(" : "") + select + (selectParenthesis ? ")" : "");
187189
}
188190
if (likeTable != null) {
189-
sql += " LIKE " + (selectParenthesis ? "(" : "") + likeTable.toString() + (selectParenthesis ? ")" : "");
191+
sql += " LIKE " + (selectParenthesis ? "(" : "") + likeTable + (selectParenthesis ? ")" : "");
192+
}
193+
if (interleaveIn != null) {
194+
sql += ", " + interleaveIn;
190195
}
191196
return sql;
192197
}
@@ -288,4 +293,17 @@ public CreateTable addIndexes(Collection<? extends Index> indexes) {
288293
collection.addAll(indexes);
289294
return this.withIndexes(collection);
290295
}
296+
297+
public SpannerInterleaveIn getSpannerInterleaveIn() {
298+
return interleaveIn;
299+
}
300+
301+
public void setSpannerInterleaveIn(SpannerInterleaveIn spannerInterleaveIn) {
302+
this.interleaveIn = spannerInterleaveIn;
303+
}
304+
305+
public CreateTable withSpannerInterleaveIn(SpannerInterleaveIn spannerInterleaveIn) {
306+
this.interleaveIn = spannerInterleaveIn;
307+
return this;
308+
}
291309
}

src/main/java/net/sf/jsqlparser/statement/select/ValuesList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public String toString() {
8888
StringBuilder b = new StringBuilder();
8989

9090
b.append("(VALUES ");
91-
for (Iterator<ExpressionList> it = getMultiExpressionList().getExprList().iterator(); it.
91+
for (Iterator<ExpressionList> it = getMultiExpressionList().getExpressionLists().iterator(); it.
9292
hasNext();) {
9393
b.append(PlainSelect.getStringList(it.next().getExpressions(), true, !isNoBrackets()));
9494
if (it.hasNext()) {

src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ public void visit(LateralSubSelect lateralSubSelect) {
491491

492492
@Override
493493
public void visit(MultiExpressionList multiExprList) {
494-
for (ExpressionList exprList : multiExprList.getExprList()) {
494+
for (ExpressionList exprList : multiExprList.getExpressionLists()) {
495495
exprList.accept(this);
496496
}
497497
}

src/main/java/net/sf/jsqlparser/util/deparser/CreateIndexDeParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void deParse(CreateIndex createIndex) {
4444

4545
if (index.getColumnsNames() != null) {
4646
buffer.append(" (");
47-
buffer.append(index.getColumnWithParams().stream()
47+
buffer.append(index.getColumns().stream()
4848
.map(cp -> cp.columnName + (cp.getParams() != null ? " " + String.join(" ", cp.getParams()) : ""))
4949
.collect(joining(", ")));
5050
buffer.append(")");

src/main/java/net/sf/jsqlparser/util/deparser/CreateTableDeParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ public void deParse(CreateTable createTable) {
117117
buffer.append(")");
118118
}
119119
}
120+
if (createTable.getSpannerInterleaveIn() != null) {
121+
buffer.append(", ").append(createTable.getSpannerInterleaveIn());
122+
}
120123
}
121124

122125
}

src/main/java/net/sf/jsqlparser/util/deparser/DeclareStatementDeParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public void deParse(DeclareStatement declare) {
3131
declare.getUserVariable().accept(expressionVisitor);
3232
}
3333

34-
if (declare.getType() == DeclareType.AS) {
34+
if (declare.getDeclareType() == DeclareType.AS) {
3535
buffer.append(" AS ");
3636
buffer.append(declare.getTypeName());
3737
return;
3838
}
3939

40-
if (declare.getType() == DeclareType.TABLE) {
40+
if (declare.getDeclareType() == DeclareType.TABLE) {
4141
buffer.append(" TABLE (");
4242
for (int i = 0; i < declare.getColumnDefinitions().size(); i++) {
4343
if (i > 0) {

src/main/java/net/sf/jsqlparser/util/deparser/ExpressionDeParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ public void visit(ExtractExpression eexpr) {
719719

720720
@Override
721721
public void visit(MultiExpressionList multiExprList) {
722-
for (Iterator<ExpressionList> it = multiExprList.getExprList().iterator(); it.hasNext();) {
722+
for (Iterator<ExpressionList> it = multiExprList.getExpressionLists().iterator(); it.hasNext();) {
723723
it.next().accept(this);
724724
if (it.hasNext()) {
725725
buffer.append(", ");

src/main/java/net/sf/jsqlparser/util/deparser/InsertDeParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public void visit(NamedExpressionList NamedExpressionList) {
164164
@Override
165165
public void visit(MultiExpressionList multiExprList) {
166166
buffer.append(" VALUES ");
167-
for (Iterator<ExpressionList> it = multiExprList.getExprList().iterator(); it.hasNext();) {
167+
for (Iterator<ExpressionList> it = multiExprList.getExpressionLists().iterator(); it.hasNext();) {
168168
buffer.append("(");
169169
for (Iterator<Expression> iter = it.next().getExpressions().iterator(); iter.hasNext();) {
170170
Expression expression = iter.next();

src/main/java/net/sf/jsqlparser/util/deparser/ReplaceDeParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void setSelectVisitor(SelectVisitor visitor) {
123123
@Override
124124
public void visit(MultiExpressionList multiExprList) {
125125
buffer.append("VALUES ");
126-
for (Iterator<ExpressionList> it = multiExprList.getExprList().iterator(); it.hasNext();) {
126+
for (Iterator<ExpressionList> it = multiExprList.getExpressionLists().iterator(); it.hasNext();) {
127127
buffer.append("(");
128128
for (Iterator<Expression> iter = it.next().getExpressions().iterator(); iter.hasNext();) {
129129
Expression expression = iter.next();

src/main/java/net/sf/jsqlparser/util/deparser/UpsertDeParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void visit(NamedExpressionList namedExpressionList) {
123123
@Override
124124
public void visit(MultiExpressionList multiExprList) {
125125
buffer.append(" VALUES ");
126-
for (Iterator<ExpressionList> it = multiExprList.getExprList().iterator(); it.hasNext();) {
126+
for (Iterator<ExpressionList> it = multiExprList.getExpressionLists().iterator(); it.hasNext();) {
127127
buffer.append("(");
128128
for (Iterator<Expression> iter = it.next().getExpressions().iterator(); iter.hasNext();) {
129129
Expression expression = iter.next();

0 commit comments

Comments
 (0)