Skip to content

Commit

Permalink
Refactor ColumnShadowAlgorithmDeterminer (#33558)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Nov 5, 2024
1 parent 472dc42 commit 5e8dbbc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
@Getter
public final class PreciseColumnShadowValue<T extends Comparable<?>> implements ShadowValue {

private final String logicTableName;
private final String tableName;

private final ShadowOperationType shadowOperationType;
private final ShadowOperationType operationType;

private final String columnName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ private ShadowOperationType getShadowOperationType(final Properties props) {

@Override
public final boolean isShadow(final PreciseColumnShadowValue<Comparable<?>> shadowValue) {
String table = shadowValue.getLogicTableName();
String table = shadowValue.getTableName();
String column = shadowValue.getColumnName();
Comparable<?> value = shadowValue.getValue();
if (shadowOperationType == shadowValue.getShadowOperationType() && shadowColumn.equals(column)) {
if (shadowOperationType == shadowValue.getOperationType() && shadowColumn.equals(column)) {
ColumnShadowValueValidator.validate(table, column, value);
return matchesShadowValue(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.shadow.condition.ShadowCondition;
import org.apache.shardingsphere.shadow.spi.ShadowOperationType;
import org.apache.shardingsphere.shadow.spi.column.ColumnShadowAlgorithm;
import org.apache.shardingsphere.shadow.spi.column.PreciseColumnShadowValue;
import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition;

import java.util.Collection;
import java.util.LinkedList;
Expand All @@ -44,22 +42,18 @@ public final class ColumnShadowAlgorithmDeterminer {
* @return is shadow or not
*/
public static boolean isShadow(final ColumnShadowAlgorithm<Comparable<?>> shadowAlgorithm, final ShadowCondition shadowCondition) {
ShadowColumnCondition shadowColumnCondition = shadowCondition.getColumnCondition();
String tableName = shadowCondition.getTableName();
ShadowOperationType operationType = shadowCondition.getOperationType();
for (PreciseColumnShadowValue<Comparable<?>> each : createColumnShadowValues(shadowColumnCondition.getColumn(), shadowColumnCondition.getValues(), tableName, operationType)) {
if (!tableName.equals(shadowColumnCondition.getOwner()) || !shadowAlgorithm.isShadow(each)) {
for (PreciseColumnShadowValue<Comparable<?>> each : createColumnShadowValues(shadowCondition)) {
if (!shadowCondition.getTableName().equals(shadowCondition.getColumnCondition().getOwner()) || !shadowAlgorithm.isShadow(each)) {
return false;
}
}
return true;
}

private static Collection<PreciseColumnShadowValue<Comparable<?>>> createColumnShadowValues(final String columnName, final Collection<Comparable<?>> columnValues, final String tableName,
final ShadowOperationType operationType) {
private static Collection<PreciseColumnShadowValue<Comparable<?>>> createColumnShadowValues(final ShadowCondition shadowCondition) {
Collection<PreciseColumnShadowValue<Comparable<?>>> result = new LinkedList<>();
for (Comparable<?> each : columnValues) {
result.add(new PreciseColumnShadowValue<>(tableName, operationType, columnName, each));
for (Comparable<?> each : shadowCondition.getColumnCondition().getValues()) {
result.add(new PreciseColumnShadowValue<>(shadowCondition.getTableName(), shadowCondition.getOperationType(), shadowCondition.getColumnCondition().getColumn(), each));
}
return result;
}
Expand Down

0 comments on commit 5e8dbbc

Please sign in to comment.