forked from opensearch-project/opensearch-spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: YANGDB <[email protected]>
- Loading branch information
Showing
8 changed files
with
200 additions
and
32 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
39 changes: 39 additions & 0 deletions
39
ppl-spark-integration/src/main/java/org/opensearch/sql/ast/tree/Correlation.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,39 @@ | ||
package org.opensearch.sql.ast.tree; | ||
|
||
import org.opensearch.flint.spark.ppl.OpenSearchPPLParser; | ||
import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
|
||
import java.util.List; | ||
|
||
/** Logical plan node of correlation , the interface for building the searching sources. */ | ||
|
||
public class Correlation extends UnresolvedPlan { | ||
private final CorrelationType correlationTypeContext; | ||
private final List<OpenSearchPPLParser.FieldExpressionContext> fieldExpression; | ||
private final OpenSearchPPLParser.ScopeClauseContext contextParamContext; | ||
private final OpenSearchPPLParser.MappingListContext mappingListContext; | ||
private UnresolvedPlan child; | ||
public Correlation(OpenSearchPPLParser.CorrelationTypeContext correlationTypeContext, OpenSearchPPLParser.FieldListContext fieldListContext, OpenSearchPPLParser.ScopeClauseContext contextParamContext, OpenSearchPPLParser.MappingListContext mappingListContext) { | ||
this.correlationTypeContext = CorrelationType.valueOf(correlationTypeContext.getText()); | ||
this.fieldExpression = fieldListContext.fieldExpression(); | ||
this.contextParamContext = contextParamContext; | ||
this.mappingListContext = mappingListContext; | ||
} | ||
|
||
@Override | ||
public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) { | ||
return nodeVisitor.visitCorrelation(this, context); | ||
} | ||
|
||
@Override | ||
public Correlation attach(UnresolvedPlan child) { | ||
this.child = child; | ||
return this; | ||
} | ||
|
||
enum CorrelationType { | ||
exact, | ||
approximate | ||
} | ||
|
||
} |
30 changes: 0 additions & 30 deletions
30
ppl-spark-integration/src/main/java/org/opensearch/sql/ast/tree/JoinClause.java
This file was deleted.
Oops, something went wrong.
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
46 changes: 46 additions & 0 deletions
46
.../org/opensearch/flint/spark/ppl/PPLLogicalPlanCorrelationQueriesTranslatorTestSuite.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,46 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.spark.ppl | ||
|
||
import org.apache.spark.SparkFunSuite | ||
import org.apache.spark.sql.catalyst.analysis.{UnresolvedAttribute, UnresolvedRelation, UnresolvedStar} | ||
import org.apache.spark.sql.catalyst.expressions.{Ascending, Descending, Literal, NamedExpression, SortOrder} | ||
import org.apache.spark.sql.catalyst.plans.logical._ | ||
import org.junit.Assert.assertEquals | ||
import org.opensearch.flint.spark.ppl.PlaneUtils.plan | ||
import org.opensearch.sql.ppl.{CatalystPlanContext, CatalystQueryPlanVisitor} | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class PPLLogicalPlanCorrelationQueriesTranslatorTestSuite | ||
extends SparkFunSuite | ||
with LogicalPlanTestUtils | ||
with Matchers { | ||
|
||
private val planTrnasformer = new CatalystQueryPlanVisitor() | ||
private val pplParser = new PPLSyntaxParser() | ||
|
||
|
||
test("Search multiple tables with correlation - translated into join call with fields") { | ||
val context = new CatalystPlanContext | ||
val query = "source = table1, table2 | where @timestamp=`2018-07-02T22:23:00` AND ip=`10.0.0.1` AND cloud.provider=`aws` | correlate exact fields(ip, port) scope(@timestamp, 1d)" + | ||
" mapping( alb_logs.ip = traces.source_ip, alb_logs.port = metrics.target_port )" | ||
val logPlan = planTrnasformer.visit(plan(pplParser, query, false), context) | ||
|
||
val table1 = UnresolvedRelation(Seq("table1")) | ||
val table2 = UnresolvedRelation(Seq("table2")) | ||
|
||
val allFields1 = UnresolvedStar(None) | ||
val allFields2 = UnresolvedStar(None) | ||
|
||
val projectedTable1 = Project(Seq(allFields1), table1) | ||
val projectedTable2 = Project(Seq(allFields2), table2) | ||
|
||
val expectedPlan = | ||
Union(Seq(projectedTable1, projectedTable2), byName = true, allowMissingCol = true) | ||
|
||
assertEquals(expectedPlan, logPlan) | ||
} | ||
} |