obsidian-dataview icon indicating copy to clipboard operation
obsidian-dataview copied to clipboard

file.tags vs tags(frontmatter)

Open mnvwvnm opened this issue 2 years ago • 8 comments

Describe the bug Using GROUP BY / FLATTEN in dataview query I'm able to obtain the expect result if work with "tags" via frontmatter (except the fact that the tag not be an 'active/clickable' element). That's not possible with "file.tags".

To Reproduce

  1. Query with "tags":
TABLE join(rows.file.link, ", ") AS Files
WHERE tags
FLATTEN tags
GROUP BY tags
Group Files
tag1 File A
tag2 File A, File B
tag3 File C
tag4 File A, File D
tag5 File D
tag6 File A, File C, File D

The table is grouped as wanted - tag by tag -, although tags are not 'active' elements.

  1. Query with "file.tags"
TABLE join(rows.file.link, ", ") AS Files
FROM "Teste2"
WHERE tags
FLATTEN tags
GROUP BY tags
Group Files
#tag1
#tag2
#tag4
#tag6
File A, File A, File A, File A
#tag2 File B
#tag3
#tag6
File C, File C
#tag4
#tag6
File D, File D

The table isn't grouped as wanted - tag by tag -, although tags are now 'active' elements.

Expected behavior A mix of the two previous results: a table grouped as in case 1 with 'active' tags as in case 2.

Desktop (please complete the following information):

  • OS: macOS BigSur
  • Obsidian Version: v0.12.15
  • Dataview Version: 0.4.8

mnvwvnm avatar Sep 11 '21 10:09 mnvwvnm

The two queries are the same - I think you may have accidentally copy-pasted the same one twice.

The following query works for me to obtain both desired behaviors:

TABLE join(rows.file.link, ", ") AS Files
FLATTEN file.tags AS tag
GROUP BY tag

It looks like the GROUP BY is grouping by lists instead of individual tags - do you have nested tag lists?

blacksmithgu avatar Sep 11 '21 19:09 blacksmithgu

Thanks for your answer. And yes, you are right 🤦‍♂️... Sorry. The correct query was:

TABLE join(rows.file.link, ", ") AS Files
WHERE file.tags
FLATTEN file.tags
GROUP BY file.tags

I tried your query and works for me too. Thank you. About the nested tags, I have some in my "test" vault. But in target files/folder filtered in my query example, no.

mnvwvnm avatar Sep 11 '21 22:09 mnvwvnm

Ah, the reason your second query is due to a bad Dataview interaction with how GROUP BY works - it makes a variable literally called "file.tags", which you have to obtain via row["file.tags"]. I would use GROUP BY file.tags AS tag to rename it to something usable.

blacksmithgu avatar Sep 12 '21 03:09 blacksmithgu

This mostly appears to be a UX problem with GROUP BY doing something stupid with variables with dots in them. I may be able to fix the behavior.

blacksmithgu avatar Sep 12 '21 04:09 blacksmithgu

Once again, thank you for the clarification and for all availability.

mnvwvnm avatar Sep 12 '21 08:09 mnvwvnm

Hi mnvwvnm, is this fixed?

AB1908 avatar Jul 25 '22 11:07 AB1908

Are you moving under the rug, on the dust of history? 😄 I guess it's not fixed... i.e., the behavior remains the same. But now I rename every flatten and group by actions and it becomes a non-issue.

mnvwvnm avatar Jul 25 '22 14:07 mnvwvnm

I see, let's keep this open then.

AB1908 avatar Jul 25 '22 19:07 AB1908

Looks like there's nothing to do here since we've documented the row syntax. Closing.

AB1908 avatar Nov 07 '22 22:11 AB1908