Translator¶
The translator turns a SQL string into a Redis FT.SEARCH or FT.AGGREGATE
command. It does not execute anything; use Executor
for that.
Translator¶
Translator
¶
Translator(
schema_registry: SchemaRegistry | AsyncSchemaRegistry,
)
Translates SQL queries to Redis FT.SEARCH/FT.AGGREGATE commands.
Initialize translator with schema registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema_registry
|
SchemaRegistry | AsyncSchemaRegistry
|
Registry containing index schemas. Can be either sync (SchemaRegistry) or async (AsyncSchemaRegistry) - only the sync get_schema() method is used. |
required |
Source code in sql_redis/translator.py
parse
¶
Parse a SQL SELECT into a ParsedQuery AST.
Useful when callers need the parsed result before translation (e.g., to extract the index name for async schema loading).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sql
|
str
|
SQL SELECT statement. |
required |
Returns:
| Type | Description |
|---|---|
ParsedQuery
|
ParsedQuery with extracted index, fields, conditions, etc. |
Source code in sql_redis/translator.py
translate
¶
translate(sql: str) -> TranslatedQuery
Translate a SQL SELECT into a Redis search command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sql
|
str
|
SQL SELECT statement. |
required |
Returns:
| Type | Description |
|---|---|
TranslatedQuery
|
TranslatedQuery with command details. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If SQL is invalid or references unknown index/fields. |
Source code in sql_redis/translator.py
translate_parsed
¶
translate_parsed(parsed: ParsedQuery) -> TranslatedQuery
Translate a pre-parsed query into a Redis search command.
This avoids re-parsing SQL when the caller has already parsed it (e.g., AsyncExecutor extracts the index name before translation).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parsed
|
ParsedQuery
|
A ParsedQuery from SQLParser.parse(). |
required |
Returns:
| Type | Description |
|---|---|
TranslatedQuery
|
TranslatedQuery with command details. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the index or a field is unknown. |