Topic
Summary
- How to filter the data by the filename of a link from the Markdown files with the
case_YAML_Y-YYY
structure?
Structures: case_YAML_Y-YYY
Summary
TIP:
1.AoH in the topic means an Array of Hashes.
2.Hashes in the topic means JavaScript Objects.
Definitions:
Structure Code: case_YAML_Y-YYY
Definitions: Use nested YAML fields, where a single root YAML field which is an Array of Hashes consists of
at least one Hash, which is represented by sub YAML fields “-YYY”.YAML: Use YAML.
Y: a single root YAML field which is an Array of Hashes
-YYY: at least one Hash, which is represented by sub YAML fields “-YYY”The first sub YYY, an element of the root Y, consists of multiple key/value pairs, as known as a Hash.
The second sub YYY, an element of the root Y, consists of multiple key/value pairs, as known as a Hash.Data Structure: an AoH
Original Structure Code expressed in regular expressions: case_YAML_Y(-YYY){1,}
Basic Example: The AoH drinks
consists of two elements with the data type of a Hash.
NOTE:
Take the following filedb_20220110
as an example.
Y: drinks, which is an AoH
-YYY: The first sub YYY, an element of the root Y, contains multiple key/value pairs, as known as a Hash.
-YYY: The second sub YYY, an element of the root Y, contains multiple key/value pairs, as known as a Hash.
```yaml
---
Date: 2022-01-10
drinks:
# The first sub YYY
- item_name: "Black Coffee"
unit_price: 120
caffeine_content: 300
item_no: "IT001"
# The second sub YYY
- item_name: "Green Tea"
unit_price: 100
caffeine_content: 200
item_no: "IT002"
---
```
Basic Example: The AoH drinks
consists of one element with the data type of a Hash.
NOTE:
Take the following filedb_20220111
as an example.
Y: drinks, which is an AoH
-YYY: The first sub YYY, an element of the root Y, contains multiple key/value pairs, as known as a Hash.
```yaml
---
Date: 2022-01-11
drinks:
# The first sub YYY
- item_name: "Apple Juice"
unit_price: 110
caffeine_content: 0
item_no: "IT003"
---
```
Notes:
Summary
Q1: What is the data structure of the file dic_19920301
?
Summary_Q1
Original Example: Q1 (To be explained)
NOTE:
Take the following filedic_19920301
as an example.
```yaml
---
date: 1992-03-01
purchases:
- store: "[[some store]]"
item: some item
comments: comments
- store: "[[another store]]"
item: another item
comments: other comments
---
```
A1:
Another Example: A1_11 (Before using FLATTEN)
NOTE:
Before runningFLATTEN purchases AS OnePurchase
, the fieldpurchases
in the page, is an AoH as shown below.
- Here is a slice of the
page
hash, where thepage.file.name
isdic_19920301
.
```JSON
{
date: "1992-03-01T00:00:00.000Z",
purchases: [
{
store: "[[some store]]",
item: "some item",
comments: "comments",
},
{
store: "[[another store]]",
item: "another item",
comments: "other comments",
},
],
}
```
Another Example: A1_12 (After using FLATTEN)
NOTE:
After runningFLATTEN purchases AS OnePurchase
, theOnePurchase
in the page is a Hash as shown below.
- Here is a slice of the
page
hash, where thepage.file.name
isdic_19920301
.
```JSON
[
{
date: "1992-03-01T00:00:00.000Z",
OnePurchase: {
store: "[[some store]]",
item: "some item",
comments: "comments",
},
purchases: [
{
store: "[[some store]]",
item: "some item",
comments: "comments",
},
{
store: "[[another store]]",
item: "another item",
comments: "other comments",
},
],
},
{
date: "1992-03-01T00:00:00.000Z",
OnePurchase: {
store: "[[another store]]",
item: "another item",
comments: "other comments",
},
purchases: [
{
store: "[[some store]]",
item: "some item",
comments: "comments",
},
{
store: "[[another store]]",
item: "another item",
comments: "other comments",
},
],
},
]
```
Q2: What is the data structure of the file dic_19920601
?
Summary_Q2
Original Example: Q2 (To be explained)
NOTE:
- Take the following file
dic_19920601
as an example.- The
purchases
in the page is a Hash.
```yaml
---
date: 1992-06-01
purchases:
- store: "[[some store]]"
item: some item
comments: comments
---
```
A2_21:
Another Example: A2_21
- Here is a slice of the
page
hash, where thepage.file.name
isdic_19920601
.
```JSON
{
date: "1992-06-01T00:00:00.000Z",
purchases: [
{
store: "[[some store]]",
item: "some item",
comments: "comments",
},
],
}
```
Test
Summary
- dataview: v0.5.55
Input
Summary
dictionary files: for the DQL10
- Location: “100_Project/02_dataview/Q17_Purchases/Q17_test_data”
folder: 03_an_AoH_consists_of_two_hashes
- filename :
dic_19920301
---
date: 1992-03-01
purchases:
- store: "[[some store]]"
item: some item
comments: comments
- store: "[[another store]]"
item: another item
comments: other comments
---
folder: 04
- filename :
dic_19920401
---
date: 1992-04-01
purchases:
- store: "[[some store]]"
item: apples
comments:
- store: "[[some store]]"
item: oranges
comments:
---
folder: 05
- filename :
dic_19920501
---
date: 1992-05-01
purchases:
- store: "[[another store]]"
item: potatoes, potatoes
comments:
- store: "[[another store]]"
item: a very big watermelon
comments:
---
folder: 06_an_AoH_consists_of_one_hash
- filename :
dic_19920601
---
date: 1992-06-01
purchases:
- store: "[[some store]]"
item: some item
comments: comments
---
folder: 07_an_AoH_contains_one_empty_hash
- filename :
dic_19920701
---
date: 1992-07-01
purchases:
- store: "[[some store]]"
item: some item
comments: comments
- store:
item:
comments:
---
folder: 08_null
- filename :
dic_19920801
---
date: 1992-08-01
purchases:
- store:
item:
comments:
---
- filename :
dic_19920806
---
date: 1992-08-06
purchases:
---
folder: 09_undefined
- filename :
dic_19920901
---
date: 1992-09-01
---
folder: 10_excluding_store_not_link
- filename :
dic_19921001
---
date: 1992-10-01
purchases:
- store: "another store"
item: another item
comments: comments
---
DQL10_filter_by_filename_of_a_link_and_TABLE: case_YAML_Y-YYY
Summary
Main DQL
Code Name | Data type | Group By | Purposes | Remark |
---|---|---|---|---|
DQL10 _filter_by_filename _of_a_link _and_TABLE |
OnePurchase.store :a link |
no | 1.To filter by purchases 2.To split up a list purchases into each individual element OnePurchase 3.To filter by OnePurchase and OnePurchase.store 4.To define a field variable s_filename_of_link 5.To filter by s_filename_of_link 6.To sort by date in descending order 7.To display the result as a table |
NOTE: Require the files with the case_YAML_Y-YYY structureThe Regular Expression in the DQL10 is based on the DQL10 in the following topic. - Solutions: by Justdoitcc |
Code DQL10_filter_by_filename_of_a_link_and_TABLE: case_YAML_Y-YYY
Summary_code
title: DQL10_filter_by_filename_of_a_link_and_TABLE =>0.Require the files with the `case_YAML_Y-YYY` structure 1.To filter by `purchases` 2.To split up a list `purchases` into each individual element `OnePurchase` 3.To filter by `OnePurchase` and `OnePurchase.store` 4.To define a field variable `s_filename_of_link` 5.To filter by `s_filename_of_link` 6.To sort by `date` in descending order 7.To display the result as a table
collapse: close
icon:
color:
```dataview
TABLE WITHOUT ID
file.link AS "File",
OnePurchase.store AS "store",
OnePurchase.item AS "item",
OnePurchase.comments AS "comments",
s_filename_of_link AS "filename_of_store"
FROM "100_Project/02_dataview/Q17_Purchases/Q17_test_data"
WHERE purchases
FLATTEN purchases AS OnePurchase
WHERE OnePurchase AND OnePurchase.store
FLATTEN regexreplace(meta(OnePurchase.store).path, "^(.*/)(.+)(\.md)$", "$2") AS s_filename_of_link
WHERE contains(s_filename_of_link, "another store")
SORT date DESC
```
Screenshots(DQL10)
Reference
Summary
Q88_Links:Regular Expressions
- Q88_Links: Solutions
```dataview
FLATTEN regexreplace(meta(up).path, "^(.*/)(.+)(\.md)$", "$2") AS s_filename_of_link
```