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

enhancement(remap): improved type definitions for or with nullable fields #6462

Merged
merged 3 commits into from
Feb 17, 2021

Conversation

StephenWakely
Copy link
Contributor

Replacing #6344 - I've updated it to work with the recent parser changes.

Following from #6182, a number of functions return fields that can be Null, for example appname from parse_syslog can be Kind::Bytes | Kind::Null.

This PR makes it possible to specify a default value using Or. Since we know that if the lhs is either Null or Bytes, we can deduce that the whole expression lhs | rhs will either be the lhs - Kind::Null or the rhs.

Eg. This now typechecks:

.parsed = parse_syslog(.message)
.sha = sha3(.parsed.appname || "default")

However this will still not typecheck, the procid field can be either a string, an integer or null. So even after an Or it could still be an Integer or a String.:

.parsed = parse_syslog(.message)
.sha = sha3(.parsed.procid || "default")

Signed-off-by: Stephen Wakely [email protected]

@StephenWakely StephenWakely requested review from a team and ktff and removed request for a team February 16, 2021 21:14
@StephenWakely StephenWakely requested review from JeanMertz and removed request for ktff February 16, 2021 21:51
Signed-off-by: Stephen Wakely <[email protected]>
Copy link
Contributor

@JeanMertz JeanMertz left a comment

Choose a reason for hiding this comment

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

Sweet! Left a few comments, but otherwise this looks good to go.

lib/vrl/compiler/src/expression/op.rs Outdated Show resolved Hide resolved
lib/vrl/compiler/src/expression/op.rs Outdated Show resolved Hide resolved
lib/vrl/compiler/src/expression/op.rs Outdated Show resolved Hide resolved
lib/vrl/compiler/src/type_def.rs Outdated Show resolved Hide resolved
lib/vrl/compiler/src/type_def.rs Outdated Show resolved Hide resolved
lib/vrl/compiler/src/type_def.rs Outdated Show resolved Hide resolved
@StephenWakely StephenWakely merged commit 25e9e5e into master Feb 17, 2021
@StephenWakely StephenWakely deleted the remap_or_type_def2 branch February 17, 2021 13:57
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.

2 participants