-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:support information_schema.PARAMETERS query in cluster mod (#24378)
- Loading branch information
Showing
4 changed files
with
99 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...shardingsphere/proxy/backend/collector/MySQLInformationSchemaParameterTableCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.apache.shardingsphere.proxy.backend.collector; | ||
|
||
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; | ||
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; | ||
import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereRowData; | ||
import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereTableData; | ||
import org.apache.shardingsphere.infra.metadata.statistics.collector.ShardingSphereStatisticsCollector; | ||
import org.apache.shardingsphere.infra.metadata.statistics.collector.ShardingSphereTableDataCollectorUtils; | ||
import org.apache.shardingsphere.proxy.backend.context.ProxyContext; | ||
|
||
import java.sql.SQLException; | ||
import java.util.*; | ||
|
||
/** | ||
* @author sheldon | ||
* @date 2023-09-28 | ||
*/ | ||
public final class MySQLInformationSchemaParameterTableCollector implements ShardingSphereStatisticsCollector { | ||
|
||
private final static String PARAMETER_TABLE_NAME = "PARAMETERS"; | ||
|
||
private final static String COLLECT_SQL = "select * from information_schema.PARAMETERS"; | ||
|
||
@Override | ||
public Optional<ShardingSphereTableData> collect(String databaseName, ShardingSphereTable table, Map<String, ShardingSphereDatabase> shardingSphereDatabases) throws SQLException { | ||
Optional<String> databaseWithDatasource = ProxyContext.getInstance().getAllDatabaseNames().stream().filter(MySQLInformationSchemaParameterTableCollector::hasDataSource).findFirst(); | ||
if (databaseWithDatasource.isPresent()) { | ||
Collection<ShardingSphereRowData> rows = ShardingSphereTableDataCollectorUtils.collectRowData(shardingSphereDatabases.get(databaseWithDatasource.get()), | ||
table, table.getColumnNames(), COLLECT_SQL); | ||
ShardingSphereTableData result = new ShardingSphereTableData(PARAMETER_TABLE_NAME); | ||
result.getRows().addAll(rows); | ||
return Optional.of(result); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
private static Boolean hasDataSource(final String databaseName) { | ||
return ProxyContext.getInstance().getDatabase(databaseName).containsDataSource(); | ||
} | ||
|
||
@Override | ||
public Object getType() { | ||
return PARAMETER_TABLE_NAME; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...ache.shardingsphere.infra.metadata.statistics.collector.ShardingSphereStatisticsCollector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
org.apache.shardingsphere.proxy.backend.collector.MySQLInformationSchemaParameterTableCollector |