Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Kwok <[email protected]>
  • Loading branch information
andy-k-improving committed Nov 14, 2024
1 parent b6d356d commit 2b61f4c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ package org.opensearch.flint.spark.ppl

import org.opensearch.sql.ppl.utils.DataTypeTransformer.seq
import org.opensearch.sql.ppl.utils.SortUtils
import org.scalatest.matchers.should.Matchers.{a, convertToAnyShouldWrapper}

import org.apache.spark.sql.{QueryTest, Row}
import org.apache.spark.sql.catalyst.analysis.{UnresolvedAttribute, UnresolvedFunction, UnresolvedRelation, UnresolvedStar}
import org.apache.spark.sql.catalyst.expressions.{Add, Alias, Ascending, CaseWhen, CurrentRow, Descending, Divide, Expression, LessThan, Literal, Multiply, RowFrame, SortOrder, SpecifiedWindowFrame, WindowExpression, WindowSpecDefinition}
import org.apache.spark.sql.catalyst.parser.ParseException
import org.apache.spark.sql.catalyst.plans.logical._
import org.apache.spark.sql.streaming.StreamTest

Expand Down Expand Up @@ -483,6 +485,13 @@ class FlintSparkPPLTrendlineITSuite

}

test("test invalid wma command with negative dataPoint value") {
val exception = intercept[ParseException](sql(s"""
| source = $testTable | trendline sort + age wma(-3, age)
| """.stripMargin))
assert(exception.getMessage contains "[PARSE_SYNTAX_ERROR] Syntax error")
}

private def getNthValueAggregation(
dataField: String,
sortField: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.opensearch.flint.spark.ppl

import org.opensearch.flint.spark.ppl.PlaneUtils.plan
import org.opensearch.sql.common.antlr.SyntaxCheckException
import org.opensearch.sql.ppl.{CatalystPlanContext, CatalystQueryPlanVisitor}
import org.opensearch.sql.ppl.utils.DataTypeTransformer.seq
import org.opensearch.sql.ppl.utils.SortUtils
Expand Down Expand Up @@ -251,6 +252,14 @@ class PPLLogicalPlanTrendlineCommandTranslatorTestSuite

}

test("WMA - with negative dataPoint value") {
val context = new CatalystPlanContext
val exception = intercept[SyntaxCheckException](
planTransformer
.visit(plan(pplParser, "source=relation | trendline sort age wma(-3, age)"), context))
assert(exception.getMessage startsWith "Failed to parse query due to offending symbol [-]")
}

private def getNthValueAggregation(
dataField: String,
sortField: String,
Expand Down

0 comments on commit 2b61f4c

Please sign in to comment.