Skip to content

Commit

Permalink
update license and scalafmt
Browse files Browse the repository at this point in the history
Signed-off-by: YANGDB <[email protected]>
  • Loading branch information
YANG-DB committed Nov 9, 2024
1 parent fd45d52 commit 61c6bb8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class FlintSparkPPLTopAndRareITSuite
// Retrieve the results
val results: Array[Row] = frame.collect()
assert(results.length == 3)

// Retrieve the logical plan
val logicalPlan: LogicalPlan = frame.queryExecution.logical
// Define the expected logical plan
Expand All @@ -114,7 +114,10 @@ class FlintSparkPPLTopAndRareITSuite
Seq(
SortOrder(
Alias(
UnresolvedFunction(Seq("APPROX_COUNT_DISTINCT"), Seq(addressField), isDistinct = false),
UnresolvedFunction(
Seq("APPROX_COUNT_DISTINCT"),
Seq(addressField),
isDistinct = false),
"count_address")(),
Ascending)),
global = true,
Expand Down Expand Up @@ -170,7 +173,7 @@ class FlintSparkPPLTopAndRareITSuite
val expectedPlan = Project(projectList, sortedPlan)
comparePlans(expectedPlan, logicalPlan, false)
}

test("create ppl rare 3 address by age field query test") {
val frame = sql(s"""
| source = $testTable| rare 3 address by age
Expand Down Expand Up @@ -220,7 +223,7 @@ class FlintSparkPPLTopAndRareITSuite
val expectedPlan = Project(Seq(UnresolvedStar(None)), planWithLimit)
comparePlans(expectedPlan, logicalPlan, false)
}

test("create ppl rare 3 address by age field query test with approximation") {
val frame = sql(s"""
| source = $testTable| rare_approx 3 address by age
Expand All @@ -230,7 +233,6 @@ class FlintSparkPPLTopAndRareITSuite
val results: Array[Row] = frame.collect()
assert(results.length == 3)


// Retrieve the logical plan
val logicalPlan: LogicalPlan = frame.queryExecution.logical
val addressField = UnresolvedAttribute("address")
Expand All @@ -255,7 +257,10 @@ class FlintSparkPPLTopAndRareITSuite
Seq(
SortOrder(
Alias(
UnresolvedFunction(Seq("APPROX_COUNT_DISTINCT"), Seq(addressField), isDistinct = false),
UnresolvedFunction(
Seq("APPROX_COUNT_DISTINCT"),
Seq(addressField),
isDistinct = false),
"count_address")(),
Ascending)),
global = true,
Expand Down Expand Up @@ -313,7 +318,7 @@ class FlintSparkPPLTopAndRareITSuite
val expectedPlan = Project(projectList, sortedPlan)
comparePlans(expectedPlan, logicalPlan, checkAnalysis = false)
}

test("create ppl top address field query test with approximation") {
val frame = sql(s"""
| source = $testTable| top_approx address
Expand All @@ -323,7 +328,6 @@ class FlintSparkPPLTopAndRareITSuite
val results: Array[Row] = frame.collect()
assert(results.length == 3)


// Retrieve the logical plan
val logicalPlan: LogicalPlan = frame.queryExecution.logical
// Define the expected logical plan
Expand All @@ -345,7 +349,10 @@ class FlintSparkPPLTopAndRareITSuite
Seq(
SortOrder(
Alias(
UnresolvedFunction(Seq("APPROX_COUNT_DISTINCT"), Seq(addressField), isDistinct = false),
UnresolvedFunction(
Seq("APPROX_COUNT_DISTINCT"),
Seq(addressField),
isDistinct = false),
"count_address")(),
Descending)),
global = true,
Expand Down Expand Up @@ -400,7 +407,7 @@ class FlintSparkPPLTopAndRareITSuite
val expectedPlan = Project(Seq(UnresolvedStar(None)), planWithLimit)
comparePlans(expectedPlan, logicalPlan, checkAnalysis = false)
}

test("create ppl top 3 countries query test with approximation") {
val frame = sql(s"""
| source = $newTestTable| top_approx 3 country
Expand All @@ -409,7 +416,7 @@ class FlintSparkPPLTopAndRareITSuite
// Retrieve the results
val results: Array[Row] = frame.collect()
assert(results.length == 3)

// Retrieve the logical plan
val logicalPlan: LogicalPlan = frame.queryExecution.logical
val countryField = UnresolvedAttribute("country")
Expand All @@ -428,7 +435,10 @@ class FlintSparkPPLTopAndRareITSuite
Seq(
SortOrder(
Alias(
UnresolvedFunction(Seq("APPROX_COUNT_DISTINCT"), Seq(countryField), isDistinct = false),
UnresolvedFunction(
Seq("APPROX_COUNT_DISTINCT"),
Seq(countryField),
isDistinct = false),
"count_country")(),
Descending)),
global = true,
Expand Down Expand Up @@ -491,7 +501,7 @@ class FlintSparkPPLTopAndRareITSuite
comparePlans(expectedPlan, logicalPlan, checkAnalysis = false)

}

test("create ppl top 2 countries by occupation field query test with approximation") {
val frame = sql(s"""
| source = $newTestTable| top_approx 3 country by occupation
Expand Down Expand Up @@ -522,7 +532,10 @@ class FlintSparkPPLTopAndRareITSuite
Seq(
SortOrder(
Alias(
UnresolvedFunction(Seq("APPROX_COUNT_DISTINCT"), Seq(countryField), isDistinct = false),
UnresolvedFunction(
Seq("APPROX_COUNT_DISTINCT"),
Seq(countryField),
isDistinct = false),
"count_country")(),
Descending)),
global = true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
package org.opensearch.sql.ast.tree;

import org.opensearch.sql.ast.expression.Literal;

import java.util.Optional;

/**
* marker interface for numeric based count aggregation (specific number of returned results)
*/
public interface CountedAggregation {
Optional<Literal> getResults();
}
Original file line number Diff line number Diff line change
Expand Up @@ -753,11 +753,13 @@ class PPLLogicalPlanAggregationQueriesTranslatorTestSuite

comparePlans(expectedPlan, logPlan, false)
}

test("test approx distinct count product group by brand sorted") {
val context = new CatalystPlanContext
val logPlan = planTransformer.visit(
plan(pplParser, "source = table | stats distinct_count_approx(product) by brand | sort brand"),
plan(
pplParser,
"source = table | stats distinct_count_approx(product) by brand | sort brand"),
context)
val star = Seq(UnresolvedStar(None))
val brandField = UnresolvedAttribute("brand")
Expand Down Expand Up @@ -828,8 +830,9 @@ class PPLLogicalPlanAggregationQueriesTranslatorTestSuite

comparePlans(expectedPlan, logPlan, false)
}

test("test distinct count age by span of interval of 10 years query with sort using approximation ") {

test(
"test distinct count age by span of interval of 10 years query with sort using approximation ") {
val context = new CatalystPlanContext
val logPlan = planTransformer.visit(
plan(
Expand Down Expand Up @@ -890,8 +893,9 @@ class PPLLogicalPlanAggregationQueriesTranslatorTestSuite
// Compare the two plans
comparePlans(expectedPlan, logPlan, false)
}

test("test distinct count status by week window and group by status with limit using approximation") {

test(
"test distinct count status by week window and group by status with limit using approximation") {
val context = new CatalystPlanContext
val logPlan = planTransformer.visit(
plan(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class PPLLogicalPlanTopAndRareQueriesTranslatorTestSuite
val expectedPlan = Project(projectList, sortedPlan)
comparePlans(expectedPlan, logPlan, checkAnalysis = false)
}

test("test simple rare command with a single field approximation") {
// if successful build ppl logical plan and translate to catalyst logical plan
val context = new CatalystPlanContext
Expand All @@ -83,7 +83,10 @@ class PPLLogicalPlanTopAndRareQueriesTranslatorTestSuite
Seq(
SortOrder(
Alias(
UnresolvedFunction(Seq("APPROX_COUNT_DISTINCT"), Seq(addressField), isDistinct = false),
UnresolvedFunction(
Seq("APPROX_COUNT_DISTINCT"),
Seq(addressField),
isDistinct = false),
"count_address")(),
Ascending)),
global = true,
Expand Down

0 comments on commit 61c6bb8

Please sign in to comment.