英文:
How to perform Partial Reload with Left Join on Qlik?
问题
我有一个Qlik脚本,在其中加载了两个表格,Product
和Customer
。我使用左连接在一个名为Purchase_ID
的共同字段上将这两个表格连接起来。我想要使用部分重新加载按钮对Customer
表格进行部分重新加载,以查看当新客户被添加到Customer
表格时的更新。 但是,当选择部分重新加载选项时,我的工作表没有更新,如下所示:
我尝试使用ADD ONLY LOAD
选项,但这要求我每次加载仪表板时都要点击重新加载按钮,否则我会收到“不完整的可视化”错误,因为它只在启动部分重新加载时加载Customer
表格。 我还尝试为Product表格使用if PartialReload = 0 then ... endif
条件,但我收到了“没有表格可连接”的错误。
在这种情况下,我该如何进行部分重新加载?以下是我脚本的参考:
LOAD
Product_ID,
Cost_Per_Unit,
Purchase_ID,
Date
FROM Product
WHERE Date > '2023-06-01'
LEFT JOIN
ADD LOAD
Customer_ID,
Purchase_ID
FROM Customer
英文:
I have a Qlik script where I load two tables, Product
and Customer
. I join these two tables on a common field called Purchase_ID
using a left join. I want to do a partial reload on the Customer
table using the Partial Reload button to see the updates when new customers are added to the Customer
table. However, this does not update my sheet when the Partial Reload option is selected as shown below:
I tried using the ADD ONLY LOAD
option but this requires me to click the Reload button each time I load the dashboard, else I get an Incomplete Visualization
error as it loads the Customer
table only when a Partial Reload is initiated. I also tried using an if PartialReload = 0 then ... endif
condition for the Product table but I get a No Table to Join
error.
How can I do a Partial Reload in this situation? Here is my script for reference:
LOAD
Product_ID,
Cost_Per_Unit,
Purchase_ID,
Date
FROM Product
WHERE Date > '2023-06-01'
LEFT JOIN
ADD LOAD
Customer_ID,
Purchase_ID
FROM Customer
答案1
得分: 2
看起来你的 If ... Then
需要进行微调,因为你应该使用 IsPartialReload()
函数 来实现这个目标:
LOAD
Product_ID,
Cost_Per_Unit,
Purchase_ID,
Date
FROM Product
WHERE Date > '2023-06-01';
If Not IsPartialReload() Then
LEFT JOIN
LOAD
Customer_ID,
Purchase_ID
FROM Customer;
End If
编辑
经过考虑你的评论并重新阅读你的原始问题后,我现在更好地理解了你的问题。我已经创建了一个与你的示例(Customer 和 Product)相同的两个表格,并具有相同的字段,以尝试复制这个问题。
部分重新加载不起作用的一个可能原因是它实际上可能正在工作,但你对 Left Join
的使用实际上可能不是你想要的。根据你的示例脚本,你想要完全加载客户和产品表,同时仅部分重新加载客户表。我在测试时发现的问题是,Left Join
只会在原始的“正常”重新加载中已经在产品表中存在 [Purchase_ID]
字段的情况下加载任何新的客户记录。如果在尝试使用部分重新加载从客户表中加载新记录时,你还在拉取新的 [Purchase_ID]
,那么就不会有值成功地与产品表进行 Left Join
。
你可以通过简单地从原始脚本中删除 Left Join
来测试这个理论。当我添加新的客户记录然后执行部分重新加载时,这对我来说一切都正常工作。
编辑 2
在这个 Qlik Community 帖子中发布的解决方案允许我在常规重新加载和部分重新加载情况下都使用 Left Join
。这是我使用的脚本:
IF IsPartialReload() THEN
DROP TABLE [Product];
END IF;
[Product]:
ADD SELECT
"Product_ID",
"Cost_Per_Unit",
"Purchase_ID",
"Date"
FROM "public"."Product"
WHERE "Date" > 'Jan-08-2022';
;
LEFT JOIN ([Product])
ADD SELECT
"Customer_ID",
"Purchase_ID",
"Customer_Name"
FROM "public"."Customer";
DROP TABLE [Product]
似乎是使这个工作的关键,还要注意在 两个 表格上使用 ADD
前缀。
英文:
Looks like your If ... Then
needs to be tweaked, as you should be using the IsPartialReload()
function to achieve this:
LOAD
Product_ID,
Cost_Per_Unit,
Purchase_ID,
Date
FROM Product
WHERE Date > '2023-06-01';
If Not IsPartialReload() Then
LEFT JOIN
LOAD
Customer_ID,
Purchase_ID
FROM Customer;
End If
Edit
After taking into account your comments and re-reading your original question, I'm now understanding your issue much more. I have spun up a database with the same two tables from your example (Customer and Product) and with the same fields to try and replicate the issue.
One possibility for why the partial reload is not working is that it actually is working but your use of the Left Join
is not actually what you want. Based on your example script, you are wanting to fully load both the Customer and Product tables while only partially reloading the Customer table. The problem I found when testing this out was that the Left Join
is only going to load any new Customer records if the [Purchase_ID]
field is already in the Product table from the original, "normal" reload. If, when trying to load new records from the Customer table using a partial reload, you are also pulling in new [Purchase_ID]
s, then there won't be values to successfully Left Join
to the Product table on.
You can test this theory by simply removing the Left Join
from your original script. Everything worked correctly for me when I did this by adding new customer records and then doing a partial reload.
Edit 2
The solution posted in this Qlik Community thread allowed me to use a Left Join
in both the regular and partial reload scenarios. This is the script I used:
IF IsPartialReload() THEN
DROP TABLE [Product];
END IF;
[Product]:
ADD SELECT
"Product_ID",
"Cost_Per_Unit",
"Purchase_ID",
"Date"
FROM "public"."Product"
WHERE "Date" > 'Jan-08-2022';
;
LEFT JOIN ([Product])
ADD SELECT
"Customer_ID",
"Purchase_ID",
"Customer_Name"
FROM "public"."Customer";
The DROP TABLE [Product]
is what appears to get this working, along with using the ADD
prefix on both tables.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论