blacksmithgu / obsidian-dataview

A data index and query language over Markdown files, for https://obsidian.md/.
https://blacksmithgu.github.io/obsidian-dataview/
MIT License
7.04k stars 413 forks source link

Array interpreted as string in inline fields #432

Open juanfcocontreras opened 3 years ago

juanfcocontreras commented 3 years ago

Describe the bug When a list is used within an inline field, it is interpreted as a string. If the same field is used in the Frontmatter, it works as expected.

To Reproduce

  1. Create a note with the following content:
elements:: [3, 5, 6]

#test 
  1. Create a note with the following content:
```dataview
table
elements[0] as "First"
from #test
```
  1. Turn on preview
  2. The result is:
File First
test_list [

Expected behavior

File First
test_list 3

Desktop (please complete the following information):

Additional context

If the field is used in the frontmatter, it works as expected:

---
elements: [3, 5, 6]
---

#test 
blacksmithgu commented 3 years ago

Thanks for filing, will correct it for the next release.

blacksmithgu commented 3 years ago

Punting to 0.4.6 later this week to not delay the current release too long.

blacksmithgu commented 3 years ago

The fix here got caught up in some other inline field improvements and will be released as part of 0.5.0.

whydnct commented 2 years ago

I think the behavior in the image below could be related; first and second instances of the same field are treated differently. If field_a is stored in front matter all instances are treated as arrays of 3 elements

OS: Windows 10 Obsidian Version: 0.14.6 Dataview Version: 0.5.15

image

blacksmithgu commented 2 years ago

@whydnct I believe that behavior is because multiple field arrays with the same name are merged into one array - i.e., field_a becomes [uno, 1, a, dos, 2, b] rather than [[uno, 1, a], [dos, 2, b]]. However, I think the behavior isn't quite right in that case as well.

whydnct commented 2 years ago

I might be missing something, but I don't think it merges them that way: the 2nd query returns the first character of every element of the first field_a, but only the first element of the second field_a. It seems to me that both fields are treated differently.

AB1908 commented 2 years ago

Best inspect the index yourself by logging to console with `$=console.log(dv.current())` after turning on inline DVJS.

s-blu commented 1 year ago

Regarding the initial bug report: The syntax of lists in frontmatter and inline fields differ. In frontmatter it's elements: [3, 5, 6], inline its elements:: 3, 5, 6. Using this syntax, I get your expected result. elements:: [3, 5, 6] gets interpreted as a text and therefore elements[0] gives you back the first character of the text.

Regarding @whydnct point, this input gives me the result blacksmithgu expects - an array consisting of two arrays.

a:: "aa", "ab", "ac"
a:: "ba", "bb", "bc"

```dataview
LIST a
WHERE file.path = this.file.path


results to: 

![Image](https://user-images.githubusercontent.com/2006600/208263237-ae410754-a7b5-403b-96b6-64fba7551579.png)