Hi, I’m running into a problem when trying to creating a simple data model. I have two entities named Comment and Tags and a mapping table with foreign keys comment_id and tag_id pointing to both tables.
When I try to publish the data model, I’m getting an error message that says:
“Target model is invalid, a dataset must have either a fact or an anchor with a label or a valid grain.”
Can you tell me what am I doing wrong? Also, what is fact, anchor, label, and grain?
Best answer by Pavel
first, I’m sorry for the unclear message, I have escalated that to my colleagues in the GoodData product team.
Long story short, is basically tells you that you should define a compound primary key on your mapping table. Let me show how to do that:
- First, I have created a simple data model similar to what you have described:
Note the gray key icons in the mapping tables. It means they are foreign keys but there is no primary key on that table.
- Hover your mouse over the Mapping table, click the More button in the top right, and select “Set Primary Key”:
- On the next screen, select both Tag and Comment ID fields and click the “Set key” button:
- That’s it, your model is ready to be published. Note the key icons in the Mapping table have turned orange. It means they both belong to the compound primary key.
I hope this solves your problem but let me briefly explain the terminology and the logic behind the error message.
- Fact - a numeric column, something you want to aggregate using functions such as SUM, AVG etc
- “Anchor with a label” or a connection point is basically the same thing as a single column primary key.
- Grain - the level of detail in a fact table. In this context, it is basically the same thing is a unique constraint on table (typically containing multiple keys)
We have found out that no useful solution includes a table without a fact or a unique constraint and if it happens, it is usually a mistake or it leads to undesired consequences. In your situation, imagine how you could perform an incremental update of your mapping table without that compound primary key. This is why we require users to specify one of those on each table before a model is published.