You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/09/29 07:34:29 UTC

[GitHub] [shardingsphere] justbk2015 opened a new pull request #12814: extend mppdb_decoding plugin support types: bit,timestamp,time,smalldate reltime etc

justbk2015 opened a new pull request #12814:
URL: https://github.com/apache/shardingsphere/pull/12814


   …atetime,bytea, raw, money, interval and delete '' by default action
   
   Fixes #12813.
   
   Changes proposed in this pull request:
   - repair bit 、datetime、time、bytea ' issue
   - add new type raw/text/character/nvarchar2/interval/reltime/money support and change default behaive to remote single quote ''
   - add some testcase.
   


-- 
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] sandynz commented on a change in pull request #12814: extend mppdb_decoding plugin support types: bit,timestamp,time,smalldate ,eltime etc

Posted by GitBox <gi...@apache.org>.
sandynz commented on a change in pull request #12814:
URL: https://github.com/apache/shardingsphere/pull/12814#discussion_r718430925



##########
File path: shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-opengauss/src/main/java/org/apache/shardingsphere/scaling/opengauss/wal/decode/MppdbDecodingPlugin.java
##########
@@ -158,28 +160,77 @@ private Object readColumnData(final String data, final String columnType) {
             case "boolean":
                 return Boolean.parseBoolean(data);
             case "time without time zone":
+            case "time with time zone":
                 try {
-                    return timestampUtils.toTime(null, data);
+                    return timestampUtils.toTime(null, decodeString(data));
                 } catch (final SQLException ex) {
                     throw new DecodingException(ex);
                 }
             case "date":
-                return Date.valueOf(data);
+                return Date.valueOf(decodeString(data));
             case "timestamp without time zone":
+            case "timestamp with time zone":
+            case "smalldatetime":
                 try {
-                    return timestampUtils.toTimestamp(null, data);
+                    return timestampUtils.toTimestamp(null, decodeString(data));
                 } catch (final SQLException ex) {
                     throw new DecodingException(ex);
                 }
             case "bytea":
-                return decodeHex(data.substring(2));
+                return decodeBytea(data);
+            case "raw":
+            case "reltime":
+                return decodePgObject(data, columnType);
+            case "money":
+                return decodeMoney(data);
+            case "interval":
+                return decodeInterval(data);
             case "character varying":
-                return decodeString(data);
+            case "text":
+            case "character":
+            case "nvarchar2":
             default:
-                return data;
+                return decodeString(data);
         }
     }
     
