Skip to content

chore: make statement parsing public (marked as InternalApi) #1690

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
Feb 16, 2022
Merged
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 @@ -130,7 +130,8 @@ public static AbstractStatementParser getInstance(Dialect dialect) {
.parse(Statement.of("RUN BATCH"));

/** The type of statement that has been recognized by the parser. */
enum StatementType {
@InternalApi
public enum StatementType {
CLIENT_SIDE,
DDL,
QUERY,
Expand All @@ -139,7 +140,8 @@ enum StatementType {
}

/** A statement that has been parsed */
static class ParsedStatement {
@InternalApi
public static class ParsedStatement {
private final StatementType type;
private final ClientSideStatementImpl clientSideStatement;
private final Statement statement;
Expand Down Expand Up @@ -217,11 +219,18 @@ public boolean equals(Object other) {
&& Objects.equals(this.sqlWithoutComments, o.sqlWithoutComments);
}

StatementType getType() {
/** Returns the type of statement that was recognized by the parser. */
@InternalApi
public StatementType getType() {
return type;
}

boolean isQuery() {
/**
* Returns true if the statement is a query that will return a {@link
* com.google.cloud.spanner.ResultSet}.
*/
@InternalApi
public boolean isQuery() {
switch (type) {
case CLIENT_SIDE:
return getClientSideStatement().isQuery();
Expand All @@ -235,7 +244,12 @@ boolean isQuery() {
return false;
}

boolean isUpdate() {
/**
* Returns true if the statement is a DML statement or a client side statement that will return
* an update count.
*/
@InternalApi
public boolean isUpdate() {
switch (type) {
case CLIENT_SIDE:
return getClientSideStatement().isUpdate();
Expand All @@ -249,7 +263,9 @@ boolean isUpdate() {
return false;
}

boolean isDdl() {
/** Returns true if the statement is a DDL statement. */
@InternalApi
public boolean isDdl() {
switch (type) {
case DDL:
return true;
Expand Down Expand Up @@ -286,7 +302,9 @@ Statement mergeQueryOptions(Statement statement, QueryOptions defaultQueryOption
.build();
}

String getSqlWithoutComments() {
/** Returns the SQL statement with all comments removed from the SQL string. */
@InternalApi
public String getSqlWithoutComments() {
return sqlWithoutComments;
}

Expand Down Expand Up @@ -321,7 +339,8 @@ ClientSideStatement getClientSideStatement() {
* @param statement The statement to parse.
* @return the parsed and categorized statement.
*/
ParsedStatement parse(Statement statement) {
@InternalApi
public ParsedStatement parse(Statement statement) {
return parse(statement, null);
}

Expand Down