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 2022/02/16 02:01:45 UTC

[GitHub] [shardingsphere] tuichenchuxin opened a new pull request #15431: refactor encrypt config extract data type

tuichenchuxin opened a new pull request #15431:
URL: https://github.com/apache/shardingsphere/pull/15431


   for #14987.
   
   Changes proposed in this pull request:
   - refactor encrypt config extract data type
   


-- 
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] codecov-commenter commented on pull request #15431: refactor encrypt config extract data type

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #15431:
URL: https://github.com/apache/shardingsphere/pull/15431#issuecomment-1041054134


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15431?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#15431](https://codecov.io/gh/apache/shardingsphere/pull/15431?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (5ada1e0) into [master](https://codecov.io/gh/apache/shardingsphere/commit/d02698ae25fd81dc384d58a729dbf51a300576cb?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (d02698a) will **increase** coverage by `0.02%`.
   > The diff coverage is `72.56%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/15431/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/15431?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #15431      +/-   ##
   ============================================
   + Coverage     60.48%   60.51%   +0.02%     
     Complexity     1954     1954              
   ============================================
     Files          3220     3221       +1     
     Lines         48249    48340      +91     
     Branches       8234     8249      +15     
   ============================================
   + Hits          29183    29252      +69     
   - Misses        16695    16717      +22     
     Partials       2371     2371              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/15431?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...ere/encrypt/spi/context/EncryptColumnDataType.java](https://codecov.io/gh/apache/shardingsphere/pull/15431/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWFwaS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvZW5jcnlwdC9zcGkvY29udGV4dC9FbmNyeXB0Q29sdW1uRGF0YVR5cGUuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...ache/shardingsphere/encrypt/rule/EncryptTable.java](https://codecov.io/gh/apache/shardingsphere/pull/15431/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcnVsZS9FbmNyeXB0VGFibGUuamF2YQ==) | `65.30% <43.75%> (-20.41%)` | :arrow_down: |
   | [...pache/shardingsphere/encrypt/rule/EncryptRule.java](https://codecov.io/gh/apache/shardingsphere/pull/15431/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcnVsZS9FbmNyeXB0UnVsZS5qYXZh) | `71.71% <44.44%> (-1.69%)` | :arrow_down: |
   | [.../rule/extractor/MySQLEncryptDataTypeExtractor.java](https://codecov.io/gh/apache/shardingsphere/pull/15431/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcnVsZS9leHRyYWN0b3IvTXlTUUxFbmNyeXB0RGF0YVR5cGVFeHRyYWN0b3IuamF2YQ==) | `92.20% <92.20%> (ø)` | |
   | [...ite/context/EncryptSQLRewriteContextDecorator.java](https://codecov.io/gh/apache/shardingsphere/pull/15431/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS9jb250ZXh0L0VuY3J5cHRTUUxSZXdyaXRlQ29udGV4dERlY29yYXRvci5qYXZh) | `61.53% <0.00%> (ø)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15431?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15431?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [d02698a...5ada1e0](https://codecov.io/gh/apache/shardingsphere/pull/15431?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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] tuichenchuxin closed pull request #15431: refactor encrypt config extract data type

Posted by GitBox <gi...@apache.org>.
tuichenchuxin closed pull request #15431:
URL: https://github.com/apache/shardingsphere/pull/15431


   


-- 
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] strongduanmu commented on a change in pull request #15431: refactor encrypt config extract data type

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



