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

[GitHub] [shardingsphere] jyotisharma7 opened a new pull request, #24358: PostgreSQL protocol support UUID binary data format

jyotisharma7 opened a new pull request, #24358:
URL: https://github.com/apache/shardingsphere/pull/24358

   Fixes #24043.
   
   Changes proposed in this pull request:
     - Support for UUID Datatype in ShardingSphere
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [X] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [X] I have self-reviewed the commit code.
   - [X] I have (or in comment I request) added corresponding labels for the pull request.
   - [X ] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [X ] I have made corresponding changes to the documentation.
   - [X] I have added corresponding unit tests for my changes.
   


-- 
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


[GitHub] [shardingsphere] jyotisharma7 commented on pull request #24358: PostgreSQL protocol support UUID binary data format

Posted by "jyotisharma7 (via GitHub)" <gi...@apache.org>.
jyotisharma7 commented on PR #24358:
URL: https://github.com/apache/shardingsphere/pull/24358#issuecomment-1449804520

   > It seems that the UUID in binary format is 16 bytes.
   > 
   > https://github.com/pgjdbc/pgjdbc/blob/99d010147b3e6907a39485ec0113c56d09fdfc37/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java#L3575-L3590
   
   
   
   > It seems that the UUID in binary format is 16 bytes.
   > 
   > https://github.com/pgjdbc/pgjdbc/blob/99d010147b3e6907a39485ec0113c56d09fdfc37/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java#L3575-L3590
   
   yes it is 16 bytes in binary format.


-- 
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


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

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN commented on code in PR #24358:
URL: https://github.com/apache/shardingsphere/pull/24358#discussion_r1122508485


##########
db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/PostgreSQLUUIDBinaryProtocolValueTest.java:
##########
@@ -0,0 +1,55 @@
+/*
+ * 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 io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import org.junit.Test;
+import java.util.UUID;
+
+import java.nio.charset.StandardCharsets;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public final class PostgreSQLUUIDBinaryProtocolValueTest {
+    
+    private final byte[] expected = new byte[5];

Review Comment:
   I wonder why the 5 bytes worked in unit test if UUID is 16 bytes?



-- 
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


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

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
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


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

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN commented on PR #24358:
URL: https://github.com/apache/shardingsphere/pull/24358#issuecomment-1447941713

   It seems that the UUID in binary format is 16 bytes.
   
   https://github.com/pgjdbc/pgjdbc/blob/99d010147b3e6907a39485ec0113c56d09fdfc37/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java#L3575-L3590


-- 
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


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

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN commented on code in PR #24358:
URL: https://github.com/apache/shardingsphere/pull/24358#discussion_r1121470639


##########
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();

Review Comment:
   I mean:
   ```suggestion
           return value.toString().length();
   ```



-- 
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


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

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN commented on PR #24358:
URL: https://github.com/apache/shardingsphere/pull/24358#issuecomment-1479341170

   Hi @jyotisharma7 
   Any update here?


-- 
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


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

Posted by "jyotisharma7 (via GitHub)" <gi...@apache.org>.
jyotisharma7 commented on code in PR #24358:
URL: https://github.com/apache/shardingsphere/pull/24358#discussion_r1121452031


##########
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();

Review Comment:
   yes it is required as it is a function.



-- 
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


Re: [PR] PostgreSQL protocol support UUID binary data format [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on PR #24358:
URL: https://github.com/apache/shardingsphere/pull/24358#issuecomment-2024273610

   Since pr #29662 has been merged, I will close this pr. If you have any problems with using the PostgreSQL UUID, please submit an issue.
   


-- 
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


Re: [PR] PostgreSQL protocol support UUID binary data format [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu closed pull request #24358: PostgreSQL protocol support UUID binary data format
URL: https://github.com/apache/shardingsphere/pull/24358


-- 
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


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

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN commented on code in PR #24358:
URL: https://github.com/apache/shardingsphere/pull/24358#discussion_r1119855209


##########
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();

Review Comment:
   Is the parentheses around `value.toString()` necessary?



##########
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[] result = new byte[parameterValueLength];
+        UUID uuidFromBytes = UUID.nameUUIDFromBytes(result);
+        payload.getByteBuf().readBytes(result);
+        return uuidFromBytes;

Review Comment:
   The variable to be returned should be named `result`.



##########
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[] result = new byte[parameterValueLength];
+        UUID uuidFromBytes = UUID.nameUUIDFromBytes(result);
+        payload.getByteBuf().readBytes(result);
+        return uuidFromBytes;
+    }
+    
+    @Override
+    public void write(final PostgreSQLPacketPayload payload, final Object value) {
+        payload.writeBytes((byte[]) value);

Review Comment:
   Is it possible that the value is an instance of `java.util.UUID`?



-- 
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


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

Posted by "jyotisharma7 (via GitHub)" <gi...@apache.org>.
jyotisharma7 commented on code in PR #24358:
URL: https://github.com/apache/shardingsphere/pull/24358#discussion_r1121463243


##########
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[] result = new byte[parameterValueLength];
+        UUID uuidFromBytes = UUID.nameUUIDFromBytes(result);
+        payload.getByteBuf().readBytes(result);
+        return uuidFromBytes;

Review Comment:
   I fixed this issue.



-- 
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


[GitHub] [shardingsphere] jyotisharma7 commented on pull request #24358: PostgreSQL protocol support UUID binary data format

Posted by "jyotisharma7 (via GitHub)" <gi...@apache.org>.
jyotisharma7 commented on PR #24358:
URL: https://github.com/apache/shardingsphere/pull/24358#issuecomment-1482265201

   > Hi @jyotisharma7 Any update here?
   
   Yes, I will update the PR will latest changes.


-- 
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