-
Notifications
You must be signed in to change notification settings - Fork 0
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
Pagination, phase 1: Add unit tests for :core
module with coverage.
#230
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
package org.opensearch.sql.executor.execution; | ||
|
||
import org.apache.commons.lang3.NotImplementedException; | ||
import org.opensearch.sql.ast.tree.Paginate; | ||
import org.opensearch.sql.ast.tree.UnresolvedPlan; | ||
import org.opensearch.sql.common.response.ResponseListener; | ||
|
@@ -38,8 +39,9 @@ public void execute() { | |
} | ||
|
||
@Override | ||
// TODO why can't use listener given in the constructor? | ||
public void explain(ResponseListener<ExecutionEngine.ExplainResponse> listener) { | ||
listener.onFailure(new UnsupportedOperationException( | ||
listener.onFailure(new NotImplementedException( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why change from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to comply with nature of these exceptions. Explain for |
||
"`explain` feature for paginated requests is not implemented yet.")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,11 +46,7 @@ public void executePlan(LogicalPlan plan, | |
*/ | ||
public void executePlan(PhysicalPlan plan, | ||
ResponseListener<ExecutionEngine.QueryResponse> listener) { | ||
try { | ||
executionEngine.execute(plan, ExecutionContext.emptyExecutionContext(), listener); | ||
} catch (Exception e) { | ||
listener.onFailure(e); | ||
} | ||
executionEngine.execute(plan, ExecutionContext.emptyExecutionContext(), listener); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was the try-catch block removed? Was something changed so that we don't expect this to throw an exception anymore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
public LogicalPlan analyze(UnresolvedPlan plan) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.executor; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static org.mockito.Mockito.withSettings; | ||
|
||
import java.util.List; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator; | ||
import org.junit.jupiter.api.Test; | ||
import org.opensearch.sql.ast.dsl.AstDSL; | ||
import org.opensearch.sql.ast.tree.Project; | ||
import org.opensearch.sql.ast.tree.Relation; | ||
|
||
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) | ||
public class CanPaginateVisitorTest { | ||
|
||
static final CanPaginateVisitor visitor = new CanPaginateVisitor(); | ||
|
||
@Test | ||
// select * from y | ||
public void accept_query_with_select_star_and_from() { | ||
var plan = AstDSL.project(AstDSL.relation("dummy"), AstDSL.allFields()); | ||
assertTrue(plan.accept(visitor, null)); | ||
} | ||
|
||
@Test | ||
// select x from y | ||
public void reject_query_with_select_field_and_from() { | ||
var plan = AstDSL.project(AstDSL.relation("dummy"), AstDSL.field("pewpew")); | ||
assertFalse(plan.accept(visitor, null)); | ||
} | ||
|
||
@Test | ||
// select x,z from y | ||
public void reject_query_with_select_fields_and_from() { | ||
var plan = AstDSL.project(AstDSL.relation("dummy"), | ||
AstDSL.field("pewpew"), AstDSL.field("pewpew")); | ||
assertFalse(plan.accept(visitor, null)); | ||
} | ||
|
||
@Test | ||
// select x | ||
public void reject_query_without_from() { | ||
var plan = AstDSL.project(AstDSL.values(List.of(AstDSL.intLiteral(1))), | ||
AstDSL.alias("1",AstDSL.intLiteral(1))); | ||
assertFalse(plan.accept(visitor, null)); | ||
} | ||
|
||
@Test | ||
// select * from y limit z | ||
public void reject_query_with_limit() { | ||
var plan = AstDSL.project(AstDSL.limit(AstDSL.relation("dummy"), 1, 2), AstDSL.allFields()); | ||
assertFalse(plan.accept(visitor, null)); | ||
} | ||
|
||
@Test | ||
// select * from y where z | ||
public void reject_query_with_where() { | ||
var plan = AstDSL.project(AstDSL.filter(AstDSL.relation("dummy"), | ||
AstDSL.booleanLiteral(true)), AstDSL.allFields()); | ||
assertFalse(plan.accept(visitor, null)); | ||
} | ||
|
||
@Test | ||
// select * from y order by z | ||
public void reject_query_with_order_by() { | ||
var plan = AstDSL.project(AstDSL.sort(AstDSL.relation("dummy"), AstDSL.field("1")), | ||
AstDSL.allFields()); | ||
assertFalse(plan.accept(visitor, null)); | ||
} | ||
|
||
@Test | ||
// select * from y group by z | ||
public void reject_query_with_group_by() { | ||
var plan = AstDSL.project(AstDSL.agg( | ||
AstDSL.relation("dummy"), List.of(), List.of(), List.of(AstDSL.field("1")), List.of()), | ||
AstDSL.allFields()); | ||
assertFalse(plan.accept(visitor, null)); | ||
} | ||
|
||
@Test | ||
// select agg(x) from y | ||
public void reject_query_with_aggregation_function() { | ||
var plan = AstDSL.project(AstDSL.agg( | ||
AstDSL.relation("dummy"), | ||
List.of(AstDSL.alias("agg", AstDSL.aggregate("func", AstDSL.field("pewpew")))), | ||
List.of(), List.of(), List.of()), | ||
AstDSL.allFields()); | ||
assertFalse(plan.accept(visitor, null)); | ||
} | ||
|
||
@Test | ||
// select window(x) from y | ||
public void reject_query_with_window_function() { | ||
var plan = AstDSL.project(AstDSL.relation("dummy"), | ||
AstDSL.alias("pewpew", | ||
AstDSL.window( | ||
AstDSL.aggregate("func", AstDSL.field("pewpew")), | ||
List.of(AstDSL.qualifiedName("1")), List.of()))); | ||
assertFalse(plan.accept(visitor, null)); | ||
} | ||
|
||
@Test | ||
// select * from y, z | ||
public void reject_query_with_select_from_multiple_indices() { | ||
var plan = mock(Project.class); | ||
when(plan.getChild()).thenReturn(List.of(AstDSL.relation("dummy"), AstDSL.relation("pummy"))); | ||
when(plan.getProjectList()).thenReturn(List.of(AstDSL.allFields())); | ||
assertFalse(visitor.visitProject(plan, null)); | ||
} | ||
|
||
@Test | ||
// unreal case, added for coverage only | ||
public void reject_project_when_relation_has_child() { | ||
var relation = mock(Relation.class, withSettings().useConstructor(AstDSL.qualifiedName("42"))); | ||
when(relation.getChild()).thenReturn(List.of(AstDSL.relation("pewpew"))); | ||
when(relation.accept(visitor, null)).thenCallRealMethod(); | ||
var plan = mock(Project.class); | ||
when(plan.getChild()).thenReturn(List.of(relation)); | ||
when(plan.getProjectList()).thenReturn(List.of(AstDSL.allFields())); | ||
assertFalse(visitor.visitProject((Project) plan, null)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is canPaginate not used anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is used in commented code below only.