##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/main/java/org/apache/shardingsphere/encrypt/spi/EncryptDataTypeExtractor.java
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.encrypt.spi;
+
+import org.apache.shardingsphere.infra.database.type.DatabaseTypeAwareSPI;
+import org.apache.shardingsphere.spi.singleton.SingletonSPI;
+
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Encrypt data type extractor for SPI.
+ */
+public interface EncryptDataTypeExtractor extends DatabaseTypeAwareSPI, SingletonSPI {

Review comment:
       @tuichenchuxin Maybe `EncryptDataTypeConverter` may be better.

##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/extractor/MySQLEncryptDataTypeExtractor.java
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.encrypt.rule.extractor;
+
+import org.apache.shardingsphere.encrypt.spi.EncryptDataTypeExtractor;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * MySQL encrypt data type extractor.
+ */
+public final class MySQLEncryptDataTypeExtractor implements EncryptDataTypeExtractor {
+    
+    private final Map<String, String> compatibleDbDataTypes = initCompatibleDataTypes();
+    
+    private Map<String, String> initCompatibleDataTypes() {
+        Map<String, String> result = new LinkedHashMap<>();
+        result.put("bool", "tinyint");
+        result.put("boolean", "tinyint");
+        result.put("character varying", "varchar");
+        result.put("fixed", "decimal");
+        result.put("float4", "float");
+        result.put("float8", "double");
+        result.put("int1", "tinyint");
+        result.put("int2", "smallint");
+        result.put("int3", "mediumint");
+        result.put("int4", "int");
+        result.put("int8", "bigint");
+        result.put("long varbinary", "mediumblob");
+        result.put("long varchar", "mediumtext");
+        result.put("long char varying", "mediumtext");
+        result.put("long", "mediumtext");
+        result.put("middleint", "mediumint");
+        result.put("numeric", "decimal");
+        result.put("nchar", "char");
+        result.put("national character", "char");
+        result.put("national char", "char");
+        result.put("national varchar", "varchar");
+        result.put("nvarchar", "varchar");
+        result.put("nchar varchar", "varchar");
+        result.put("national character varying", "varchar");
+        result.put("national char varying", "varchar");
+        result.put("nchar varying", "varchar");
+        result.put("serial", "bigint");
+        result.put("geometrycollection", "binary");
+        result.put("year", "date");
+        result.put("geometry", "binary");
+        result.put("json", "text");
+        result.put("point", "binary");
+        result.put("multipoint", "binary");
+        result.put("linestring", "binary");
+        result.put("multilinestring", "binary");
+        result.put("polygon", "binary");
+        result.put("multipolygon", "binary");
+        return result;
+    }
+    
+    @Override
+    public Optional<Integer> getDataType(final String typeName, final Map<String, Integer> dataTypes) {
+        return Optional.ofNullable(dataTypes.get(getRealDataTypeName(typeName)));
+    }
+    
+    private String getRealDataTypeName(final String fullDataTypeDefinition) {
+        String dataType = extractConfigDataType(fullDataTypeDefinition);
+        return compatibleDbDataTypes.getOrDefault(dataType, dataType);
+    }
+    
+    private String extractConfigDataType(final String fullDataTypeDefinition) {
+        String dataType = fullDataTypeDefinition.trim().toLowerCase();
+        Optional<String> multiWordDataType = findMultiWordDataType(dataType);
+        if (multiWordDataType.isPresent()) {
+            return multiWordDataType.get();
+        }
+        if (dataType.contains("(")) {
+            return dataType.substring(0, dataType.indexOf("("));
+        } 
+        if (dataType.contains(" ")) {
+            return dataType.substring(0, dataType.indexOf(" "));
+        } 
+        return dataType;

Review comment:
       Please rename it to result.

##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
##########
@@ -67,19 +69,27 @@
     public EncryptRule(final EncryptRuleConfiguration config, final Map<String, DataSource> dataSourceMap) {
         Preconditions.checkArgument(isValidRuleConfiguration(config), "Invalid encrypt column configurations in EncryptTableRuleConfigurations.");
         config.getEncryptors().forEach((key, value) -> encryptors.put(key, ShardingSphereAlgorithmFactory.createAlgorithm(value, EncryptAlgorithm.class)));
-        Map<String, Integer> dataTypes = containsConfigDataTypeColumn(config.getTables()) ? getDataTypes(dataSourceMap) : Collections.emptyMap();
-        config.getTables().forEach(each -> tables.put(each.getName(), new EncryptTable(each, dataTypes)));
+        initEncryptTables(config.getTables(), dataSourceMap);

Review comment:
       createEncryptTables may be better.

##########
File path: shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rule/extractor/MySQLEncryptDataTypeExtractor.java
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.encrypt.rule.extractor;
+
+import org.apache.shardingsphere.encrypt.spi.EncryptDataTypeExtractor;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * MySQL encrypt data type extractor.
+ */
+public final class MySQLEncryptDataTypeExtractor implements EncryptDataTypeExtractor {
+    
+    private final Map<String, String> compatibleDbDataTypes = initCompatibleDataTypes();

Review comment:
       Please add static modifier for compatibleDbDataTypes, and change this field for more meaningful name.




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