fix: remove trailing semicolons in DDL by olavloite · Pull Request #3879 · googleapis/java-spanner · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

fix: remove trailing semicolons in DDL #3879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/**
* Convenience class for executing Data Definition Language statements on transactions that support
Expand Down Expand Up @@ -137,7 +138,21 @@ OperationFuture<Void, UpdateDatabaseDdlMetadata> executeDdl(
dbBuilder.setProtoDescriptors(protoDescriptors);
}
Database db = dbBuilder.build();
return dbAdminClient.updateDatabaseDdl(db, statements, null);
return dbAdminClient.updateDatabaseDdl(
db,
statements.stream().map(DdlClient::stripTrailingSemicolon).collect(Collectors.toList()),
null);
}

static String stripTrailingSemicolon(String input) {
if (!input.contains(";")) {
return input;
}
String trimmed = input.trim();
if (trimmed.endsWith(";")) {
return trimmed.substring(0, trimmed.length() - 1);
}
return input;
}

/** Returns true if the statement is a `CREATE DATABASE ...` statement. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,47 @@ public void testSetsDefaultSequenceKindAndRetriesBatch() {
"create table bar (id2 int64 auto_increment primary key",
((UpdateDatabaseDdlRequest) requests.get(0)).getStatements(1));
}

@Test
public void testStripTrailingSemicolon() {
addUpdateDdlResponse();
addUpdateDdlResponse();
addUpdateDdlResponse();
addUpdateDdlResponse();
try (Connection connection = createConnection()) {
connection.execute(Statement.of("drop table foo;"));
connection.execute(Statement.of("drop table foo \n\t;\n\t "));
connection.execute(Statement.of("drop table foo"));

connection.startBatchDdl();
connection.execute(Statement.of("create table foo (id1 int64 auto_increment primary key;"));
connection.execute(
Statement.of("create table foo (id1 int64 auto_increment primary key \n\t;\n\t "));
connection.execute(Statement.of("create table foo (id2 int64 auto_increment primary key"));
connection.runBatch();
}
assertEquals(4, mockDatabaseAdmin.getRequests().size());
assertEquals(
"drop table foo",
((UpdateDatabaseDdlRequest) mockDatabaseAdmin.getRequests().get(0)).getStatements(0));
assertEquals(
"drop table foo \n\t",
((UpdateDatabaseDdlRequest) mockDatabaseAdmin.getRequests().get(1)).getStatements(0));
assertEquals(
"drop table foo",
((UpdateDatabaseDdlRequest) mockDatabaseAdmin.getRequests().get(2)).getStatements(0));

assertEquals(
3,
((UpdateDatabaseDdlRequest) mockDatabaseAdmin.getRequests().get(3)).getStatementsCount());
assertEquals(
"create table foo (id1 int64 auto_increment primary key",
((UpdateDatabaseDdlRequest) mockDatabaseAdmin.getRequests().get(3)).getStatements(0));
assertEquals(
"create table foo (id1 int64 auto_increment primary key \n\t",
((UpdateDatabaseDdlRequest) mockDatabaseAdmin.getRequests().get(3)).getStatements(1));
assertEquals(
"create table foo (id2 int64 auto_increment primary key",
((UpdateDatabaseDdlRequest) mockDatabaseAdmin.getRequests().get(3)).getStatements(2));
}
}
Loading

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.