TeslaCN commented on code in PR #25044:
URL: https://github.com/apache/shardingsphere/pull/25044#discussion_r1165030979
##########
proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java:
##########
@@ -145,7 +153,17 @@ void assertExecuteSelectStatementAndReturnAllRows() throws
SQLException {
List<PostgreSQLValueFormat> resultFormats = new
ArrayList<>(Arrays.asList(PostgreSQLValueFormat.TEXT,
PostgreSQLValueFormat.BINARY));
Portal portal = new Portal("", preparedStatement,
Collections.emptyList(), resultFormats, backendConnection);
portal.bind();
- assertThat(portal.describe(),
instanceOf(PostgreSQLRowDescriptionPacket.class));
+
+ PostgreSQLPacket portalDescription = portal.describe();
+ assertThat(portalDescription,
instanceOf(PostgreSQLRowDescriptionPacket.class));
+ Optional<Collection<PostgreSQLColumnDescription>> columnDescriptions =
ReflectionUtils.getFieldValue(portalDescription, "columnDescriptions");
+ assertTrue(columnDescriptions.isPresent());
+ Iterator<PostgreSQLColumnDescription> columnDescriptionIterator =
columnDescriptions.get().iterator();
+ PostgreSQLColumnDescription textColumnDescription =
columnDescriptionIterator.next();
+ PostgreSQLColumnDescription intColumnDescription =
columnDescriptionIterator.next();
+ assertEquals(textColumnDescription.getDataFormat(),
PostgreSQLValueFormat.TEXT.getCode());
+ assertEquals(intColumnDescription.getDataFormat(),
PostgreSQLValueFormat.BINARY.getCode());
Review Comment:
Please use `assertThat` here.
##########
proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java:
##########
@@ -145,7 +153,17 @@ void assertExecuteSelectStatementAndReturnAllRows() throws
SQLException {
List<PostgreSQLValueFormat> resultFormats = new
ArrayList<>(Arrays.asList(PostgreSQLValueFormat.TEXT,
PostgreSQLValueFormat.BINARY));
Portal portal = new Portal("", preparedStatement,
Collections.emptyList(), resultFormats, backendConnection);
portal.bind();
- assertThat(portal.describe(),
instanceOf(PostgreSQLRowDescriptionPacket.class));
+
Review Comment:
Please remove blank line.
##########
db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/PostgreSQLColumnDescription.java:
##########
@@ -41,12 +42,20 @@ public final class PostgreSQLColumnDescription {
private final int typeModifier = -1;
- private final int dataFormat = 0;
+ private int dataFormat = PostgreSQLValueFormat.TEXT.getCode();
public PostgreSQLColumnDescription(final String columnName, final int
columnIndex, final int columnType, final int columnLength, final String
columnTypeName) {
this.columnName = columnName;
this.columnIndex = columnIndex;
this.columnLength = columnLength;
typeOID = Types.ARRAY == columnType ?
PostgreSQLArrayColumnType.getTypeOid(columnTypeName) :
PostgreSQLColumnType.valueOfJDBCType(columnType).getValue();
Review Comment:
Consider using `this(a, b, ...)` here.
##########
db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/PostgreSQLColumnDescription.java:
##########
@@ -41,12 +42,20 @@ public final class PostgreSQLColumnDescription {
private final int typeModifier = -1;
- private final int dataFormat = 0;
+ private int dataFormat = PostgreSQLValueFormat.TEXT.getCode();
Review Comment:
Please make this field final.
##########
proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java:
##########
@@ -132,8 +138,10 @@ void assertGetName() throws SQLException {
@Test
void assertExecuteSelectStatementAndReturnAllRows() throws SQLException {
QueryResponseHeader responseHeader = mock(QueryResponseHeader.class);
- QueryHeader queryHeader = new QueryHeader("schema", "table",
"columnLabel", "columnName", Types.INTEGER, "columnTypeName", 0, 0, false,
false, false, false);
-
when(responseHeader.getQueryHeaders()).thenReturn(Collections.singletonList(queryHeader));
+ QueryHeader queryHeader = new QueryHeader("schema", "table",
"columnLabel", "columnName", Types.VARCHAR, "columnTypeName", 0, 0, false,
false, false, false);
+ QueryHeader intColumnQueryHeader = new QueryHeader("schema", "table",
"columnLabel", "columnName", Types.INTEGER, "columnTypeName", 0, 0, false,
false, false, false);
+
when(responseHeader.getQueryHeaders()).thenReturn(Arrays.asList(queryHeader,
intColumnQueryHeader));
+
Review Comment:
Please remove blank line.
##########
proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java:
##########
@@ -145,7 +153,17 @@ void assertExecuteSelectStatementAndReturnAllRows() throws
SQLException {
List<PostgreSQLValueFormat> resultFormats = new
ArrayList<>(Arrays.asList(PostgreSQLValueFormat.TEXT,
PostgreSQLValueFormat.BINARY));
Portal portal = new Portal("", preparedStatement,
Collections.emptyList(), resultFormats, backendConnection);
portal.bind();
- assertThat(portal.describe(),
instanceOf(PostgreSQLRowDescriptionPacket.class));
+
+ PostgreSQLPacket portalDescription = portal.describe();
+ assertThat(portalDescription,
instanceOf(PostgreSQLRowDescriptionPacket.class));
+ Optional<Collection<PostgreSQLColumnDescription>> columnDescriptions =
ReflectionUtils.getFieldValue(portalDescription, "columnDescriptions");
+ assertTrue(columnDescriptions.isPresent());
+ Iterator<PostgreSQLColumnDescription> columnDescriptionIterator =
columnDescriptions.get().iterator();
+ PostgreSQLColumnDescription textColumnDescription =
columnDescriptionIterator.next();
+ PostgreSQLColumnDescription intColumnDescription =
columnDescriptionIterator.next();
+ assertEquals(textColumnDescription.getDataFormat(),
PostgreSQLValueFormat.TEXT.getCode());
+ assertEquals(intColumnDescription.getDataFormat(),
PostgreSQLValueFormat.BINARY.getCode());
+
Review Comment:
Please remove blank line.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]