База данных нашего проекта находится в Google Cloud
(PostgreSQL
), и я пытаюсь запланировать хранимую процедуру в BigQuery
. Я создал запланированное задание для запуска хранимой процедуры, которая выполняется ежечасно, но завершается с ошибкой:
Подпрограмма с именем "automadashboardsteps_New" отсутствует набор данных, но нет набора данных по умолчанию.
В моей хранимой процедуре есть только операторы DDL и DML. Даже после создания набора данных я повторяю ту же ошибку.
Может кто-нибудь помочь?
Вот так выглядит мой ИП:
-- PROCEDURE: public.automationdashboardhr()
-- DROP PROCEDURE public.automationdashboardhr();
CREATE OR REPLACE PROCEDURE public.automationdashboardhr(
)
LANGUAGE 'plpgsql'
AS $BODY$
BEGIN
CREATE TEMP TABLE HRTempLogs(GroupId INT, Date VARCHAR(28), ProcessName VARCHAR(128),
BotName VARCHAR(128), Status VARCHAR(28), StartTime VARCHAR(28), EndTime VARCHAR(28),
Exception VARCHAR(6), StartedCount INT, EndedCount INT, TotalProcess INT, InfoCount INT,
Cycle INT, Duration VARCHAR(62), Errors INT, Warnings INT, PaycomReportsDownloaded INT,
FilesImported INT, ReportsExported INT);
INSERT INTO HRTempLogs(GroupId, StartTime, EndTime, StartedCount, EndedCount, TotalProcess, InfoCount, Errors, Warnings, PaycomReportsDownloaded, FilesImported, ReportsExported)
SELECT LG.GroupId,
(SELECT MIN(ExecutionTimeStamp) FROM logging WHERE GroupId=LG.GroupId) AS StartTime,
(SELECT MAX(ExecutionTimeStamp) FROM logging WHERE GroupId=LG.GroupId) AS EndTime,
(SELECT COUNT(*) FROM logging WHERE LogMessage LIKE '%started%' AND GroupId = LG.GroupId) AS StartedCount,
(SELECT COUNT(*) FROM logging WHERE LogMessage LIKE '%ended%' AND GroupId = LG.GroupId) AS EndedCount,
(SELECT COUNT(*) FROM logging WHERE GroupId = LG.GroupId) AS TotalProcess,
(SELECT COUNT(*) FROM logging WHERE LogLevel='INFO' AND GroupId = LG.GroupId) AS InfoCount,
(SELECT COUNT(*) FROM logging WHERE LogLevel='ERROR' AND GroupId = LG.GroupId) AS Errors,
(SELECT COUNT(*) FROM logging WHERE LogLevel='WARN' AND GroupId = LG.GroupId) AS Warnings,
(SELECT COUNT(*) FROM logging WHERE ActivityName= 'Download Report' AND IsObjectReceived=1 AND GroupId = LG.GroupId) AS PaycomReportsDownloaded,
(SELECT COUNT(*) FROM logging WHERE ActivityName= 'Import Script' AND IsObjectReceived=1 AND GroupId = LG.GroupId) AS FilesImported,
(SELECT COUNT(*) FROM logging WHERE ActivityName= 'Export Script' AND IsObjectReceived=1 AND GroupId = LG.GroupId) AS ReportsExported
FROM logging LG
WHERE (LG.ProcessName LIKE '%HR%')
GROUP BY LG.GroupId;
Do
$$
DECLARE MAXID INT;
COUNTER INT := 1;
NewGroupId INT;
BEGIN
MAXID := (SELECT COUNT(*) FROM HRTempLogs);
WHILE (COUNTER <= MAXID) LOOP
NewGroupId := (SELECT GroupId FROM (SELECT GroupId, ROW_NUMBER() OVER (ORDER BY GroupId) AS RowNum FROM HRTempLogs) Logs WHERE RowNum = COUNTER);
UPDATE HRTempLogs
SET Date = to_char(to_date(StartTime, 'MM/DD/YYYY'), 'DD MON YYYY'),
ProcessName = 'HR Automation HR Reports',
BotName = (SELECT DISTINCT RobotName FROM logging WHERE GroupId = NewGroupId LIMIT 1),
Status = (SELECT
CASE WHEN EndedCount=0 AND StartedCount=1 THEN 'Started'
WHEN EndedCount=0 AND StartedCount>1 THEN 'Running'
WHEN EndedCount=StartedCount THEN 'Completed'
END
FROM HRTempLogs WHERE GroupId = NewGroupId LIMIT 1),
Exception = (SELECT
CASE WHEN InfoCount != TotalProcess THEN 'Yes'
ELSE 'No'END
FROM HRTempLogs WHERE GroupId = NewGroupId LIMIT 1),
Cycle = (SELECT RowNum FROM (SELECT ROW_NUMBER() OVER (ORDER BY GroupId) AS RowNum FROM HRTempLogs) Logs WHERE RowNum = COUNTER),
Duration = (SELECT CAST((DATE_PART('day', EndTime::timestamp - StartTime::timestamp) * 24 +
DATE_PART('hour', EndTime::timestamp - StartTime::timestamp))
AS VARCHAR) || ' hours ' ||
CAST(((DATE_PART('day', EndTime::timestamp - StartTime::timestamp) * 24 +
DATE_PART('hour', EndTime::timestamp - StartTime::timestamp)) * 60 +
DATE_PART('minute', EndTime::timestamp - StartTime::timestamp)) AS VARCHAR) || ' mins ' ||
CAST((((DATE_PART('day', EndTime::timestamp - StartTime::timestamp) * 24 +
DATE_PART('hour', EndTime::timestamp - StartTime::timestamp)) * 60 +
DATE_PART('minute', EndTime::timestamp - StartTime::timestamp)) * 60 +
DATE_PART('second', EndTime::timestamp - StartTime::timestamp)) AS VARCHAR) || ' secs ')
WHERE GroupId = NewGroupId;
COUNTER := COUNTER + 1;
END LOOP;
END
$$;
DELETE FROM AutomationDashboard WHERE ProcessName='HR Automation HR Reports';
--Automation Process HR
INSERT INTO AutomationDashboard(Date, ProcessName, BotName, Status, StartTime, EndTime, Cycle, Duration, Errors, Warnings, PaycomReportsDownloaded, FilesImported, ReportsExported)
SELECT Date,
ProcessName, BotName, Status,
CAST(StartTime as time),
CAST(EndTime as time),
Cycle, Duration, Errors, Warnings,
PaycomReportsDownloaded, FilesImported, ReportsExported
FROM HRTempLogs;
DELETE FROM AutomationDashboardHeader WHERE ProcessName='HR Automation HR Reports';
--Automation Process HR Header
INSERT INTO AutomationDashboardHeader(Date, ProcessName, No_of_Bots, No_of_Processes, No_of_Cycles, No_of_Exceptions, No_of_Warnings)
SELECT
T.Date,
'HR Automation HR Reports',
COUNT(DISTINCT T.BotName) ,
COUNT(DISTINCT T.ProcessName),
(SELECT COUNT(*) FROM HRTempLogs WHERE Status='Completed' AND Date = T.Date) ,
(SELECT COUNT(*) FROM logging WHERE LogLevel='ERROR' AND ProcessName LIKE '%HR%' AND to_char(to_date(ExecutionTimestamp, 'MM/DD/YYYY'), 'DD MON YYYY') = T.Date),
(SELECT COUNT(*) FROM logging WHERE LogLevel='WARN' AND ProcessName LIKE '%HR%' AND to_char(to_date(ExecutionTimestamp, 'MM/DD/YYYY'), 'DD MON YYYY') = T.Date)
FROM HRTempLogs T
GROUP BY T.Date;
DELETE FROM AutomationDashboardExceptions WHERE ProcessName='HR Automation HR Reports';
--Automation Process HR Exceptions
INSERT INTO AutomationDashboardExceptions(Date, ProcessName, BotName, ExceptionType, No_of_Errors, LogMessage, Cycle, ActivityName)
SELECT to_char(to_date(ExecutionTimestamp, 'MM/DD/YYYY'), 'DD MON YYYY'),
(SELECT DISTINCT ProcessName FROM HRTempLogs),
LG.RobotName, LG.LogLevel,
(SELECT count(*) from logging WHERE LogLevel='ERROR' AND Id = LG.Id),
LogMessage,
(SELECT Cycle FROM HRTempLogs WHERE GroupId = LG.GroupId),
ActivityName
FROM logging LG
WHERE LG.ProcessName LIKE '%HR%' AND LG.LogLevel='ERROR';
DELETE FROM HRFileTransfer;
--Automation Process HR File Tranfer
INSERT INTO HRFileTransfer(Date, File, ActivityName)
SELECT to_char(to_date(ExecutionTimestamp, 'MM/DD/YYYY'), 'DD MON YYYY'),
ObjectName, ActivityName
FROM logging
WHERE (ProcessName LIKE '%HR%') AND IsObjectReceived = 1;
DROP Table HRTempLogs;
END
$BODY$;