Skip to content

Commit

Permalink
Migrate assertStatement in TestSqlParser.testRenameColumn
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Apr 3, 2023
1 parent ba23913 commit 54953dc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,9 @@ public class RenameColumn
private final boolean tableExists;
private final boolean columnExists;

public RenameColumn(QualifiedName table, Identifier source, Identifier target, boolean tableExists, boolean columnExists)
{
this(Optional.empty(), table, source, target, tableExists, columnExists);
}

public RenameColumn(NodeLocation location, QualifiedName table, Identifier source, Identifier target, boolean tableExists, boolean columnExists)
{
this(Optional.of(location), table, source, target, tableExists, columnExists);
}

private RenameColumn(Optional<NodeLocation> location, QualifiedName table, Identifier source, Identifier target, boolean tableExists, boolean columnExists)
{
super(location);
super(Optional.of(location));
this.table = requireNonNull(table, "table is null");
this.source = requireNonNull(source, "source is null");
this.target = requireNonNull(target, "target is null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2076,10 +2076,49 @@ public void testCommentColumn()
@Test
public void testRenameColumn()
{
assertStatement("ALTER TABLE foo.t RENAME COLUMN a TO b", new RenameColumn(QualifiedName.of("foo", "t"), identifier("a"), identifier("b"), false, false));
assertStatement("ALTER TABLE IF EXISTS foo.t RENAME COLUMN a TO b", new RenameColumn(QualifiedName.of("foo", "t"), identifier("a"), identifier("b"), true, false));
assertStatement("ALTER TABLE foo.t RENAME COLUMN IF EXISTS a TO b", new RenameColumn(QualifiedName.of("foo", "t"), identifier("a"), identifier("b"), false, true));
assertStatement("ALTER TABLE IF EXISTS foo.t RENAME COLUMN IF EXISTS a TO b", new RenameColumn(QualifiedName.of("foo", "t"), identifier("a"), identifier("b"), true, true));
assertThat(statement("ALTER TABLE foo.t RENAME COLUMN a TO b"))
.isEqualTo(new RenameColumn(
location(1, 1),
QualifiedName.of(ImmutableList.of(
new Identifier(location(1, 13), "foo", false),
new Identifier(location(1, 17), "t", false))),
new Identifier(location(1, 33), "a", false),
new Identifier(location(1, 38), "b", false),
false,
false));

assertThat(statement("ALTER TABLE IF EXISTS foo.t RENAME COLUMN a TO b"))
.isEqualTo(new RenameColumn(
location(1, 1),
QualifiedName.of(ImmutableList.of(
new Identifier(location(1, 23), "foo", false),
new Identifier(location(1, 27), "t", false))),
new Identifier(location(1, 43), "a", false),
new Identifier(location(1, 48), "b", false),
true,
false));

assertThat(statement("ALTER TABLE foo.t RENAME COLUMN IF EXISTS a TO b"))
.isEqualTo(new RenameColumn(
location(1, 1),
QualifiedName.of(ImmutableList.of(
new Identifier(location(1, 13), "foo", false),
new Identifier(location(1, 17), "t", false))),
new Identifier(location(1, 43), "a", false),
new Identifier(location(1, 48), "b", false),
false,
true));

assertThat(statement("ALTER TABLE IF EXISTS foo.t RENAME COLUMN IF EXISTS a TO b"))
.isEqualTo(new RenameColumn(
location(1, 1),
QualifiedName.of(ImmutableList.of(
new Identifier(location(1, 23), "foo", false),
new Identifier(location(1, 27), "t", false))),
new Identifier(location(1, 53), "a", false),
new Identifier(location(1, 58), "b", false),
true,
true));
}

@Test
Expand Down

0 comments on commit 54953dc

Please sign in to comment.