随着QlikView文档数据源中的数据量增加,加载文件所需的时间也会增加,这会降低分析过程的速度.最小化加载数据所花费的时间的一种方法是仅加载源中的新记录或更新的记录.将源中的新记录或已更改记录加载到QlikView文档中的概念称为增量加载.
要从源识别新记录,我们使用每行的顺序唯一键或日期时间戳.这些唯一键或数据时间字段的值必须从源文件流向QlikView文档.
让我们考虑以下包含零售商店中产品详细信息的源文件.将其保存为本地系统中的.csv文件,QlikView可以访问该文件.在一段时间内,会添加更多产品,并对某些产品的描述进行更改.
Product_Id,Product_Line,Product_category,Product_Subcategory 1,Sporting Goods,Outdoor Recreation,Winter Sports & Activities 2,"Food, Beverages & Tobacco",Food Items,Fruits & Vegetables 3,Apparel & Accessories,Clothing,Uniforms 4,Sporting Goods,Athletics,Rugby 5,Health & Beauty,Personal Care 6,Arts & Entertainment,Hobbies & Creative Arts,Musical Instruments 7,Arts & Entertainment,Hobbies & Creative Arts,Orchestra Accessories 8,Arts & Entertainment,Hobbies & Creative Arts,Crafting Materials 9,Hardware,Tool Accessories,Power Tool Batteries 10,Home & Garden,Bathroom Accessories,Bath Caddies 11,"Food, Beverages & Tobacco",Food Items,Frozen Vegetables 12,Home & Garden,Lawn & Garden,Power Equipment
我们将使用脚本编辑器加载上述CSV文件(通过选择Table Files选项控制+ E),如下所示.在这里,我们还将数据保存到本地系统的QVD文件中.将QlikView文档另存为.qvw文件.
我们可以通过创建名为表格框的工作表对象来检查加载到QlikView文档的数据.这可以在布局菜单和新工作表对象子菜单中找到.
选择表格框表格对象后,进入下一个屏幕,即用于选择要创建的表中的列及其位置.我们选择以下列及其位置,然后单击"完成".
下面的图表显示了上一步中列出的数据.
让我们将以下三个记录添加到源数据中.在这里,产品ID是唯一的数字,代表新的记录.
13,Office Supplies,Presentation Supplies,Display 14,Hardware,Tool Accessories,Jigs 15,Baby & Toddler,Diapering,Baby Wipes
现在,我们编写脚本以仅从源中提取新记录.
// Load the data from the stored qvd. Stored_Products: LOAD Product_Id, Product_Line, Product_category, Product_Subcategory FROM [E:\Qlikview\data\products.qvd] (qvd); //Select the maximum value of Product ID. Max_Product_ID: Load max(Product_Id) as MaxId resident Stored_Products; //Store the Maximum value of product Id in a variable. Let MaxId = peek('MaxId',-1); drop table Stored_Products; //Pull the rows that are new. NewProducts: LOAD Product_Id,Product_Line, Product_category,Product_Subcategory from [E:\Qlikview\data\product_categories.csv] (txt, codepage is 1252, embedded labels, delimiter is ',', msq) where Product_Id > $(MaxId); //Concatenate the new values with existing qvd. Concatenate LOAD Product_Id,Product_Line, Product_category, Product_Subcategory FROM [E:\Qlikview\data\products.qvd](qvd); //Store the values in qvd. store NewProducts into [E:\Qlikview\data\products.qvd](qvd);
上述脚本仅提取新记录,这些记录被加载并存储到qvd文件中.当我们看到带有新产品ID 13,14和15的记录时.