<commit_before>------------------------------------
-- Inserts Job entity into Job table
------------------------------------
Create or replace FUNCTION InsertJob(
    v_job_id UUID,
    v_action_type VARCHAR(50),
    v_description TEXT,
    v_status VARCHAR(32),
    v_owner_id UUID,
    v_visible BOOLEAN,
    v_start_time TIMESTAMP WITH TIME ZONE,
    v_end_time TIMESTAMP WITH TIME ZONE,
    v_last_update_time TIMESTAMP WITH TIME ZONE,
    v_correlation_id VARCHAR(50))
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO job(
        job_id,
        action_type,
        description,
        status,
        owner_id,
        visible,
        start_time,
        end_time,
        last_update_time,
        correlation_id)
    VALUES (
        v_job_id,
        v_action_type,
        v_description,
        v_status,
        v_owner_id,
        v_visible,
        v_start_time,
        v_end_time,
        v_last_update_time,
        v_correlation_id);
END; $procedure$
LANGUAGE plpgsql;

----------------------------------------------------
-- Retrieves Job entity by its job-id from Job table
----------------------------------------------------
Create or replace FUNCTION GetJobByJobId(v_job_id UUID)
RETURNS SETOF job
AS $procedure$
BEGIN
    RETURN QUERY SELECT job.*
    FROM JOB
    WHERE job_id = v_job_id;
END; $procedure$
LANGUAGE plpgsql;

--------------------------------------------
-- Retrieves All Job entitise from Job table
--------------------------------------------
Create or replace FUNCTION GetAllJobs()
RETURNS SETOF job
AS $procedure$
BEGIN
    RETURN QUERY SELECT job.*
    FROM JOB;
END; $procedure$
LANGUAGE plpgsql;

-----------------------------------------------------
-- Retrieves All Job entities by offset and page size
-----------------------------------------------------
Create or replace FUNCTION GetJobsByOffsetAndPageSize(v_position INTEGER, v_page_size INTEGER)
RETURNS SETOF job
AS $procedure$
BEGIN
    RETURN QUERY
    (SELECT job.*
    FROM JOB
    WHERE status = 'STARTED'
    ORDER BY last_update_time desc)
    UNION ALL
    (SELECT job.*
    FROM JOB
    WHERE status != 'STARTED'
    ORDER BY last_update_time desc)
    OFFSET v_position LIMIT v_page_size;
END; $procedure$
LANGUAGE plpgsql;

-----------------------------------------------
-- Retrieves All Job entities by Correlation-ID
-----------------------------------------------
Create or replace FUNCTION GetJobsByCorrelationId(v_correlation_id VARCHAR(50))
RETURNS SETOF job
AS $procedure$
BEGIN
    RETURN QUERY SELECT job.*
    FROM JOB
    WHERE correlation_id = v_correlation_id;
END; $procedure$
LANGUAGE plpgsql;

----------------------------------
-- Updates Job entity in Job table
----------------------------------<commit_msg>core:remove single unknown tasks from the task(817817)<commit_after>------------------------------------
-- Inserts Job entity into Job table
------------------------------------
Create or replace FUNCTION InsertJob(
    v_job_id UUID,
    v_action_type VARCHAR(50),
    v_description TEXT,
    v_status VARCHAR(32),
    v_owner_id UUID,
    v_visible BOOLEAN,
    v_start_time TIMESTAMP WITH TIME ZONE,
    v_end_time TIMESTAMP WITH TIME ZONE,
    v_last_update_time TIMESTAMP WITH TIME ZONE,
    v_correlation_id VARCHAR(50))
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO job(
        job_id,
        action_type,
        description,
        status,
        owner_id,
        visible,
        start_time,
        end_time,
        last_update_time,
        correlation_id)
    VALUES (
        v_job_id,
        v_action_type,
        v_description,
        v_status,
        v_owner_id,
        v_visible,
        v_start_time,
        v_end_time,
        v_last_update_time,
        v_correlation_id);
END; $procedure$
LANGUAGE plpgsql;

----------------------------------------------------
-- Retrieves Job entity by its job-id from Job table
----------------------------------------------------
Create or replace FUNCTION GetJobByJobId(v_job_id UUID)
RETURNS SETOF job
AS $procedure$
BEGIN
    RETURN QUERY SELECT job.*
    FROM JOB
    WHERE job_id = v_job_id;
END; $procedure$
LANGUAGE plpgsql;

--------------------------------------------
-- Retrieves All Job entitise from Job table
--------------------------------------------
Create or replace FUNCTION GetAllJobs()
RETURNS SETOF job
AS $procedure$
BEGIN
    RETURN QUERY SELECT job.*
    FROM JOB
    where status != 'UNKNOWN';
END; $procedure$
LANGUAGE plpgsql;

-----------------------------------------------------
-- Retrieves All Job entities by offset and page size
-----------------------------------------------------
Create or replace FUNCTION GetJobsByOffsetAndPageSize(v_position INTEGER, v_page_size INTEGER)
RETURNS SETOF job
AS $procedure$
BEGIN
    RETURN QUERY
    (SELECT job.*
    FROM JOB
    WHERE status = 'STARTED'
    ORDER BY last_update_time desc)
    UNION ALL
    (SELECT job.*
    FROM JOB
    WHERE status not in ('STARTED','UNKNOWN')
    ORDER BY last_update_time desc)
    OFFSET v_position LIMIT v_page_size;
END; $procedure$
LANGUAGE plpgsql;

-----------------------------------------------
-- Retrieves All Job entities by Correlation-ID
-----------------------------------------------
Create or replace FUNCTION GetJobsByCorrelationId(v_correlation_id VARCHAR(50))
RETURNS SETOF job
AS $procedure$
BEGIN
    RETURN QUERY SELECT job.*
    FROM JOB
    WHERE correlation_id = v_correlation_id;
END; $procedure$
LANGUAGE plpgsql;

----------------------------------
-- Updates Job entity in Job table
----------------------------------
{'fraction_non_alphanumeric': 0.2369787005548595, 'fraction_numerical': 0.00393771254698407, 'mean_word_length': 1.5423111919927206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7302890', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1522, 'n_words': 471}