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/10/10 09:51:01 UTC

[GitHub] [shardingsphere] tuichenchuxin opened a new pull request, #21456: support use federation to query sharding sphere data.

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

   For #21268.
   
   Changes proposed in this pull request:
     - support use federation to query sharding sphere data.
   
   
   ---
   
   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 passed maven check: `mvn clean install -B -T2C -DskipTests -Dmaven.javadoc.skip=true -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [ ] 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] strongduanmu commented on a diff in pull request #21456: Support using federation to query ShardingSphere data.

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on code in PR #21456:
URL: https://github.com/apache/shardingsphere/pull/21456#discussion_r991146556


##########
kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/executor/ShardingSphereDataFederationQueryEngine.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.sqlfederation.optimizer.executor;
+
+import org.apache.calcite.config.CalciteConnectionProperty;
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.jdbc.CalciteConnection;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereDatabaseData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereSchemaData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereTableData;
+import org.apache.shardingsphere.infra.metadata.data.query.ShardingSphereDataQueryEngine;
+import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
+import org.apache.shardingsphere.sqlfederation.optimizer.metadata.memory.MemorySchema;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+
+/**
+ * ShardingSphere data federation query engine.
+ */
+public final class ShardingSphereDataFederationQueryEngine implements ShardingSphereDataQueryEngine {
+    
+    private ShardingSphereMetaData metaData;
+    
+    private Map<String, ShardingSphereDatabaseData> databaseData;
+    
+    @Override
+    public void init(final ShardingSphereMetaData metaData, final Map<String, ShardingSphereDatabaseData> databaseData) {
+        this.databaseData = databaseData;
+        this.metaData = metaData;
+    }
+    
+    @Override
+    public Connection createConnection(final String databaseName, final String schemaName) throws SQLException {
+        Map<String, ShardingSphereTableData> tableDataMap = Optional.ofNullable(databaseData.get(databaseName)).map(database -> database.getSchemaData().get(schemaName))
+                .map(ShardingSphereSchemaData::getTableData).orElseGet(LinkedHashMap::new);
+        ShardingSphereSchema shardingSphereSchema = Optional.ofNullable(metaData.getDatabase(databaseName)).map(database -> database.getSchema(schemaName))
+                .orElseGet(ShardingSphereSchema::new);
+        MemorySchema memorySchema = new MemorySchema(tableDataMap, shardingSphereSchema);
+        Properties info = new Properties();
+        info.setProperty(CalciteConnectionProperty.DEFAULT_NULL_COLLATION.camelName(), NullCollation.LAST.name());
+        info.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), "false");
+        Connection result = DriverManager.getConnection("jdbc:calcite:", info);

Review Comment:
   Please use sql federation engine instead of a new calcite engine.



-- 
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 #21456: Support using federation to query ShardingSphere data.

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

   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/21456?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 [#21456](https://codecov.io/gh/apache/shardingsphere/pull/21456?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (6fb91ab) into [master](https://codecov.io/gh/apache/shardingsphere/commit/4c778a7eab7e1c867c1803568fc1ac7030774b1b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (4c778a7) will **decrease** coverage by `0.04%`.
   > The diff coverage is `21.73%`.
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #21456      +/-   ##
   ============================================
   - Coverage     61.33%   61.28%   -0.05%     
   + Complexity     2509     2508       -1     
   ============================================
     Files          4105     4109       +4     
     Lines         56924    56975      +51     
     Branches       7521     7523       +2     
   ============================================
   + Hits          34913    34916       +3     
   - Misses        19086    19134      +48     
     Partials       2925     2925              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/21456?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...etadata/data/ShardingStatisticsTableCollector.java](https://codecov.io/gh/apache/shardingsphere/pull/21456/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-ZmVhdHVyZXMvc2hhcmRpbmcvY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2hhcmRpbmcvbWV0YWRhdGEvZGF0YS9TaGFyZGluZ1N0YXRpc3RpY3NUYWJsZUNvbGxlY3Rvci5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...sphere/infra/metadata/data/ShardingSphereData.java](https://codecov.io/gh/apache/shardingsphere/pull/21456/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-aW5mcmEvY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9tZXRhZGF0YS9kYXRhL1NoYXJkaW5nU3BoZXJlRGF0YS5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...ta/query/ShardingSphereDataQueryEngineFactory.java](https://codecov.io/gh/apache/shardingsphere/pull/21456/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-aW5mcmEvY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9tZXRhZGF0YS9kYXRhL3F1ZXJ5L1NoYXJkaW5nU3BoZXJlRGF0YVF1ZXJ5RW5naW5lRmFjdG9yeS5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [.../datasource/config/yaml/YamlJdbcConfiguration.java](https://codecov.io/gh/apache/shardingsphere/pull/21456/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-a2VybmVsL2RhdGEtcGlwZWxpbmUvYXBpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9kYXRhL3BpcGVsaW5lL2FwaS9kYXRhc291cmNlL2NvbmZpZy95YW1sL1lhbWxKZGJjQ29uZmlndXJhdGlvbi5qYXZh) | `100.00% <ø> (ø)` | |
   | [...i/impl/AbstractInventoryIncrementalJobAPIImpl.java](https://codecov.io/gh/apache/shardingsphere/pull/21456/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-a2VybmVsL2RhdGEtcGlwZWxpbmUvY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvZGF0YS9waXBlbGluZS9jb3JlL2FwaS9pbXBsL0Fic3RyYWN0SW52ZW50b3J5SW5jcmVtZW50YWxKb2JBUElJbXBsLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...ngauss/ingest/wal/OpenGaussLogicalReplication.java](https://codecov.io/gh/apache/shardingsphere/pull/21456/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-a2VybmVsL2RhdGEtcGlwZWxpbmUvZGlhbGVjdC9vcGVuZ2F1c3Mvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2RhdGEvcGlwZWxpbmUvb3BlbmdhdXNzL2luZ2VzdC93YWwvT3BlbkdhdXNzTG9naWNhbFJlcGxpY2F0aW9uLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...cutor/ShardingSphereDataFederationQueryEngine.java](https://codecov.io/gh/apache/shardingsphere/pull/21456/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-a2VybmVsL3NxbC1mZWRlcmF0aW9uL29wdGltaXplci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsZmVkZXJhdGlvbi9vcHRpbWl6ZXIvZXhlY3V0b3IvU2hhcmRpbmdTcGhlcmVEYXRhRmVkZXJhdGlvblF1ZXJ5RW5naW5lLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...on/optimizer/metadata/memory/MemoryEnumerator.java](https://codecov.io/gh/apache/shardingsphere/pull/21456/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-a2VybmVsL3NxbC1mZWRlcmF0aW9uL29wdGltaXplci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsZmVkZXJhdGlvbi9vcHRpbWl6ZXIvbWV0YWRhdGEvbWVtb3J5L01lbW9yeUVudW1lcmF0b3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...ration/optimizer/metadata/memory/MemorySchema.java](https://codecov.io/gh/apache/shardingsphere/pull/21456/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-a2VybmVsL3NxbC1mZWRlcmF0aW9uL29wdGltaXplci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsZmVkZXJhdGlvbi9vcHRpbWl6ZXIvbWV0YWRhdGEvbWVtb3J5L01lbW9yeVNjaGVtYS5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [...eration/optimizer/metadata/memory/MemoryTable.java](https://codecov.io/gh/apache/shardingsphere/pull/21456/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-a2VybmVsL3NxbC1mZWRlcmF0aW9uL29wdGltaXplci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsZmVkZXJhdGlvbi9vcHRpbWl6ZXIvbWV0YWRhdGEvbWVtb3J5L01lbW9yeVRhYmxlLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | ... and [20 more](https://codecov.io/gh/apache/shardingsphere/pull/21456/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?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 commented on a diff in pull request #21456: Support using federation to query ShardingSphere data.

Posted by GitBox <gi...@apache.org>.
tuichenchuxin commented on code in PR #21456:
URL: https://github.com/apache/shardingsphere/pull/21456#discussion_r992126327


##########
kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/executor/ShardingSphereDataFederationQueryEngine.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.sqlfederation.optimizer.executor;
+
+import org.apache.calcite.config.CalciteConnectionProperty;
+import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.jdbc.CalciteConnection;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereDatabaseData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereSchemaData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereTableData;
+import org.apache.shardingsphere.infra.metadata.data.query.ShardingSphereDataQueryEngine;
+import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
+import org.apache.shardingsphere.sqlfederation.optimizer.metadata.memory.MemorySchema;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+
+/**
+ * ShardingSphere data federation query engine.
+ */
+public final class ShardingSphereDataFederationQueryEngine implements ShardingSphereDataQueryEngine {
+    
+    private ShardingSphereMetaData metaData;
+    
+    private Map<String, ShardingSphereDatabaseData> databaseData;
+    
+    @Override
+    public void init(final ShardingSphereMetaData metaData, final Map<String, ShardingSphereDatabaseData> databaseData) {
+        this.databaseData = databaseData;
+        this.metaData = metaData;
+    }
+    
+    @Override
+    public Connection createConnection(final String databaseName, final String schemaName) throws SQLException {
+        Map<String, ShardingSphereTableData> tableDataMap = Optional.ofNullable(databaseData.get(databaseName)).map(database -> database.getSchemaData().get(schemaName))
+                .map(ShardingSphereSchemaData::getTableData).orElseGet(LinkedHashMap::new);
+        ShardingSphereSchema shardingSphereSchema = Optional.ofNullable(metaData.getDatabase(databaseName)).map(database -> database.getSchema(schemaName))
+                .orElseGet(ShardingSphereSchema::new);
+        MemorySchema memorySchema = new MemorySchema(tableDataMap, shardingSphereSchema);
+        Properties info = new Properties();
+        info.setProperty(CalciteConnectionProperty.DEFAULT_NULL_COLLATION.camelName(), NullCollation.LAST.name());
+        info.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), "false");
+        Connection result = DriverManager.getConnection("jdbc:calcite:", info);

Review Comment:
   Thank you. Done.



-- 
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 merged pull request #21456: Support using federation to query ShardingSphere data.

Posted by GitBox <gi...@apache.org>.
strongduanmu merged PR #21456:
URL: https://github.com/apache/shardingsphere/pull/21456


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