Skip to content

Commit

Permalink
Add PipelineMetaDataProcessConfigurationGovernanceRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Nov 22, 2023
2 parents 2b4a42c + ba88f53 commit 09fbb09
Show file tree
Hide file tree
Showing 31 changed files with 1,170 additions and 41 deletions.
6 changes: 3 additions & 3 deletions docs/document/content/dev-manual/sharding.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ chapter = true

### 全限定类名

[`org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/spi/KeyGenerateAlgorithm.java)
[`org.apache.shardingsphere.keygen.core.algorithm.KeyGenerateAlgorithm`](https://github.com/apache/shardingsphere/blob/master/infra/algorithm/key-generator/core/src/main/java/org/apache/shardingsphere/keygen/core/algorithm/KeyGenerateAlgorithm.java)

### 定义

Expand All @@ -44,8 +44,8 @@ chapter = true

| *配置标识* | *详细说明* | *全限定类名* |
|-----------------|-------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| SNOWFLAKE | 基于雪花算法的分布式主键生成算法 | [`org.apache.shardingsphere.sharding.algorithm.keygen.SnowflakeKeyGenerateAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithm.java) |
| UUID | 基于 UUID 的分布式主键生成算法 | [`org.apache.shardingsphere.sharding.algorithm.keygen.UUIDKeyGenerateAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/UUIDKeyGenerateAlgorithm.java) |
| SNOWFLAKE | 基于雪花算法的分布式主键生成算法 | [`org.apache.shardingsphere.keygen.snowflake.algorithm.SnowflakeKeyGenerateAlgorithm`](https://github.com/apache/shardingsphere/blob/master/infra/algorithm/key-generator/type/snowflake/src/main/java/org/apache/shardingsphere/keygen/snowflake/algorithm/SnowflakeKeyGenerateAlgorithm.java) |
| UUID | 基于 UUID 的分布式主键生成算法 | [`org.apache.shardingsphere.keygen.uuid.algorithm.UUIDKeyGenerateAlgorithm`](https://github.com/apache/shardingsphere/blob/master/infra/algorithm/key-generator/type/uuid/src/main/java/org/apache/shardingsphere/keygen/uuid/algorithm/UUIDKeyGenerateAlgorithm.java) |

## ShardingAuditAlgorithm

Expand Down
6 changes: 3 additions & 3 deletions docs/document/content/dev-manual/sharding.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Sharding Algorithm definition

### Fully-qualified class name

[`org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/spi/KeyGenerateAlgorithm.java)
[`org.apache.shardingsphere.keygen.core.algorithm.KeyGenerateAlgorithm`](https://github.com/apache/shardingsphere/blob/master/infra/algorithm/key-generator/core/src/main/java/org/apache/shardingsphere/keygen/core/algorithm/KeyGenerateAlgorithm.java)

### Definition

Expand All @@ -44,8 +44,8 @@ Distributed Key Generating Algorithm definition

| *Configuration Type* | *Description* | *Fully-qualified class name* |
|----------------------|----------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| SNOWFLAKE | Snowflake key generate algorithm | [`org.apache.shardingsphere.sharding.algorithm.keygen.SnowflakeKeyGenerateAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithm.java) |
| UUID | UUID key generate algorithm | [`org.apache.shardingsphere.sharding.algorithm.keygen.UUIDKeyGenerateAlgorithm`](https://github.com/apache/shardingsphere/blob/master/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/UUIDKeyGenerateAlgorithm.java) |
| SNOWFLAKE | Snowflake key generate algorithm | [`org.apache.shardingsphere.keygen.snowflake.algorithm.SnowflakeKeyGenerateAlgorithm`](https://github.com/apache/shardingsphere/blob/master/infra/algorithm/key-generator/type/snowflake/src/main/java/org/apache/shardingsphere/keygen/snowflake/algorithm/SnowflakeKeyGenerateAlgorithm.java) |
| UUID | UUID key generate algorithm | [`org.apache.shardingsphere.keygen.uuid.algorithm.UUIDKeyGenerateAlgorithm`](https://github.com/apache/shardingsphere/blob/master/infra/algorithm/key-generator/type/uuid/src/main/java/org/apache/shardingsphere/keygen/uuid/algorithm/UUIDKeyGenerateAlgorithm.java) |

## ShardingAuditAlgorithm

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import org.apache.shardingsphere.infra.util.json.JsonUtils;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;

/**
* Properties converter.
Expand All @@ -38,11 +38,8 @@ public final class PropertiesConverter {
* @return converted string content
*/
public static String convert(final Properties props) {
if (null == props) {
return "";
}
Map<Object, Object> sortedProps = new LinkedHashMap<>();
props.keySet().stream().map(Object::toString).sorted().forEach(each -> sortedProps.put(each, props.get(each)));
return sortedProps.isEmpty() ? "" : JsonUtils.toJsonString(sortedProps);
return null == props || props.isEmpty() ? ""
: JsonUtils.toJsonString(props.keySet().stream().map(Object::toString).sorted()
.collect(Collectors.toMap(each -> each, props::get, (oldValue, currentValue) -> oldValue, LinkedHashMap::new)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private List<DataRecord> handleUpdateRowsEvent(final UpdateRowsEvent event, fina
for (int j = 0; j < beforeValues.length; j++) {
Serializable oldValue = beforeValues[j];
Serializable newValue = afterValues[j];
boolean updated = !Objects.equals(newValue, oldValue);
boolean updated = !Objects.deepEquals(newValue, oldValue);
PipelineColumnMetaData columnMetaData = tableMetaData.getColumnMetaData(j + 1);
dataRecord.addColumn(new Column(columnMetaData.getName(),
handleValue(columnMetaData, oldValue),
Expand Down
7 changes: 7 additions & 0 deletions kernel/sql-translator/distsql/handler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,12 @@
<artifactId>shardingsphere-sql-translator-distsql-parser</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test-util</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
* limitations under the License.
*/

package org.apache.shardingsphere.sqltranslator.distsql.handler;
package org.apache.shardingsphere.sqltranslator.distsql.handler.query;

import org.apache.shardingsphere.distsql.handler.ral.query.MetaDataRequiredQueryableRALExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.sqltranslator.api.config.SQLTranslatorRuleConfiguration;
import org.apache.shardingsphere.sqltranslator.distsql.statement.ShowSQLTranslatorRuleStatement;
import org.apache.shardingsphere.sqltranslator.distsql.statement.queryable.ShowSQLTranslatorRuleStatement;
import org.apache.shardingsphere.sqltranslator.rule.SQLTranslatorRule;

import java.util.Arrays;
Expand All @@ -40,12 +41,13 @@ public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereMetaData
}

private Collection<LocalDataQueryResultRow> buildData(final SQLTranslatorRuleConfiguration ruleConfig) {
return Collections.singleton(new LocalDataQueryResultRow(null != ruleConfig.getType() ? ruleConfig.getType() : "", String.valueOf(ruleConfig.isUseOriginalSQLWhenTranslatingFailed())));
return Collections.singleton(new LocalDataQueryResultRow(null == ruleConfig.getType() ? "" : ruleConfig.getType(),
PropertiesConverter.convert(ruleConfig.getProps()), String.valueOf(ruleConfig.isUseOriginalSQLWhenTranslatingFailed())));
}

@Override
public Collection<String> getColumnNames() {
return Arrays.asList("type", "use_original_sql_when_translating_failed");
return Arrays.asList("type", "props", "use_original_sql_when_translating_failed");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.sqltranslator.distsql.handler.update;

import org.apache.shardingsphere.distsql.handler.ral.update.GlobalRuleRALUpdater;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sqltranslator.api.config.SQLTranslatorRuleConfiguration;
import org.apache.shardingsphere.sqltranslator.distsql.statement.updateable.AlterSQLTranslatorRuleStatement;
import org.apache.shardingsphere.sqltranslator.spi.SQLTranslator;

/**
* Alter SQL translator rule statement handler.
*/
public final class AlterSQLTranslatorRuleStatementUpdater implements GlobalRuleRALUpdater<AlterSQLTranslatorRuleStatement, SQLTranslatorRuleConfiguration> {

@Override
public void checkSQLStatement(final SQLTranslatorRuleConfiguration currentRuleConfig, final AlterSQLTranslatorRuleStatement sqlStatement) {
checkProvider(sqlStatement);
}

private void checkProvider(final AlterSQLTranslatorRuleStatement sqlStatement) {
TypedSPILoader.checkService(SQLTranslator.class, sqlStatement.getType(), sqlStatement.getProps());
}

@Override
public SQLTranslatorRuleConfiguration buildAlteredRuleConfiguration(final SQLTranslatorRuleConfiguration currentRuleConfig, final AlterSQLTranslatorRuleStatement sqlStatement) {
return new SQLTranslatorRuleConfiguration(sqlStatement.getType(), sqlStatement.getProps(),
null == sqlStatement.getUseOriginalSQLWhenTranslatingFailed() ? currentRuleConfig.isUseOriginalSQLWhenTranslatingFailed() : sqlStatement.getUseOriginalSQLWhenTranslatingFailed());
}

@Override
public Class<SQLTranslatorRuleConfiguration> getRuleConfigurationClass() {
return SQLTranslatorRuleConfiguration.class;
}

@Override
public Class<AlterSQLTranslatorRuleStatement> getType() {
return AlterSQLTranslatorRuleStatement.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# limitations under the License.
#

org.apache.shardingsphere.sqltranslator.distsql.handler.ShowSQLTranslatorRuleExecutor
org.apache.shardingsphere.sqltranslator.distsql.handler.query.ShowSQLTranslatorRuleExecutor
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.sqltranslator.distsql.handler.update.AlterSQLTranslatorRuleStatementUpdater
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
* limitations under the License.
*/

package org.apache.shardingsphere.sqltranslator.distsql.handler;
package org.apache.shardingsphere.sqltranslator.distsql.handler.query;

import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.sqltranslator.api.config.SQLTranslatorRuleConfiguration;
import org.apache.shardingsphere.sqltranslator.distsql.statement.ShowSQLTranslatorRuleStatement;
import org.apache.shardingsphere.sqltranslator.distsql.statement.queryable.ShowSQLTranslatorRuleStatement;
import org.apache.shardingsphere.sqltranslator.rule.SQLTranslatorRule;
import org.junit.jupiter.api.Test;

Expand All @@ -49,16 +49,18 @@ void assertExecute() {
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
LocalDataQueryResultRow row = iterator.next();
assertThat(row.getCell(1), is("NATIVE"));
assertThat(row.getCell(2), is("true"));
assertThat(row.getCell(2), is(""));
assertThat(row.getCell(3), is("true"));
}

@Test
void assertGetColumnNames() {
ShowSQLTranslatorRuleExecutor executor = new ShowSQLTranslatorRuleExecutor();
Collection<String> columns = executor.getColumnNames();
assertThat(columns.size(), is(2));
assertThat(columns.size(), is(3));
Iterator<String> iterator = columns.iterator();
assertThat(iterator.next(), is("type"));
assertThat(iterator.next(), is("props"));
assertThat(iterator.next(), is("use_original_sql_when_translating_failed"));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.sqltranslator.distsql.handler.update;

import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.sqltranslator.api.config.SQLTranslatorRuleConfiguration;
import org.apache.shardingsphere.sqltranslator.distsql.statement.updateable.AlterSQLTranslatorRuleStatement;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.Test;

import java.util.Properties;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class AlterSQLTranslatorRuleStatementUpdaterTest {

@Test
void assertExecute() {
AlterSQLTranslatorRuleStatementUpdater updater = new AlterSQLTranslatorRuleStatementUpdater();
SQLTranslatorRuleConfiguration actual = updater.buildAlteredRuleConfiguration(createSQLTranslatorRuleConfiguration(), new AlterSQLTranslatorRuleStatement("JOOQ",
PropertiesBuilder.build(new Property("foo", "bar")), null));
assertThat(actual.getType(), is("JOOQ"));
assertFalse(actual.getProps().isEmpty());
String props = PropertiesConverter.convert(actual.getProps());
assertThat(props, is("{\"foo\":\"bar\"}"));
assertTrue(actual.isUseOriginalSQLWhenTranslatingFailed());
}

private SQLTranslatorRuleConfiguration createSQLTranslatorRuleConfiguration() {
return new SQLTranslatorRuleConfiguration("NATIVE", new Properties(), true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.
*/

grammar BaseRule;

import Symbol, Keyword, Literals;

propertiesDefinition
: PROPERTIES LP_ properties? RP_
;

properties
: property (COMMA_ property)*
;

property
: key=STRING_ EQ_ value=literal
;

literal
: STRING_ | (MINUS_)? INT_ | TRUE | FALSE
;
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,39 @@ RULE
SQL_TRANSLATOR
: S Q L UL_ T R A N S L A T O R
;

USE_ORIGINAL_SQL_WHEN_TRANSLATING_FAILED
: U S E UL_ O R I G I N A L UL_ S Q L UL_ W H E N UL_ T R A N S L A T I N G UL_ F A I L E D
;

ALTER
: A L T E R
;

TYPE
: T Y P E
;

JOOQ
: J O O Q
;

NATIVE
: N A T I V E
;

NAME
: N A M E
;

PROPERTIES
: P R O P E R T I E S
;

TRUE
: T R U E
;

FALSE
: F A L S E
;
Loading

0 comments on commit 09fbb09

Please sign in to comment.