-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into issues/838
- Loading branch information
Showing
21 changed files
with
491 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
## PPL IP Address Functions | ||
|
||
### `CIDRMATCH` | ||
|
||
**Description** | ||
|
||
`CIDRMATCH(ip, cidr)` checks if ip is within the specified cidr range. | ||
|
||
**Argument type:** | ||
- STRING, STRING | ||
- Return type: **BOOLEAN** | ||
|
||
Example: | ||
|
||
os> source=ips | where cidrmatch(ip, '192.169.1.0/24') | fields ip | ||
fetched rows / total rows = 1/1 | ||
+--------------+ | ||
| ip | | ||
|--------------| | ||
| 192.169.1.5 | | ||
+--------------+ | ||
|
||
os> source=ipsv6 | where cidrmatch(ip, '2003:db8::/32') | fields ip | ||
fetched rows / total rows = 1/1 | ||
+-----------------------------------------+ | ||
| ip | | ||
|-----------------------------------------| | ||
| 2003:0db8:0000:0000:0000:0000:0000:0000 | | ||
+-----------------------------------------+ | ||
|
||
Note: | ||
- `ip` can be an IPv4 or an IPv6 address | ||
- `cidr` can be an IPv4 or an IPv6 block | ||
- `ip` and `cidr` must be either both IPv4 or both IPv6 | ||
- `ip` and `cidr` must both be valid and non-empty/non-null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...t/java/org/opensearch/flint/core/metadata/log/DefaultOptimisticTransactionMetricTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.core.metadata.log; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.opensearch.flint.common.metadata.log.FlintMetadataLog; | ||
import org.opensearch.flint.common.metadata.log.FlintMetadataLogEntry; | ||
|
||
import java.util.Optional; | ||
import org.opensearch.flint.common.metadata.log.FlintMetadataLogEntry.IndexState$; | ||
import org.opensearch.flint.core.metrics.MetricsTestUtil; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class DefaultOptimisticTransactionMetricTest { | ||
|
||
@Mock | ||
private FlintMetadataLog<FlintMetadataLogEntry> metadataLog; | ||
|
||
@Mock | ||
private FlintMetadataLogEntry logEntry; | ||
|
||
@InjectMocks | ||
private DefaultOptimisticTransaction<String> transaction; | ||
|
||
@Test | ||
void testCommitWithValidInitialCondition() throws Exception { | ||
MetricsTestUtil.withMetricEnv(verifier -> { | ||
when(metadataLog.getLatest()).thenReturn(Optional.of(logEntry)); | ||
when(metadataLog.add(any(FlintMetadataLogEntry.class))).thenReturn(logEntry); | ||
when(logEntry.state()).thenReturn(IndexState$.MODULE$.ACTIVE()); | ||
|
||
transaction.initialLog(entry -> true) | ||
.transientLog(entry -> logEntry) | ||
.finalLog(entry -> logEntry) | ||
.commit(entry -> "Success"); | ||
|
||
verify(metadataLog, times(2)).add(logEntry); | ||
verifier.assertHistoricGauge("indexState.updatedTo.active.count", 1); | ||
}); | ||
} | ||
|
||
@Test | ||
void testConditionCheckFailed() throws Exception { | ||
MetricsTestUtil.withMetricEnv(verifier -> { | ||
when(metadataLog.getLatest()).thenReturn(Optional.of(logEntry)); | ||
when(logEntry.state()).thenReturn(IndexState$.MODULE$.DELETED()); | ||
|
||
transaction.initialLog(entry -> false) | ||
.finalLog(entry -> logEntry); | ||
|
||
assertThrows(IllegalStateException.class, () -> { | ||
transaction.commit(entry -> "Should Fail"); | ||
}); | ||
verifier.assertHistoricGauge("initialConditionCheck.failed.deleted.count", 1); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
.../src/integration/scala/org/opensearch/flint/spark/ppl/FlintSparkPPLCidrmatchITSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.spark.ppl | ||
|
||
import org.apache.spark.SparkException | ||
import org.apache.spark.sql.QueryTest | ||
import org.apache.spark.sql.streaming.StreamTest | ||
|
||
class FlintSparkPPLCidrmatchITSuite | ||
extends QueryTest | ||
with LogicalPlanTestUtils | ||
with FlintPPLSuite | ||
with StreamTest { | ||
|
||
/** Test table and index name */ | ||
private val testTable = "spark_catalog.default.flint_ppl_test" | ||
|
||
override def beforeAll(): Unit = { | ||
super.beforeAll() | ||
|
||
// Create test table | ||
createIpAddressTable(testTable) | ||
} | ||
|
||
protected override def afterEach(): Unit = { | ||
super.afterEach() | ||
// Stop all streaming jobs if any | ||
spark.streams.active.foreach { job => | ||
job.stop() | ||
job.awaitTermination() | ||
} | ||
} | ||
|
||
test("test cidrmatch for ipv4 for 192.168.1.0/24") { | ||
val frame = sql(s""" | ||
| source = $testTable | where isV6 = false and isValid = true and cidrmatch(ipAddress, '192.168.1.0/24') | ||
| """.stripMargin) | ||
|
||
val results = frame.collect() | ||
assert(results.length == 2) | ||
} | ||
|
||
test("test cidrmatch for ipv4 for 192.169.1.0/24") { | ||
val frame = sql(s""" | ||
| source = $testTable | where isV6 = false and isValid = true and cidrmatch(ipAddress, '192.169.1.0/24') | ||
| """.stripMargin) | ||
|
||
val results = frame.collect() | ||
assert(results.length == 0) | ||
} | ||
|
||
test("test cidrmatch for ipv6 for 2001:db8::/32") { | ||
val frame = sql(s""" | ||
| source = $testTable | where isV6 = true and isValid = true and cidrmatch(ipAddress, '2001:db8::/32') | ||
| """.stripMargin) | ||
|
||
val results = frame.collect() | ||
assert(results.length == 3) | ||
} | ||
|
||
test("test cidrmatch for ipv6 for 2003:db8::/32") { | ||
val frame = sql(s""" | ||
| source = $testTable | where isV6 = true and isValid = true and cidrmatch(ipAddress, '2003:db8::/32') | ||
| """.stripMargin) | ||
|
||
val results = frame.collect() | ||
assert(results.length == 0) | ||
} | ||
|
||
test("test cidrmatch for ipv6 with ipv4 cidr") { | ||
val frame = sql(s""" | ||
| source = $testTable | where isV6 = true and isValid = true and cidrmatch(ipAddress, '192.169.1.0/24') | ||
| """.stripMargin) | ||
|
||
assertThrows[SparkException](frame.collect()) | ||
} | ||
|
||
test("test cidrmatch for invalid ipv4 addresses") { | ||
val frame = sql(s""" | ||
| source = $testTable | where isV6 = false and isValid = false and cidrmatch(ipAddress, '192.169.1.0/24') | ||
| """.stripMargin) | ||
|
||
assertThrows[SparkException](frame.collect()) | ||
} | ||
|
||
test("test cidrmatch for invalid ipv6 addresses") { | ||
val frame = sql(s""" | ||
| source = $testTable | where isV6 = true and isValid = false and cidrmatch(ipAddress, '2003:db8::/32') | ||
| """.stripMargin) | ||
|
||
assertThrows[SparkException](frame.collect()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.