Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
The file I have for the Initial load is Sample.xlsx
Number | Alphabet |
---|---|
1 | A |
2 | B |
3 | C |
4 | D |
After loading this file, I'm storing it as a QVD File using the following Code,
Sample:
LOAD Number,
Alphabet
FROM Sample.xlsx (ooxml, embedded labels, table is Sheet1);
Store Sample into Sample.qvd(qvd);
I have inserted a new row to the Sample.xlsx as
Number | Alphabet |
---|---|
1 | A |
2 | B |
3 | C |
4 | D |
5 | E |
For performing Incremental Load (Insert and Update) on this data, I have added the following code to the existing Code.
MaxNumber:
LOAD max(Number) as MaxNumber
Resident Sample;
Let vmax=peek('MaxNumber',0,'Last_Updated_Number');
Drop Table MaxNumber;
IncTable:
LOAD Number,
Alphabet
FROM Sample.xlsx
(ooxml, embedded labels, table is Sheet1) where Number > $(vmax);
Concatenate
LOAD Number,
Alphabet
FROM Sample.qvd (qvd) where not Exists(Number);
Drop Table IncTable;
Once I reload this, I'm encountering a problem like
What is even more baffling is, I got the updated data when I checked the Preview of the Table in Data model.
Can someone help me on this? Where I was wrong and What needs to be done to get this without any Script Error?
Thanks
Hi
Try Like this
Sample:
LOAD Number,Alphabet
FROM Sample.xlsx (ooxml, embedded labels, table is Sheet1);
Store Sample into Sample.qvd(qvd);
MaxNumber:
LOAD max(Number) as Last_Updated_Number Resident Sample;
Let vmax=peek('Last_Updated_Number',0,'MaxNumber');
Drop Table MaxNumber,Sample;
IncTable:
LOAD Number,Alphabet
FROM Sample.qvd (qvd) ;
Concatenate
LOAD Number,Alphabet
FROM UpdatedSample.xlsx
(ooxml, embedded labels, table is Sheet1) where not Exists(Number,Number);
hth
Sasi
HI
PFA
Thanks
Manju
Incremental load is a very common task in relation to data bases. It is defined as loading nothing but new or changed records from the database. All other data should already be available, in one way or another. With QVD Files it is possible to perform incremental load in most cases.
The basic process is described below:
1. Load the new data from Database table (a slow process, but loading a limited number of records).
2. Load the old data from QVD file (loading many records, but a much faster process).
3. Create a new QVD file.
4. Repeat the procedure for every table loaded.
The complexity of the actual solution depends on the nature of the source database, but the following basic cases can be identified:
1) Case 1: Append Only (typically log files
2) Case 2: Insert Only (No Update or Delete)
3) Case 3: Insert and Update (No Delete)
4) Case 4: Insert, Update and Delete
Below you will find outlined solutions for each of these cases. The reading of QVD files can be done in either optimized mode or standard mode. (The method employed is automatically selected by the QlikView script engine depending on the complexity of the operation.) Optimized mode is (very approximately) about 10x faster than standard mode or about 100x faster than loading the database in the ordinary fashion.
The simplest case is the one of log files; files in which records are only appended and never deleted. The following conditions apply:
Script Example:Buffer (Incremental) Load * From LogFile.txt (ansi, txt, delimiter is '\t', embedded labels);
If the data resides in a database other than a simple log file the case 1 approach will not work. However, the problem can still be solved with minimum amount of extra work. The following conditions apply:
Script Example:QV_Table:SQL SELECT PrimaryKey, X, Y FROM DB_TABLEWHERE ModificationTime >= #$(LastExecTime)#AND ModificationTime < #$(BeginningThisExecTime)#; Concatenate LOAD PrimaryKey, X, Y FROM File.QVD;STORE QV_Table INTO File.QVD;(The hash signs in the SQL WHERE clause define the beginning and end of a date. Check your database manual for the correct date syntax for your database.)
The next case is applicable when data in previously loaded records may have changed between script executions. The following conditions apply:
Script Example:QV_Table:SQL SELECT PrimaryKey, X, Y FROM DB_TABLEWHERE ModificationTime >= #$(LastExecTime)#; Concatenate LOAD PrimaryKey, X, Y FROM File.QVDWHERE NOT Exists(PrimaryKey); STORE QV_Table INTO File.QVD;
The most difficult case to handle is when records are actually deleted from the source database between script executions. The following conditions apply:
Script Example:
Let ThisExecTime = Now( );
QV_Table:
SQL SELECT PrimaryKey, X, Y FROM DB_TABLE
WHERE ModificationTime >= #$(LastExecTime)#
AND ModificationTime < #$(ThisExecTime)#;
Concatenate LOAD PrimaryKey, X, Y FROM File.QVD
WHERE NOT EXISTS(PrimaryKey);
Inner Join SQL SELECT PrimaryKey FROM DB_TABLE;
If ScriptErrorCount = 0 then
STORE QV_Table INTO File.QVD;
Let LastExecTime = ThisExecTime;
End If
QlikView 11.20 SR6