Example #1
0
def export_statement_execution_result(statement_execution_id,
                                      exporter_name,
                                      exporter_params=None):
    with DBSession() as session:
        statement_execution = logic.get_statement_execution_by_id(
            statement_execution_id, session=session)
        api_assert(statement_execution is not None,
                   message="Invalid statement execution")
        verify_query_execution_permission(
            statement_execution.query_execution_id, session=session)

    exporter = get_exporter(exporter_name)
    api_assert(exporter is not None, f"Invalid export name {exporter_name}")

    if exporter_params:
        valid, reason = validate_form(exporter.export_form, exporter_params)
        api_assert(valid, "Invalid exporter params, reason: " + reason)

    task = export_query_execution_task.apply_async(args=[
        exporter.exporter_name,
        statement_execution_id,
        current_user.id,
        exporter_params or {},
    ], )

    return task.task_id
Example #2
0
def _export_query_cell(cell_id, uid, cell_exports, session=None):
    statement_execution_id = None

    query_execution = get_last_query_execution_from_cell(cell_id,
                                                         session=session)
    if not query_execution or query_execution.status != QueryExecutionStatus.DONE:
        return [query_execution.status]
    statement_execution_id = query_execution.statement_executions[-1].id

    export_urls = []
    for export in cell_exports:
        exporter_name = export["exporter_name"]
        exporter_params = export.get("exporter_params", {})

        exporter = get_exporter(exporter_name)
        export_urls.append(
            exporter.export(statement_execution_id, uid, **exporter_params))
    return export_urls
Example #3
0
def export_query_execution_task(
    self,
    exporter_name: str,
    statement_execution_id: int,
    current_user_id: int,
    exporter_params: Dict,
):
    exporter = get_exporter(exporter_name)
    try:
        info = exporter.export(statement_execution_id, current_user_id,
                               **(exporter_params or {}))
        return {
            "type": exporter.exporter_type,
            "info": info,
        }
    except Exception as e:
        LOG.error(e)
        raise e
Example #4
0
def export_statement_execution_acquire_auth(exporter_name):
    exporter = get_exporter(exporter_name)
    api_assert(exporter is not None, f"Invalid exporter name {exporter_name}")
    if not exporter.requires_auth:
        return None
    return exporter.acquire_auth(current_user.id)
Example #5
0
def _get_exporter(export_config):
    exporter_name = export_config.get("exporter_name", None)
    try:
        return get_exporter(exporter_name)
    except ValueError:
        raise InvalidScheduleException(f"Invalid exporter {exporter_name}")