From 54953dc3ab99efd69d678116f011028f7a995e99 Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Tue, 28 Mar 2023 16:59:52 +0900 Subject: [PATCH] Migrate assertStatement in TestSqlParser.testRenameColumn --- .../java/io/trino/sql/tree/RenameColumn.java | 12 +---- .../io/trino/sql/parser/TestSqlParser.java | 47 +++++++++++++++++-- 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/core/trino-parser/src/main/java/io/trino/sql/tree/RenameColumn.java b/core/trino-parser/src/main/java/io/trino/sql/tree/RenameColumn.java index 02f2baf3dfbb..2edbc4fdac78 100644 --- a/core/trino-parser/src/main/java/io/trino/sql/tree/RenameColumn.java +++ b/core/trino-parser/src/main/java/io/trino/sql/tree/RenameColumn.java @@ -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 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"); diff --git a/core/trino-parser/src/test/java/io/trino/sql/parser/TestSqlParser.java b/core/trino-parser/src/test/java/io/trino/sql/parser/TestSqlParser.java index 9cee3bf11232..0a1224fa5b59 100644 --- a/core/trino-parser/src/test/java/io/trino/sql/parser/TestSqlParser.java +++ b/core/trino-parser/src/test/java/io/trino/sql/parser/TestSqlParser.java @@ -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