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

Rule to check if field name and description are similar #206

Open
jatin-datashells opened this issue Jan 1, 2025 · 1 comment
Open

Rule to check if field name and description are similar #206

jatin-datashells opened this issue Jan 1, 2025 · 1 comment
Labels
enhancement New feature or request new-rule New Rule support

Comments

@jatin-datashells
Copy link

jatin-datashells commented Jan 1, 2025

Hi @fabio-looker,

I am trying to create a new custom rule to check if field_name is similar to description. Code works fine if it is exact match ie if description is "first_name" and field_name is "first_name" but it does not work if description is "First Name" or "first name" trying to use regex replace and replace but unable to get the solution. Below is the code which I am using, can you please check and suggest what can be modified to get it working?

> # rule: Check_desc {
> # description: "This rule checks if description is similar to field name for any field added (dimension/measure)."
> # match: "$..view.*[dimension,dimension_group,measure][?(@.hidden!==true)]"
> # expr_rule: ($if ($boolean ($match
> #"^" ::match:$name "$"
> #($concat "^" ($replace ::match:description " " "_") "$")))
> #($concat "Field name `" ::match:$name "` and description `" ::match:description "` is similar . Please change it.")
> #true)
> #;;
> #}
@fabio-looker
Copy link
Collaborator

Hey @jatin-datashells

It looks like there's not a great built-in "regex replace" method within Liyad. It could be added if this gets too complex, but for a pretty simple set of characters, you can just replace each one independently with the string replace function.

I put these in a "pipe" so it should be easier to add more normalizations if you want:

($let normalize (-> (x) ($pipe x
   (-> (x) ($any x ""))
   (-> (x) ($__call x toLowerCase))
   (-> (x) ($replace-all x "_" ""))
   (-> (x) ($replace-all x " " ""))
   (-> (x) ($replace-all x "?" ""))
)))
(==
  (normalize ::match:$name)
  (normalize ::match:description)
)

I might even add a built-in rule for this, so I'll leave this open

@fabio-looker fabio-looker added enhancement New feature or request new-rule New Rule support labels Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new-rule New Rule support
Projects
None yet
Development

No branches or pull requests

2 participants