Skip to content

Commit 8d8d074

Browse files
committed
feat: add support for non-parent interleaving
Includes fix from #217
1 parent d97c555 commit 8d8d074

3 files changed

Lines changed: 20 additions & 11 deletions

File tree

src/main/java/com/google/cloud/solutions/spannerddl/parser/ASTtable_interleave_clause.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ public ASTtable_interleave_clause(DdlParser p, int id) {
3030
}
3131

3232
public String getParentTableName() {
33-
return AstTreeUtils.tokensToString(
34-
AstTreeUtils.getChildByType(children, ASTinterleave_in.class));
33+
return (AstTreeUtils.getOptionalChildByType(children, ASTparent.class) == null ? "" : "PARENT ")
34+
+ AstTreeUtils.tokensToString(
35+
AstTreeUtils.getChildByType(children, ASTinterleave_in.class));
3536
}
3637

3738
public String getOnDelete() {
@@ -46,14 +47,6 @@ public String getOnDelete() {
4647

4748
@Override
4849
public String toString() {
49-
return Joiner.on(" ")
50-
.skipNulls()
51-
.join(
52-
"INTERLEAVE IN",
53-
AstTreeUtils.getOptionalChildByType(children, ASTparent.class) == null
54-
? null
55-
: "PARENT",
56-
getParentTableName(),
57-
getOnDelete());
50+
return Joiner.on(" ").skipNulls().join("INTERLEAVE IN", getParentTableName(), getOnDelete());
5851
}
5952
}

src/test/java/com/google/cloud/solutions/spannerddl/diff/DdlDiffTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,15 @@ public void generateAlterTable_changeInterleaving() throws DdlDiffException {
319319
true,
320320
"Cannot change interleaved parent of table test1");
321321

322+
// add parent constraint
323+
getDiffCheckDdlDiffException(
324+
"create table test1 (col1 int64, col2 int64) "
325+
+ "primary key (col1), interleave in testparent;",
326+
"create table test1 (col1 int64, col2 int64) "
327+
+ "primary key (col1), interleave in parent testparent",
328+
true,
329+
"Cannot change interleaved parent of table test1");
330+
322331
// change on delete
323332
assertThat(
324333
getDiff(

src/test/resources/ddlParserValidation.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,11 @@ CREATE TABLE test1 (
196196
value INT64
197197
) PRIMARY KEY (keycol ASC), OPTIONS (key='value')
198198

199+
== Test 20 create table, interleave in non-parent
200+
201+
CREATE TABLE test1 (
202+
keycol INT64,
203+
value INT64
204+
) PRIMARY KEY (keycol ASC), INTERLEAVE IN other_table ON DELETE NO ACTION
205+
199206
==

0 commit comments

Comments
 (0)