Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solidify and test loading XML files using the processing queue
- Loading branch information
Showing
6 changed files
with
93 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
SQLScripts/2-Loading-and-parsing-XML-data/0.4-Create_RawDataXml.XmlFiles_Table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- Delete table if it exists already | ||
IF OBJECT_ID('RawDataXml.XmlFiles') IS NOT NULL | ||
DROP TABLE RawDataXml.XmlFiles; | ||
GO | ||
-- Create the table | ||
CREATE TABLE RawDataXml.XmlFiles ( | ||
SiteId UNIQUEIDENTIFIER, | ||
ApiSiteParameter NVARCHAR(256) NOT NULL, | ||
DataType NVARCHAR(256) NOT NULL, | ||
RawDataXml XML NULL, | ||
SourceFilePath NVARCHAR(512) NOT NULL, | ||
Inserted DATETIME2 DEFAULT GETDATE(), | ||
CONSTRAINT fk_XmlFiles_SiteId FOREIGN KEY (SiteId) REFERENCES CleanData.Sites(Id) | ||
); | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...arsing-XML-data/1.4-XmlProcessingQueue_Execute_RawXmlData.usp_LoadBadgesXml_Procedure.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
DECLARE @StartTime DATETIME2 = GETDATE() | ||
|
||
DECLARE | ||
@RowNum INT, | ||
@SiteDirectory NVARCHAR(256), | ||
@FullFilePath NVARCHAR(512), | ||
@Now DATETIME2; | ||
|
||
DECLARE _BadgesXmlProcessing CURSOR FOR | ||
SELECT TOP 100 | ||
RowNum, | ||
SiteDirectory, | ||
FilePath | ||
FROM RawDataXml.XmlProcessingQueue | ||
WHERE DataType = 'Badges' | ||
AND Processed = 0 | ||
ORDER BY RowNum ASC; | ||
|
||
OPEN _BadgesXmlProcessing; | ||
|
||
FETCH NEXT FROM _BadgesXmlProcessing INTO @RowNum, @SiteDirectory, @FullFilePath; | ||
|
||
WHILE @@FETCH_STATUS = 0 | ||
BEGIN | ||
SET @Now = GETDATE(); | ||
EXECUTE RawDataXml.usp_LoadBadgesXml @SiteDirectory, @FullFilePath; | ||
|
||
INSERT INTO RawDataXml.XmlProcessingLog | ||
SELECT SiteId, ApiSiteParameter, SiteDirectory, FilePath, | ||
DATEDIFF(MILLISECOND, @Now, GETDATE()), | ||
GETDATE() | ||
FROM RawDataXml.XmlProcessingQueue | ||
WHERE RowNum = @RowNum; | ||
UPDATE RawDataXml.XmlProcessingQueue | ||
SET Processed = 1 | ||
WHERE RowNum = @RowNum; | ||
|
||
FETCH NEXT FROM _BadgesXmlProcessing INTO @RowNum, @SiteDirectory, @FullFilePath; | ||
END | ||
|
||
CLOSE _BadgesXmlProcessing; | ||
DEALLOCATE _BadgesXmlProcessing; | ||
|
||
--verify | ||
SELECT DATEDIFF(SECOND, @StartTime, GETDATE()) AS [ProcessingTimeSeconds] | ||
SELECT * FROM RawDataXml.XmlProcessingLog | ||
SELECT * FROM CleanData.Badges ORDER BY ApiSiteParameter ASC, CreationDate ASC | ||
SELECT COUNT(*) AS [BadgesXmlLeftToProcess] | ||
FROM RawDataXml.XmlProcessingQueue WHERE DataType = 'Badges' AND Processed = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters