def _generate_udf_statements( command_id: str, context_id: str, func_name: str, positional_args: List[UDFArgument], keyword_args: Dict[str, UDFArgument], ): allowed_func_name = func_name.replace(".", "_") # A dot is not an allowed character udf_name = _create_udf_name(allowed_func_name, command_id, context_id) result_table_name = create_table_name( "table", command_id, context_id, node_config.identifier ) gen_pos_args, gen_kw_args = _convert_udf2udfgen_args(positional_args, keyword_args) udf_creation_stmt, udf_execution_stmt = generate_udf_application_queries( func_name, gen_pos_args, gen_kw_args ) udf_creation_stmt = udf_creation_stmt.substitute(udf_name=udf_name) udf_execution_stmt = udf_execution_stmt.substitute( table_name=result_table_name, udf_name=udf_name, node_id=node_config.identifier, ) return udf_creation_stmt, udf_execution_stmt, result_table_name
def create_view( context_id: str, command_id: str, table_name: str, columns: List[str], filters_json: str, ) -> str: """ Creates a view of a table with specific columns and filters to the DB. Parameters ---------- context_id : str The id of the experiment command_id : str The id of the command that the view table_name : str The name of the table columns : List[str] A list of column names filters_json : str(dict) A Jquery filters object Returns ------ str The name of the created view """ view_name = create_table_name("view", command_id, context_id, node_config.identifier) views.create_view(view_name=view_name, table_name=table_name, columns=columns) return view_name
def create_merge_table(context_id: str, command_id: str, table_names: List[str]) -> str: """ Parameters ---------- context_id : str The id of the experiment command_id : str The id of the command that the merge table table_names: List[str] Its a list of names of the tables to be merged Returns ------ str The name(string) of the created merge table in lower case. """ validate_tables_can_be_merged(table_names) schema = common_actions.get_table_schema(table_names[0]) merge_table_name = create_table_name("merge", command_id, context_id, node_config.identifier) table_info = TableInfo(merge_table_name, schema) merge_tables.create_merge_table(table_info) merge_tables.add_to_merge_table(merge_table_name, table_names) return merge_table_name
def create_pathology_view( context_id: str, command_id: str, pathology: str, datasets: List[str], columns: List[str], filters_json: str, ) -> str: # TODO We need to add the filters """ Creates a MIP specific view of a pathology with specific columns, filters and datasets to the DB. Parameters ---------- context_id : str The id of the experiment command_id : str The id of the command that the view pathology : str The pathology data table on which the view will be created datasets : List[str] A list of dataset names columns : List[str] A list of column names filters_json : str(dict) A Jquery filters object Returns ------ str The name of the created view """ view_name = create_table_name("view", command_id, context_id, node_config.identifier) columns.insert(0, DATA_TABLE_PRIMARY_KEY) views.create_view( view_name=view_name, table_name=f"{pathology}_data", columns=columns, datasets=datasets, ) return view_name
def create_table(context_id: str, command_id: str, schema_json: str) -> str: """ Parameters ---------- context_id : str The id of the experiment command_id : str The id of the command that the table schema_json : str(TableSchema) A TableSchema object in a jsonified format Returns ------ str The name of the created table in lower case """ schema_object = TableSchema.from_json(schema_json) table_name = create_table_name( "table", command_id, context_id, node_config.identifier ) table_info = TableInfo(table_name, schema_object) tables.create_table(table_info) return table_name