Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Apache Shardingsphere ColumnShadowAlgorithm SPI

From Leeroopedia


Knowledge Sources
Domains Shadow_Testing, SPI, SQL_Routing
Last Updated 2026-02-10 00:00 GMT

Overview

SPI interface for column-value-based shadow routing algorithms.

Description

ColumnShadowAlgorithm<T> is a generic interface extending ShadowAlgorithm that defines the contract for shadow algorithms based on column values in SQL statements. Implementors decide whether a SQL statement targets a shadow data source by examining the value of a designated shadow column.

Usage

Implement this interface when creating shadow algorithms that route based on column values (e.g., a shadow_flag column in INSERT/UPDATE/SELECT/DELETE statements).

Code Reference

Source Location

Signature

public interface ColumnShadowAlgorithm<T> extends ShadowAlgorithm {

    boolean isShadow(Collection<String> shadowTableNames, PreciseColumnShadowValue<T> shadowValue);

    String getShadowColumn();

    ShadowOperationType getShadowOperationType();
}

Import

import org.apache.shardingsphere.shadow.spi.column.ColumnShadowAlgorithm;

I/O Contract

Inputs

Name Type Required Description
shadowTableNames Collection<String> Yes Names of configured shadow tables
shadowValue PreciseColumnShadowValue<T> Yes Column value context including table name, operation type, column name, and value

Outputs

Name Type Description
isShadow() returns boolean True if the statement should route to shadow data source
getShadowColumn() returns String The column name used for shadow determination
getShadowOperationType() returns ShadowOperationType The SQL operation type this algorithm handles

Usage Examples

import org.apache.shardingsphere.shadow.spi.column.ColumnShadowAlgorithm;
import org.apache.shardingsphere.shadow.spi.column.PreciseColumnShadowValue;
import org.apache.shardingsphere.shadow.spi.ShadowOperationType;

public final class ColumnValueMatchedShadowAlgorithm implements ColumnShadowAlgorithm<Comparable<?>> {

    @Override
    public boolean isShadow(final Collection<String> shadowTableNames,
                            final PreciseColumnShadowValue<Comparable<?>> shadowValue) {
        return shadowTableNames.contains(shadowValue.getTableName())
                && getShadowOperationType() == shadowValue.getShadowOperationType()
                && getShadowColumn().equals(shadowValue.getColumnName())
                && matchesValue(shadowValue.getValue());
    }

    @Override
    public String getShadowColumn() {
        return "shadow_flag";
    }

    @Override
    public ShadowOperationType getShadowOperationType() {
        return ShadowOperationType.INSERT;
    }

    private boolean matchesValue(final Comparable<?> value) {
        return "1".equals(String.valueOf(value));
    }
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment