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

[WIP] FEAT(3038): iplocation command #3085

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pitest {
}

dependencies {
implementation "org.opensearch:opensearch-geospatial-spi:${opensearch_build}"
Copy link

Choose a reason for hiding this comment

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

I don't see why core needs to depend on geospatial.


api group: 'com.google.guava', name: 'guava', version: "${guava_version}"
api group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
api group: 'org.apache.commons', name: 'commons-text', version: '1.10.0'
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/org/opensearch/sql/expression/DSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,14 @@ public static FunctionExpression lte(Expression... expressions) {
return lte(FunctionProperties.None, expressions);
}

public static FunctionExpression geoip(FunctionProperties fp, Expression... expressions) {
return compile(fp, BuiltinFunctionName.GEOIP, expressions);
}

public static FunctionExpression geoip(Expression... expressions) {
return geoip(FunctionProperties.None, expressions);
}

public static FunctionExpression greater(FunctionProperties fp, Expression... expressions) {
return compile(fp, BuiltinFunctionName.GREATER, expressions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,11 @@ public enum BuiltinFunctionName {
MULTIMATCH(FunctionName.of("multimatch")),
MULTIMATCHQUERY(FunctionName.of("multimatchquery")),
WILDCARDQUERY(FunctionName.of("wildcardquery")),
WILDCARD_QUERY(FunctionName.of("wildcard_query"));
WILDCARD_QUERY(FunctionName.of("wildcard_query")),

/** Geospatial Function. */
GEOIP(FunctionName.of("geoip")),
IPLOCATION(FunctionName.of("iplocation"));

private final FunctionName name;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.opensearch.sql.expression.geospatial;

import static org.opensearch.sql.expression.function.FunctionDSL.define;
import static org.opensearch.sql.expression.function.FunctionDSL.impl;

import lombok.Builder;
import lombok.experimental.UtilityClass;
import org.opensearch.geospatial.spl
import org.opensearch.sql.expression.function.BuiltinFunctionName;
import org.opensearch.sql.expression.function.BuiltinFunctionRepository;
import org.opensearch.sql.expression.function.DefaultFunctionResolver;
import org.opensearch.sql.expression.function.FunctionName;

@UtilityClass
public class GeospatialFunction {
/**
* Register Geospatial Functions.
*
* @param repository {@link BuiltinFunctionRepository}.
*/
public void register(BuiltinFunctionRepository repository) {
repository.register(geoip());
}

private DefaultFunctionResolver geoipIplocation(FunctionName functionName) {
return define(
functionName,
impl(
,
STRING,
STRING
)
);
}

private DefaultFunctionResolver geoip() {
return geoipIplocation(BuiltinFunctionName.GEOIP.getName());
}

private DefaultFunctionResolver iplocation() {
return geoipIplocation(BuiltinFunctionName.IPLOCATION.getName());
}
}
22 changes: 21 additions & 1 deletion plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ opensearchplugin {
name 'opensearch-sql'
description 'OpenSearch SQL'
classname 'org.opensearch.sql.plugin.SQLPlugin'
extendedPlugins = ['opensearch-job-scheduler']
extendedPlugins = ['opensearch-job-scheduler', 'opensearch-geospatial']
licenseFile rootProject.file("LICENSE.txt")
noticeFile rootProject.file("NOTICE")
}
Expand Down Expand Up @@ -149,6 +149,7 @@ spotless {

dependencies {
compileOnly "org.opensearch:opensearch-job-scheduler-spi:${opensearch_build}"
compileOnly "org.opensearch:opensearch-geospatial-spi:${opensearch_build}"
compileOnly "com.google.guava:guava:${guava_version}"
compileOnly 'com.google.guava:failureaccess:1.0.2'

Expand All @@ -171,6 +172,7 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.3'

zipArchive group: 'org.opensearch.plugin', name:'opensearch-job-scheduler', version: "${opensearch_build}"
zipArchive group: 'org.opensearch.plugin', name:'opensearch-geospatial', version: "${opensearch_build}"
}

test {
Expand Down Expand Up @@ -301,8 +303,26 @@ def getJobSchedulerPlugin() {
})
}

def getGeospatialPlugin() {
provider(new Callable<RegularFile>() {
@Override
RegularFile call() throws Exception {
return new RegularFile() {
@Override
File getAsFile() {
return configurations.zipArchive.asFileTree.matching {
include '**/opensearch-geospatial*'
}.singleFile
}
}
}
})

}

testClusters.integTest {
plugin(getJobSchedulerPlugin())
plugin(getGeospatialPlugin())
plugin(project.tasks.bundlePlugin.archiveFile)
testDistribution = "ARCHIVE"

Expand Down
4 changes: 4 additions & 0 deletions ppl/src/main/antlr/OpenSearchPPLLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ NULLIF: 'NULLIF';
IF: 'IF';
TYPEOF: 'TYPEOF';

// GEOSPATIAL FUNCTIONS
GEOIP: 'GEOIP';
IPLOCATION: 'IPLOCATION';

// RELEVANCE FUNCTIONS AND PARAMETERS
MATCH: 'MATCH';
MATCH_PHRASE: 'MATCH_PHRASE';
Expand Down
6 changes: 6 additions & 0 deletions ppl/src/main/antlr/OpenSearchPPLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ evalFunctionName
| flowControlFunctionName
| systemFunctionName
| positionFunctionName
| geospatialFunctionName
;

functionArgs
Expand Down Expand Up @@ -666,6 +667,11 @@ positionFunctionName
: POSITION
;

geospatialFunctionName
: GEOIP
| IPLOCATION
;

// operators
comparisonOperator
: EQUAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,4 +816,32 @@ public void testTimeStampDiffFunctionExpr() {
stringLiteral("1997-01-01 00:00:00"),
stringLiteral("2001-03-06 00:00:00")))));
}

@Test
public void testGeoIpFunctionExpr() {
assertEqual(
"source=t | eval f=geoip('127.0.0.1', 'lat,lon')",
eval(
relation("t"),
let(
field("f"),
function(
"geoip",
stringLiteral("127.0.0.1"),
stringLiteral("lat,lon")))));
}

@Test
public void testIpLocationFunctionExpr() {
assertEqual(
"source=t | eval f=iplocation('127.0.0.1', 'lat,lon')",
eval(
relation("t"),
let(
field("f"),
function(
"iplocation",
stringLiteral("127.0.0.1"),
stringLiteral("lat,lon")))));
}
}
Loading