+    private static PGobject decodeInterval(final String data) {
+        try {
+            return new PGInterval(decodeString(data));
+        } catch (SQLException ex) {
+            return null;
+        }
+    }
+    
+    private static PGobject decodePgObject(final String data, final String type) {
+        try {
+            PGobject pgObject = new PGobject();
+            pgObject.setType(type);
+            pgObject.setValue(decodeString(data));
+            return pgObject;
+        } catch (SQLException ex) {
+            return null;
+        }
+    }
+    
+    private static PGobject decodeBytea(final String data) {
+        try {
+            PGobject pgObject = new PGobject();
+            pgObject.setType("bytea");
+            byte[] decodeByte = decodeHex(decodeString(data).substring(2));
+            pgObject.setValue(new String(decodeByte));
+            return pgObject;
+        } catch (SQLException ex) {

Review comment:
       Could be `final SQLException ignored`, and also other places.

##########
File path: shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-opengauss/src/test/java/org/apache/shardingsphere/scaling/opengauss/wal/decode/MppdbDecodingPluginTest.java
##########
@@ -50,14 +55,18 @@ public void assertDecodeWriteRowEvent() {
         MppTableData tableData = new MppTableData();
         tableData.setTableName("public.test");
         tableData.setOpType("INSERT");
-        tableData.setColumnsName(new String[]{"data"});
-        tableData.setColumnsType(new String[]{"character varyint"});
-        tableData.setColumnsVal(new String[]{"1 2 3"});
+        String[] insertTypes = new String[]{"character varying", "text", "char", "character", "nchar", "varchar2", "nvarchar2", "clob"};
+    

Review comment:
       Blank line could be removed, and also other places




-- 
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] sandynz merged pull request #12814: extend mppdb_decoding plugin support types: bit,timestamp,time,smalldate ,eltime etc

Posted by GitBox <gi...@apache.org>.
sandynz merged pull request #12814:
URL: https://github.com/apache/shardingsphere/pull/12814


   


-- 
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] sandynz commented on a change in pull request #12814: extend mppdb_decoding plugin support types: bit,timestamp,time,smalldate ,eltime etc

Posted by GitBox <gi...@apache.org>.
sandynz commented on a change in pull request #12814:
URL: https://github.com/apache/shardingsphere/pull/12814#discussion_r718430925



##########
File path: shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-opengauss/src/main/java/org/apache/shardingsphere/scaling/opengauss/wal/decode/MppdbDecodingPlugin.java
##########
@@ -158,28 +160,77 @@ private Object readColumnData(final String data, final String columnType) {
             case "boolean":
                 return Boolean.parseBoolean(data);
             case "time without time zone":
+            case "time with time zone":
                 try {
-                    return timestampUtils.toTime(null, data);
+                    return timestampUtils.toTime(null, decodeString(data));
                 } catch (final SQLException ex) {
                     throw new DecodingException(ex);
                 }
             case "date":
-                return Date.valueOf(data);
+                return Date.valueOf(decodeString(data));
             case "timestamp without time zone":
+            case "timestamp with time zone":
+            case "smalldatetime":
                 try {
-                    return timestampUtils.toTimestamp(null, data);
+                    return timestampUtils.toTimestamp(null, decodeString(data));
                 } catch (final SQLException ex) {
                     throw new DecodingException(ex);
                 }
             case "bytea":
-                return decodeHex(data.substring(2));
+                return decodeBytea(data);
+            case "raw":
+            case "reltime":
+                return decodePgObject(data, columnType);
+            case "money":
+                return decodeMoney(data);
+            case "interval":
+                return decodeInterval(data);
             case "character varying":
-                return decodeString(data);
+            case "text":
+            case "character":
+            case "nvarchar2":
             default:
-                return data;
+                return decodeString(data);
         }
     }
     
+    private static PGobject decodeInterval(final String data) {
+        try {
+            return new PGInterval(decodeString(data));
+        } catch (SQLException ex) {
+            return null;
+        }
+    }
+    
+    private static PGobject decodePgObject(final String data, final String type) {
+        try {
+            PGobject pgObject = new PGobject();
+            pgObject.setType(type);
+            pgObject.setValue(decodeString(data));
+            return pgObject;
+        } catch (SQLException ex) {
+            return null;
+        }
+    }
+    
+    private static PGobject decodeBytea(final String data) {
+        try {
+            PGobject pgObject = new PGobject();
+            pgObject.setType("bytea");
+            byte[] decodeByte = decodeHex(decodeString(data).substring(2));
+            pgObject.setValue(new String(decodeByte));
+            return pgObject;
+        } catch (SQLException ex) {

Review comment:
       Could be `final SQLException ignored`, and also other places.

##########
File path: shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-opengauss/src/test/java/org/apache/shardingsphere/scaling/opengauss/wal/decode/MppdbDecodingPluginTest.java
##########
@@ -50,14 +55,18 @@ public void assertDecodeWriteRowEvent() {
         MppTableData tableData = new MppTableData();
         tableData.setTableName("public.test");
         tableData.setOpType("INSERT");
-        tableData.setColumnsName(new String[]{"data"});
-        tableData.setColumnsType(new String[]{"character varyint"});
-        tableData.setColumnsVal(new String[]{"1 2 3"});
+        String[] insertTypes = new String[]{"character varying", "text", "char", "character", "nchar", "varchar2", "nvarchar2", "clob"};
+    

Review comment:
       Blank line could be removed, and also other places




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