From ed9256059230080c6ac1b541fffeb16ad96b3edd Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Thu, 21 Nov 2024 16:46:55 +0800 Subject: [PATCH] Remove IdentifierValue.getQuotedContent() (#33757) --- .../core/value/identifier/IdentifierValue.java | 11 ----------- .../core/value/identifier/IdentifierValueTest.java | 12 ------------ .../query/simple/OpenGaussComQueryExecutor.java | 4 ++-- .../postgresql/command/query/extended/Portal.java | 4 ++-- .../query/simple/PostgreSQLComQueryExecutor.java | 4 ++-- 5 files changed, 6 insertions(+), 29 deletions(-) diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/value/identifier/IdentifierValue.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/value/identifier/IdentifierValue.java index beed7c43aa8bc..1fc968a366b92 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/value/identifier/IdentifierValue.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/value/identifier/IdentifierValue.java @@ -17,7 +17,6 @@ package org.apache.shardingsphere.sql.parser.statement.core.value.identifier; -import com.google.common.base.Strings; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -55,14 +54,4 @@ public IdentifierValue(final String text, final String reservedCharacters) { public String getValueWithQuoteCharacters() { return null == value ? "" : quoteCharacter.wrap(value); } - - /** - * Get quoted content. - * - * @param text text - * @return quote content - */ - public static String getQuotedContent(final String text) { - return Strings.isNullOrEmpty(text) ? text : QuoteCharacter.unwrapAndTrimText(text); - } } diff --git a/parser/sql/statement/core/src/test/java/org/apache/shardingsphere/sql/parser/statement/core/value/identifier/IdentifierValueTest.java b/parser/sql/statement/core/src/test/java/org/apache/shardingsphere/sql/parser/statement/core/value/identifier/IdentifierValueTest.java index f7ce8802bb80f..d0e30925c3e27 100644 --- a/parser/sql/statement/core/src/test/java/org/apache/shardingsphere/sql/parser/statement/core/value/identifier/IdentifierValueTest.java +++ b/parser/sql/statement/core/src/test/java/org/apache/shardingsphere/sql/parser/statement/core/value/identifier/IdentifierValueTest.java @@ -21,7 +21,6 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertNull; class IdentifierValueTest { @@ -65,15 +64,4 @@ void assertGetValueWithQuoteCharactersWithValue() { String text = "[foo]"; assertThat(new IdentifierValue(text).getValueWithQuoteCharacters(), is("[foo]")); } - - @Test - void assertGetQuotedContentWithNullValue() { - assertNull(IdentifierValue.getQuotedContent(null)); - } - - @Test - void assertGetQuotedContent() { - assertThat(IdentifierValue.getQuotedContent(" foo "), is("foo")); - assertThat(IdentifierValue.getQuotedContent("`foo`"), is("foo")); - } } diff --git a/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/simple/OpenGaussComQueryExecutor.java b/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/simple/OpenGaussComQueryExecutor.java index 604f07a431a0d..05518060ee6a0 100644 --- a/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/simple/OpenGaussComQueryExecutor.java +++ b/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/simple/OpenGaussComQueryExecutor.java @@ -27,6 +27,7 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.simple.PostgreSQLComQueryPacket; import org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLCommandCompletePacket; import org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLParameterStatusPacket; +import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandler; @@ -47,7 +48,6 @@ import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.SetStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.CommitStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.RollbackStatement; -import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import java.sql.SQLException; import java.util.ArrayList; @@ -114,7 +114,7 @@ private Collection createParameterStatusResponse(final SetStatem Collection result = new ArrayList<>(2); result.add(new PostgreSQLCommandCompletePacket("SET", 0L)); for (VariableAssignSegment each : sqlStatement.getVariableAssigns()) { - result.add(new PostgreSQLParameterStatusPacket(each.getVariable().getVariable(), IdentifierValue.getQuotedContent(each.getAssignValue()))); + result.add(new PostgreSQLParameterStatusPacket(each.getVariable().getVariable(), null == each.getAssignValue() ? null : QuoteCharacter.unwrapText(each.getAssignValue()))); } return result; } diff --git a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/Portal.java b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/Portal.java index 7761697e58506..1597a147f41d3 100644 --- a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/Portal.java +++ b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/Portal.java @@ -36,6 +36,7 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.identifier.PostgreSQLIdentifierPacket; import org.apache.shardingsphere.infra.binder.context.aware.ParameterAware; import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; +import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager; @@ -53,7 +54,6 @@ import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.EmptyStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.SetStatement; -import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import java.sql.SQLException; import java.util.ArrayList; @@ -162,7 +162,7 @@ private List createParameterStatusResponse(final SetStatement List result = new ArrayList<>(2); result.add(new PostgreSQLCommandCompletePacket("SET", 0L)); for (VariableAssignSegment each : sqlStatement.getVariableAssigns()) { - result.add(new PostgreSQLParameterStatusPacket(each.getVariable().getVariable(), IdentifierValue.getQuotedContent(each.getAssignValue()))); + result.add(new PostgreSQLParameterStatusPacket(each.getVariable().getVariable(), null == each.getAssignValue() ? null : QuoteCharacter.unwrapText(each.getAssignValue()))); } return result; } diff --git a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutor.java b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutor.java index 3d20c16d55edd..cd9110017693f 100644 --- a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutor.java +++ b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutor.java @@ -27,6 +27,7 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.simple.PostgreSQLComQueryPacket; import org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLCommandCompletePacket; import org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLParameterStatusPacket; +import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandler; @@ -47,7 +48,6 @@ import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.SetStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.CommitStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.RollbackStatement; -import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import java.sql.SQLException; import java.util.ArrayList; @@ -114,7 +114,7 @@ private Collection createParameterStatusResponse(final SetStatem Collection result = new ArrayList<>(2); result.add(new PostgreSQLCommandCompletePacket("SET", 0L)); for (VariableAssignSegment each : sqlStatement.getVariableAssigns()) { - result.add(new PostgreSQLParameterStatusPacket(each.getVariable().getVariable(), IdentifierValue.getQuotedContent(each.getAssignValue()))); + result.add(new PostgreSQLParameterStatusPacket(each.getVariable().getVariable(), null == each.getAssignValue() ? null : QuoteCharacter.unwrapText(each.getAssignValue()))); } return result; }