Implementation:Apache Shardingsphere HintShadowAlgorithm SPI
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Shadow_Testing, SPI, SQL_Routing |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
SPI interface for hint-based shadow routing algorithms.
Description
HintShadowAlgorithm<T> is a generic interface extending ShadowAlgorithm that defines the contract for shadow algorithms based on SQL hints rather than column values. Implementors determine shadow routing by examining hint annotations attached to SQL statements.
Usage
Implement this interface when creating shadow algorithms that use SQL hint annotations (e.g., /* shadow:true */ comments) rather than column values for routing decisions.
Code Reference
Source Location
- Repository: Apache_Shardingsphere
- File: features/shadow/api/src/main/java/org/apache/shardingsphere/shadow/spi/hint/HintShadowAlgorithm.java
- Lines: 1-39
Signature
public interface HintShadowAlgorithm<T> extends ShadowAlgorithm {
boolean isShadow(Collection<String> shadowTableNames, PreciseHintShadowValue<T> shadowValue);
}
Import
import org.apache.shardingsphere.shadow.spi.hint.HintShadowAlgorithm;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| shadowTableNames | Collection<String> | Yes | Names of configured shadow tables |
| shadowValue | PreciseHintShadowValue<T> | Yes | Hint value context including table name, operation type, and hint value |
Outputs
| Name | Type | Description |
|---|---|---|
| isShadow() returns | boolean | True if the statement should route to shadow data source |
Usage Examples
import org.apache.shardingsphere.shadow.spi.hint.HintShadowAlgorithm;
import org.apache.shardingsphere.shadow.spi.hint.PreciseHintShadowValue;
public final class SQLHintShadowAlgorithm implements HintShadowAlgorithm<String> {
@Override
public boolean isShadow(final Collection<String> shadowTableNames,
final PreciseHintShadowValue<String> shadowValue) {
return "true".equalsIgnoreCase(shadowValue.getValue());
}
@Override
public String getType() {
return "SQL_HINT";
}
}
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment