Class ParseIp
java.lang.Object
org.elasticsearch.xpack.esql.expression.function.scalar.convert.ParseIp
Fast IP parsing suitable for embedding in an
EvalOperator.ExpressionEvaluator
because they don't allocate memory on every run. Instead, it converts directly from
utf-8 encoded strings into InetAddressPoint encoded ips.
This contains three parsing methods to handle the three ways ipv4 addresses
have historically handled leading 0s, namely, reject them,
treat them as decimal numbers, and treat them as
leadingZerosAreOctal(org.apache.lucene.util.BytesRef, org.elasticsearch.compute.operator.BreakingBytesRefBuilder) numbers.
Note: We say "directly from utf-8" but, really, all of the digits in an ip are in the traditional 7-bit ascii range where utf-8 overlaps. So we just treat everything as 7-bit ascii. Anything that isn't in the range is an invalid ip anyway. Much love for the designers of utf-8 for making it this way.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BreakingBytesRefBuilderbuildScratch(CircuitBreaker breaker) static org.apache.lucene.util.BytesRefleadingZerosAreDecimal(org.apache.lucene.util.BytesRef string, BreakingBytesRefBuilder scratch) Parse an IP address, interpreting v4 addresses with leading 0s as decimal numbers.static org.apache.lucene.util.BytesRefleadingZerosAreOctal(org.apache.lucene.util.BytesRef string, BreakingBytesRefBuilder scratch) Parse an IP address, interpreting v4 addresses with leading 0s as octal numbers.static org.apache.lucene.util.BytesRefleadingZerosRejected(org.apache.lucene.util.BytesRef string, BreakingBytesRefBuilder scratch) Parse an IP address, rejecting v4 addresses with leading 0s.
-
Constructor Details
-
ParseIp
public ParseIp()
-
-
Method Details
-
buildScratch
-
leadingZerosRejected
public static org.apache.lucene.util.BytesRef leadingZerosRejected(org.apache.lucene.util.BytesRef string, BreakingBytesRefBuilder scratch) Parse an IP address, rejecting v4 addresses with leading 0s. This aligns exactly withInetAddresses.forString(String).- 192.168.1.1 : valid
- 192.168.0.1 : valid
- 192.168.01.1 : invalid
- Parameters:
scratch- A "scratch" memory space build bybuildScratch(org.elasticsearch.common.breaker.CircuitBreaker)
-
leadingZerosAreDecimal
public static org.apache.lucene.util.BytesRef leadingZerosAreDecimal(org.apache.lucene.util.BytesRef string, BreakingBytesRefBuilder scratch) Parse an IP address, interpreting v4 addresses with leading 0s as decimal numbers.- 192.168.1.1 : valid
- 192.168.0.1 : valid
- 192.168.01.1 : valid
- 192.168.09.1 : valid
- 192.168.010.1 : valid
- Parameters:
scratch- A "scratch" memory space build bybuildScratch(org.elasticsearch.common.breaker.CircuitBreaker)
-
leadingZerosAreOctal
public static org.apache.lucene.util.BytesRef leadingZerosAreOctal(org.apache.lucene.util.BytesRef string, BreakingBytesRefBuilder scratch) Parse an IP address, interpreting v4 addresses with leading 0s as octal numbers.- 192.168.1.1 : valid
- 192.168.0.1 : valid
- 192.168.01.1 : valid
- 192.168.09.1 : invalid
- 192.168.010.1 : valid but would print as 192.168.8.1
- Parameters:
scratch- A "scratch" memory space build bybuildScratch(org.elasticsearch.common.breaker.CircuitBreaker)
-