GitHub user lucean created a discussion: Registering new SQLValidator
implementations
I am attempting to register a SQLValidator implementation (with some custom
rules) in my Superset v5.0.0 deployment, but I've come up against an issue with
the implementation of ValidateSQLCommand (or perhaps a limit of my
understanding of this feature).
I've updated the configuration for the `SQL_VALIDATORS_BY_ENGINE` dict in my
superset_config.py file to include a reference for my engine:
`
# Configure which SQL validator to use for each engine
SQL_VALIDATORS_BY_ENGINE = {
"presto": "PrestoDBSQLValidator",
"postgresql": "PostgreSQLValidator",
"mysql": "MySQLValidator",
}
`
However, the code which resolves this SQL Validator name is in
superset/sql_validators/__init__.py, with a hardcoded reference to the
implementations provided by Superset (for Presto and PostgreSQL):
`
def get_validator_by_name(name: str) -> Optional[type[base.BaseSQLValidator]]:
return {
"PrestoDBSQLValidator": presto_db.PrestoDBSQLValidator,
"PostgreSQLValidator": postgres.PostgreSQLValidator,
}.get(name)
`
The function defined in this file (get_validator_by_name) is then used by the
ValidateSQLCommand to run the validation implementation. I have an
implementation for MySQLValidator (extending BaseSQLValidator)
Have I misunderstood the intended mechanism for bringing your own SQLValidator
implementations? It seems that there's no way to do this at the moment without
modifying the behaviour of the get_validator_by_name function. Ideally, I'd be
able to affect this through modifying the configuration only - maybe something
like:
**superset/sql_validators/__init__.py**
`
def get_validator_by_name(name: str) -> Optional[type[base.BaseSQLValidator]]:
provided_implementations = {
"PrestoDBSQLValidator": presto_db.PrestoDBSQLValidator,
"PostgreSQLValidator": postgres.PostgreSQLValidator,
}
return { **provided_implementations, **SQL_VALIDATORS_BY_NAME }.get(name)
`
and
**superset/config.py**
`
# A mapping from the named SQLValidator implementations and the
# classes which provide the validation. Implementations are provided
# for the PrestoDBSQLValidator and PostgreSQLValidator in the
# sql_validators module
SQL_VALIDATORS_BY_NAME = {}
`
GitHub link: https://github.com/apache/superset/discussions/35638
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]