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

Normalize contactql queries with type prefixes #1253

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion contactql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,22 @@ func (c *Condition) Simplify() QueryNode {
}

func (c *Condition) String() string {
property := c.propKey
value := c.value

// add prefix for fields and URNs
if c.propType == PropertyTypeField {
property = fmt.Sprintf(`fields.%s`, property)
} else if c.propType == PropertyTypeURN {
property = fmt.Sprintf(`urns.%s`, property)
}

if !isNumberRegex.MatchString(value) {
// if not a decimal then quote
value = strconv.Quote(value)
}

return fmt.Sprintf(`%s %s %s`, c.propKey, c.operator, value)
return fmt.Sprintf(`%s %s %s`, property, c.operator, value)
}

// BoolCombination is a AND or OR combination of multiple conditions
Expand Down
Loading
Loading