You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "TeslaCN (via GitHub)" <gi...@apache.org> on 2023/04/06 10:02:38 UTC

[GitHub] [shardingsphere] TeslaCN commented on a diff in pull request #24358: PostgreSQL protocol support UUID binary data format

TeslaCN commented on code in PR #24358:
URL: https://github.com/apache/shardingsphere/pull/24358#discussion_r1159574720


##########
db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/PostgreSQLUUIDBinaryProtocolValue.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.protocol;
+
+import java.util.UUID;
+import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+
+/**
+ * Binary protocol value for UUID for PostgreSQL.
+ */
+public final class PostgreSQLUUIDBinaryProtocolValue implements PostgreSQLBinaryProtocolValue {
+    
+    @Override
+    public int getColumnLength(final Object value) {
+        return value.toString().length();
+    }
+    
+    @Override
+    public Object read(final PostgreSQLPacketPayload payload, final int parameterValueLength) {
+        byte[] uuidFromBytes = new byte[parameterValueLength];
+        UUID result = UUID.nameUUIDFromBytes(uuidFromBytes);

Review Comment:
   `UUID.nameUUIDFromBytes` is not for deserializing.
   
   This is how PostgreSQL JDBC deserialize an UUID instance.
   https://github.com/pgjdbc/pgjdbc/blob/99d010147b3e6907a39485ec0113c56d09fdfc37/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java#L3589
   
   



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org