def search_query_snippet(environment_id, engine_id=None, is_public=False, golden=None):
    search_by = current_user.id

    with DBSession() as session:
        # TODO: Check if engine_id is under environment_id
        verify_environment_permission([environment_id])
        engine_ids = (
            [engine_id]
            if engine_id is not None
            else list(
                map(
                    lambda e: e.id,
                    admin_logic.get_query_engines_by_environment(environment_id),
                )
            )
        )

        query_snippets = logic.search_snippet(
            search_by=search_by,
            engine_ids=engine_ids,
            is_public=is_public,
            golden=golden,
            session=session,
        )

        query_snippet_dicts = [
            dict(id=snippet[0], title=snippet[1]) for snippet in query_snippets
        ]

        return query_snippet_dicts
Beispiel #2
0
def get_table_query_examples(
    table_id,
    environment_id,
    uid=None,
    engine_id=None,
    with_table_id=None,
    limit=10,
    offset=0,
):
    api_assert(limit < 100)

    with DBSession() as session:
        verify_environment_permission([environment_id])
        verify_data_table_permission(table_id, session=session)
        engines = admin_logic.get_query_engines_by_environment(environment_id,
                                                               session=session)
        engine_ids = [engine.id for engine in engines]
        api_assert(engine_id is None or engine_id in engine_ids,
                   "Invalid engine id")
        query_logs = logic.get_table_query_examples(
            table_id,
            engine_ids,
            uid=uid,
            engine_id=engine_id,
            with_table_id=with_table_id,
            limit=limit,
            offset=offset,
            session=session,
        )
        query_ids = [log.query_execution_id for log in query_logs]

        return query_ids
Beispiel #3
0
def get_table_query_examples_users(table_id, environment_id, limit=5):
    api_assert(limit <= 10)
    verify_environment_permission([environment_id])
    verify_data_table_permission(table_id)
    engines = admin_logic.get_query_engines_by_environment(environment_id)
    engine_ids = [engine.id for engine in engines]
    users = logic.get_query_example_users(table_id, engine_ids, limit=limit)

    return [{"uid": r[0], "count": r[1]} for r in users]
Beispiel #4
0
def get_query_engines(environment_id):
    verify_environment_permission([environment_id])
    return admin_logic.get_query_engines_by_environment(environment_id,
                                                        ordered=True)
Beispiel #5
0
def get_query_engine_in_environment(id):
    return logic.get_query_engines_by_environment(id, ordered=True)