from lib.utils.plugin import import_plugin
from .base_executor import parse_exception

from .executors.hive import HiveQueryExecutor
from .executors.presto import PrestoQueryExecutor
from .executors.sqlalchemy import (
    MysqlQueryExecutor,
    DruidQueryExecutor,
    SqliteQueryExecutor,
    SnowflakeQueryExecutor,
)
from .executors.bigquery import BigQueryQueryExecutor


ALL_PLUGIN_EXECUTORS = import_plugin("executor_plugin", "ALL_PLUGIN_EXECUTORS", [])


ALL_EXECUTORS = [
    HiveQueryExecutor,
    PrestoQueryExecutor,
    MysqlQueryExecutor,
    DruidQueryExecutor,
    SqliteQueryExecutor,
    BigQueryQueryExecutor,
    SnowflakeQueryExecutor,
] + ALL_PLUGIN_EXECUTORS


def get_executor_class(language: str, name: str):
    for executor in ALL_EXECUTORS:
        if (
            executor.EXECUTOR_LANGUAGE() == language
            and executor.EXECUTOR_NAME() == name
        ):
            return executor

    raise ValueError(f"Unknown executor {name} with language {language}")


# Re-export parse_exception
parse_exception

[((15, 23, 15, 83), 'lib.utils.plugin.import_plugin', 'import_plugin', ({(15, 37, 15, 54): '"""executor_plugin"""', (15, 56, 15, 78): '"""ALL_PLUGIN_EXECUTORS"""', (15, 80, 15, 82): '[]'}, {}), "('executor_plugin', 'ALL_PLUGIN_EXECUTORS', [])", False, 'from lib.utils.plugin import import_plugin\n')]