Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InlineShardingAlgorithm add property LogicTableName #5710

Closed
wangjing112 opened this issue May 20, 2020 · 1 comment
Closed

InlineShardingAlgorithm add property LogicTableName #5710

wangjing112 opened this issue May 20, 2020 · 1 comment

Comments

@wangjing112
Copy link

wangjing112 commented May 20, 2020

in most time table's sharding rule is same like:

`
defaultTableStrategy:
standard:
shardingColumn: id
shardingAlgorithm:
type: INLINE
props:
algorithm.expression: ${LogicTableName}${id % 2}

`

so if algorithm.expression include LogicTableName ,most of table can use defaultTableStrategy

just add code in InlineShardingAlgorithm like this:
`

@Override
public String doSharding(final Collection<String> availableTargetNames, final PreciseShardingValue<Comparable<?>> shardingValue) {
    Preconditions.checkNotNull(properties.get(ALGORITHM_EXPRESSION), "Inline sharding algorithm expression cannot be null.");
    String algorithmExpression = InlineExpressionParser.handlePlaceHolder(properties.get(ALGORITHM_EXPRESSION).toString().trim());
    Closure<?> closure = new InlineExpressionParser(algorithmExpression).evaluateClosure();
    Closure<?> result = closure.rehydrate(new Expando(), null, null);
    result.setResolveStrategy(Closure.DELEGATE_ONLY);
    result.setProperty(shardingValue.getColumnName(), shardingValue.getValue());
    result.setProperty("LogicTableName", shardingValue.getLogicTableName());
    return result.call().toString();
}

`

@kimmking
Copy link
Member

Thanks for your suggestion, but IMO it's unneccessary now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants