from const.datasources import RESOURCE_NOT_FOUND_STATUS_CODE from logic import query_execution as logic, datadoc as datadoc_logic, user as user_logic from logic.datadoc_permission import user_can_read from logic.query_execution_permission import ( get_default_user_environment_by_execution_id, ) from lib.config import get_config_value from tasks.export_query_execution import export_query_execution_task from tasks.run_query import run_query_task from app.auth.permission import verify_query_execution_owner from models.query_execution import QueryExecutionViewer from models.access_request import AccessRequest from app.db import with_session from env import QuerybookSettings from lib.notify.utils import notify_user QUERY_RESULT_LIMIT_CONFIG = get_config_value("query_result_limit") @register("/query_execution/", methods=["POST"]) def create_query_execution(query, engine_id, data_cell_id=None, originator=None): with DBSession() as session: verify_query_engine_permission(engine_id, session=session) uid = current_user.id query_execution = logic.create_query_execution(query=query, engine_id=engine_id, uid=uid, session=session)
import sys import os import json from lib.config import get_config_value in_test = hasattr(sys, "_called_from_test") querybook_config = get_config_value("querybook_config", {}) querybook_default_config = get_config_value("querybook_default_config", {}) class MissingConfigException(Exception): pass def get_env_config(name, optional=True): found = True val = None if name in os.environ: val = os.environ.get(name) elif name in querybook_config: val = querybook_config.get(name) elif name in querybook_default_config: val = querybook_default_config.get(name) found = val is not None else: found = False # We treat empty string as None as well if not found and not optional and not in_test: raise MissingConfigException(
from sqlalchemy import func from app.db import with_session from lib.config import get_config_value from lib.logger import get_logger from const.user_roles import UserRoleType from const.elasticsearch import ElasticsearchItem from models.user import ( User, UserSetting, UserRole, ) from tasks.sync_elasticsearch import sync_elasticsearch LOG = get_logger(__file__) user_settings_config = get_config_value("user_setting") """ ---------------------------------------------------------------------------------------------------------- USER --------------------------------------------------------------------------------------------------------- """ @with_session def get_user_by_id(id, session=None): return User.get(id=id, session=session) @with_session def get_users_by_ids(ids, session=None): return session.query(User).filter(User.id.in_(ids)).all()
from lib.sqlalchemy import update_model_fields from models.datadoc import ( DataDoc, DataDocDataCell, DataCell, DataCellQueryExecution, QuerySnippet, FavoriteDataDoc, FunctionDocumentation, DataDocEditor, ) from models.access_request import AccessRequest from models.impression import Impression from tasks.sync_elasticsearch import sync_elasticsearch cell_types = get_config_value("datadoc.cell_types") """ ---------------------------------------------------------------------------------------------------------- DATA DOC --------------------------------------------------------------------------------------------------------- """ @with_session def create_data_doc( environment_id, owner_uid, cells=[], public=None, archived=None, title=None,
get_data_doc_editors_by_doc_id, ) from logic.metastore import ( get_all_table, get_table_by_id, get_table_query_samples_count, ) from logic.impression import ( get_viewers_count_by_item_after_date, get_last_impressions_date, ) from models.user import User from models.datadoc import DataCellType LOG = get_logger(__file__) ES_CONFIG = get_config_value("elasticsearch") @in_mem_memoized(3600) def get_hosted_es(): hosted_es = None if ":" in QuerybookSettings.ELASTICSEARCH_HOST: host, port = QuerybookSettings.ELASTICSEARCH_HOST.split(":") else: host = QuerybookSettings.ELASTICSEARCH_HOST port = 9200 # Default port for elasticsearch if QuerybookSettings.ELASTICSEARCH_CONNECTION_TYPE == "naive": hosted_es = Elasticsearch( hosts=[host],