This is an automated email from the ASF dual-hosted git repository.
jianglongtao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 1107d39edd6 add convert rule configuration provider for Broadcast.
(#30536)
1107d39edd6 is described below
commit 1107d39edd619cbee2b5c4a64d8807f635a76bb2
Author: Zonglei Dong <[email protected]>
AuthorDate: Tue Mar 19 07:40:57 2024 +0800
add convert rule configuration provider for Broadcast. (#30536)
* add convert rule configuration provider for Broadcast.
* format code
---
.../constant/BroadcastDistSQLConstants.java | 34 +++++++++++++
.../BroadcastConvertRuleConfigurationProvider.java | 58 ++++++++++++++++++++++
...ry.ral.convert.ConvertRuleConfigurationProvider | 18 +++++++
3 files changed, 110 insertions(+)
diff --git
a/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/constant/BroadcastDistSQLConstants.java
b/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/constant/BroadcastDistSQLConstants.java
new file mode 100644
index 00000000000..a622e1d0bf5
--- /dev/null
+++
b/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/constant/BroadcastDistSQLConstants.java
@@ -0,0 +1,34 @@
+/*
+ * 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.broadcast.distsql.handler.constant;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Broadcast DistSQL constants.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class BroadcastDistSQLConstants {
+
+ public static final String COMMA = ", ";
+
+ public static final String SEMI = ";";
+
+ public static final String CREATE_BROADCAST_RULE = "CREATE BROADCAST TABLE
RULE ";
+}
diff --git
a/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/provider/BroadcastConvertRuleConfigurationProvider.java
b/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/provider/BroadcastConvertRuleConfigurationProvider.java
new file mode 100644
index 00000000000..233bcdf72a3
--- /dev/null
+++
b/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/provider/BroadcastConvertRuleConfigurationProvider.java
@@ -0,0 +1,58 @@
+/*
+ * 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.broadcast.distsql.handler.provider;
+
+import
org.apache.shardingsphere.broadcast.api.config.BroadcastRuleConfiguration;
+import
org.apache.shardingsphere.broadcast.distsql.handler.constant.BroadcastDistSQLConstants;
+import
org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.ConvertRuleConfigurationProvider;
+import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+
+import java.util.Iterator;
+
+/**
+ * Broadcast convert rule configuration provider.
+ */
+public final class BroadcastConvertRuleConfigurationProvider implements
ConvertRuleConfigurationProvider {
+
+ @Override
+ public String convert(final RuleConfiguration ruleConfig) {
+ return getBroadcastDistSQL((BroadcastRuleConfiguration) ruleConfig);
+ }
+
+ private String getBroadcastDistSQL(final BroadcastRuleConfiguration
ruleConfig) {
+ if (ruleConfig.getTables().isEmpty()) {
+ return "";
+ }
+ StringBuilder result = new
StringBuilder(BroadcastDistSQLConstants.CREATE_BROADCAST_RULE);
+ Iterator<String> iterator = ruleConfig.getTables().iterator();
+ while (iterator.hasNext()) {
+ String tableName = iterator.next();
+ result.append(tableName);
+ if (iterator.hasNext()) {
+ result.append(BroadcastDistSQLConstants.COMMA);
+ }
+ }
+
result.append(BroadcastDistSQLConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator());
+ return result.toString();
+ }
+
+ @Override
+ public Class<? extends RuleConfiguration> getType() {
+ return BroadcastRuleConfiguration.class;
+ }
+}
diff --git
a/features/broadcast/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.ConvertRuleConfigurationProvider
b/features/broadcast/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.ConvertRuleConfigurationProvider
new file mode 100644
index 00000000000..43fb0a80b70
--- /dev/null
+++
b/features/broadcast/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.ConvertRuleConfigurationProvider
@@ -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.broadcast.distsql.handler.provider.BroadcastConvertRuleConfigurationProvider