-
Notifications
You must be signed in to change notification settings - Fork 25.2k
ESQL: TO_IP can handle leading zeros #126294
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
Conversation
Hi @nik9000, I've created a changelog YAML for you. |
@@ -33,6 +33,7 @@ base { | |||
dependencies { | |||
compileOnly project(path: xpackModule('core')) | |||
compileOnly project(':modules:lang-painless:spi') | |||
compileOnly project(':libs:simdvec') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a leftover.
) }, | ||
description = "(Optional) Additional options.", | ||
optional = true | ||
) Expression options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fang-xing-esql could you tell me if this is a sane idea? Or should I just make two more functions instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fang-xing-esql could you tell me if this is a sane idea? Or should I just make two more functions instead?
It looks fine to me to extend to_ip, instead of making more functions. :)
public class ParseIp { | ||
private static final byte[] IPV4_PREFIX = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1 }; | ||
|
||
@ConvertEvaluator(extraName = "LeadingZerosRejected", warnExceptions = { IllegalArgumentException.class }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to extract these to a separate PR because the leadingZerosRejected
version can be used even in older versions of Elasticsearch. I can backport that PR to 9.0 and 8.19.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @nik9000! I left a comment related to the format of entries in a MapExpression
.
return new TypeResolution("map keys must be strings"); | ||
} | ||
if (e.key() instanceof Literal keyl) { | ||
key = (BytesRef) keyl.value(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key
and value
of an entry in the MapExpression
can be either a String
or BytesRef
, depending on when resolveType()
is called. If it is called by Analyzer
, they are in (human readable)String
format, if it is called by LogicalPlanOptimizer
, they might be in BytesRef
.
Having some CsvTests
should expose the different format, after the interface of to_ip
is finalized.
Superseded by #126532 |
Modifies TO_IP so it can handle leading
0
s in ipv4s. It's not done, but the goal is to keep the current behavior:But to allow
I didn't manage to plug in the map arguments properly - and I'm not entirely sure this is the right thing to do with
TO_IP
anyway. So this is a draft. There's some change we say that we needTO_IP_LEADING_ZEROS_OCTAL
andTO_IP_LEADING_ZEROS_DECIMAL
instead of using named parameters. That's becauseTO_IP
is a conversion function which is sort of defined as being unary - and adding theoptions
to it breaks that contract.