Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Function to convert data types to their display value #2480

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dnlbauer
Copy link

@dnlbauer dnlbauer commented Nov 19, 2024

Querying for metadata where only the "display" version is currently complicated.

Consider these three metadata fields:

(author:: Jon Doe)
(author:: [[Jon Doe]])
(author:: [Jon Doe](https://example.com))

The query

TABLE author
FLATTEN author
WHERE author = "Jon Doe"

only results in the first match:

File Author
test Jon Doe

The only query I found that matched all three cases was this one:

TABLE author
FLATTEN author
WHERE contains(string(author), "Jon Doe")
File Author
test Jon Doe
test Jon Doe
test Jon Doe

However, this expression is error-prone and quite complicated. This PR introduces a new utility function display() that tries to convert all objects into a valid string representation while preserving the display value. This means [[Jon Doe]] is converted to "Jon Doe" and [[Jon Doe|Joe]] is converted to "Jon", etc. The above query reduces to this much simpler expression:

TABLE author
FLATTEN author
WHERE display(author) = "Jon Doe"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant