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

[pkg/telemetryquerylanguage] Added Int factory function (#11810) #13441

Merged
merged 4 commits into from
Sep 7, 2022

Conversation

mcdoker18
Copy link
Contributor

Description:
Added the Int function to convert string and float type to int.
Use cases are described here #11810

Link to tracking Issue: #11810

Testing: unit tests

Documentation: updated the readme file

@mcdoker18 mcdoker18 requested a review from a team August 20, 2022 10:57
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 20, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: mcdoker18 / name: Vitalii Solodilov (7eb1a3edede5735be001d998821de61eb857c169)

@TylerHelmuth
Copy link
Member

@mcdoker18 Thanks for the contribution. Please split this into 2 PRs, one that adds the function to TQL and then one after that adds the function to the transform processor.


`Int(value)`

The `Int` factory function converts a float, bool and string data to the int type.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explicitly list out the types converted, and explicitly state that the returned type is int64

if value {
return int64(1)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

},
{
name: "float64 without decimal",
value: float64(55.0),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
value: float64(55.0),
value: float64(55),

Copy link
Member

@TylerHelmuth TylerHelmuth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the contribution!

@mcdoker18
Copy link
Contributor Author

@TylerHelmuth I was planning to add the changelog in the next PR, do you mind?

@TylerHelmuth
Copy link
Member

@TylerHelmuth I was planning to add the changelog in the next PR, do you mind?

Please add a changelog entry for the function addition to pkg/telemetryquerylanguage. We'll add a second changelog entry for the transform processor when the processor is updated to register the function.

We need entries for both because the TQL package can be used independently of the transform processor.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2022

This PR was marked stale due to lack of activity. It will be closed in 14 days.

Copy link
Member

@kentquirk kentquirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question about the interpretation of strings.

Also, maybe this is out of scope for this PR, but this makes me immediately want equivalent functions for Float() and String() and Bool(). @TylerHelmuth thoughts?

I'm going to approve because I don't think either of these is a blocker.

case int64:
return value
case string:
intValue, err := strconv.ParseInt(value, 10, 64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we were to specify 0 here instead of 10, then ParseInt will:

  • handle base prefixes of 0x (hex), 0b (binary), and 0 or 0o (octal)
  • support embedded _ for spacing (like 1_000_000)

I feel like that might be useful and natural. @TylerHelmuth do you agree, or do you think that's out of scope?

@TylerHelmuth
Copy link
Member

@kentquirk ya we probably should have more casting functions, or build casting into the grammar natively.

@bogdandrutu bogdandrutu merged commit a4a6e62 into open-telemetry:main Sep 7, 2022
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.

5 participants