Skip to content

Commit

Permalink
Address issues flagged by checkstyle build step (#229)
Browse files Browse the repository at this point in the history
Signed-off-by: MaxKsyunz <[email protected]>
  • Loading branch information
Max Ksyunz authored Feb 17, 2023
1 parent 02032c9 commit 11a18c1
Show file tree
Hide file tree
Showing 24 changed files with 52 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@

package org.opensearch.sql.executor;

import java.util.concurrent.atomic.AtomicBoolean;
import org.opensearch.sql.ast.AbstractNodeVisitor;
import org.opensearch.sql.ast.Node;
import org.opensearch.sql.ast.expression.AllFields;
import org.opensearch.sql.ast.tree.Filter;
import org.opensearch.sql.ast.tree.Limit;
import org.opensearch.sql.ast.tree.Project;
import org.opensearch.sql.ast.tree.Relation;
import org.opensearch.sql.ast.tree.Sort;
import org.opensearch.sql.ast.tree.Values;

import java.util.concurrent.atomic.AtomicBoolean;

/**
* Use this unresolved plan visitor to check if a plan can be serialized by PaginatedPlanCache.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,15 @@ public Cursor convertToCursor(PhysicalPlan plan) {
}
}

/**
* Compress serialized query plan.
* @param str string representing a query plan
* @return str compressed with gzip.
*/
@SneakyThrows
public static String compress(String str) {
if (str == null || str.length() == 0) {
return null;
return null;
}

ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand All @@ -70,10 +75,15 @@ public static String compress(String str) {
return HashCode.fromBytes(out.toByteArray()).toString();
}

/**
* Decompresses a query plan that was compress with {@link PaginatedPlanCache.compress}.
* @param input compressed query plan
* @return seria
*/
@SneakyThrows
public static String decompress(String input) {
if (input == null || input.length() == 0) {
return null;
return null;
}
GZIPInputStream gzip = new GZIPInputStream(new ByteArrayInputStream(
HashCode.fromString(input).asBytes()));
Expand Down Expand Up @@ -114,10 +124,10 @@ public PhysicalPlan convertToPlan(String cursor) {
throw new UnsupportedOperationException("Unsupported cursor");
}
cursor = cursor.substring(cursor.indexOf(',') + 1);
int currentPageIndex = Integer.parseInt(cursor, 0, cursor.indexOf(','), 10);
final int currentPageIndex = Integer.parseInt(cursor, 0, cursor.indexOf(','), 10);

cursor = cursor.substring(cursor.indexOf(',') + 1);
int pageSize = Integer.parseInt(cursor, 0, cursor.indexOf(','), 10);
final int pageSize = Integer.parseInt(cursor, 0, cursor.indexOf(','), 10);

cursor = cursor.substring(cursor.indexOf(',') + 1);
if (!cursor.startsWith("(Project,")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import org.opensearch.sql.planner.logical.LogicalRelation;
import org.opensearch.sql.planner.optimizer.Rule;

import java.util.Objects;

public class PushPageSize
implements Rule<LogicalPaginate> {
/** Capture the table inside matched logical paginate operator. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ public void invalid_to_retrieve_schema_from_remove() {
IllegalStateException exception =
assertThrows(IllegalStateException.class, () -> plan.schema());
assertEquals(
"[BUG] schema can been only applied to ProjectOperator, "
+ "instead of RemoveOperator(input=inputPlan, removeList=[response, referer])",
"[BUG] schema can been only applied to ProjectOperator, instead of RemoveOperator",
exception.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package org.opensearch.sql.opensearch.storage;

import static org.opensearch.sql.opensearch.request.OpenSearchScrollRequest.DEFAULT_SCROLL_TIMEOUT;

import java.util.function.Consumer;
import java.util.function.Function;
import lombok.EqualsAndHashCode;
Expand All @@ -18,8 +20,6 @@
import org.opensearch.sql.opensearch.request.OpenSearchRequest;
import org.opensearch.sql.opensearch.response.OpenSearchResponse;

import static org.opensearch.sql.opensearch.request.OpenSearchScrollRequest.DEFAULT_SCROLL_TIMEOUT;

public class ContinueScrollRequest implements OpenSearchRequest {
final String initialScrollId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@

import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.opensearch.client.OpenSearchClient;
import org.opensearch.sql.opensearch.request.OpenSearchRequest;
import org.opensearch.sql.opensearch.request.OpenSearchScrollRequest;
import org.opensearch.sql.opensearch.response.OpenSearchResponse;
import org.opensearch.sql.storage.TableScanOperator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@

public interface PagedRequestBuilder {
OpenSearchRequest build();

OpenSearchRequest.IndexName getIndexName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@

package org.opensearch.sql.opensearch.storage;

import lombok.RequiredArgsConstructor;
import org.opensearch.sql.opensearch.data.value.OpenSearchExprValueFactory;
import org.opensearch.sql.opensearch.request.OpenSearchRequest;

@RequiredArgsConstructor
public class SubsequentPageRequestBuilder implements PagedRequestBuilder {
private OpenSearchRequest.IndexName indexName;
final OpenSearchRequest.IndexName indexName;
final String scrollId;
private OpenSearchExprValueFactory exprValueFactory;

public SubsequentPageRequestBuilder(OpenSearchRequest.IndexName indexName, String scanAsString,
OpenSearchExprValueFactory exprValueFactory) {
this.indexName = indexName;
scrollId = scanAsString;
this.exprValueFactory = exprValueFactory;
}
final OpenSearchExprValueFactory exprValueFactory;

@Override
public OpenSearchRequest build() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import org.opensearch.sql.expression.NamedExpression;
import org.opensearch.sql.expression.ReferenceExpression;
import org.opensearch.sql.expression.aggregation.NamedAggregator;
import org.opensearch.sql.expression.serialization.DefaultExpressionSerializer;
import org.opensearch.sql.opensearch.response.agg.OpenSearchAggregationResponseParser;
import org.opensearch.sql.opensearch.storage.OpenSearchIndexScan;
import org.opensearch.sql.opensearch.storage.script.aggregation.AggregationQueryBuilder;
import org.opensearch.sql.expression.serialization.DefaultExpressionSerializer;
import org.opensearch.sql.planner.logical.LogicalAggregation;
import org.opensearch.sql.planner.logical.LogicalSort;
import org.opensearch.sql.storage.TableScanOperator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import org.opensearch.sql.expression.ExpressionNodeVisitor;
import org.opensearch.sql.expression.NamedExpression;
import org.opensearch.sql.expression.ReferenceExpression;
import org.opensearch.sql.expression.serialization.DefaultExpressionSerializer;
import org.opensearch.sql.opensearch.storage.OpenSearchIndexScan;
import org.opensearch.sql.opensearch.storage.script.filter.FilterQueryBuilder;
import org.opensearch.sql.opensearch.storage.script.sort.SortQueryBuilder;
import org.opensearch.sql.expression.serialization.DefaultExpressionSerializer;
import org.opensearch.sql.planner.logical.LogicalFilter;
import org.opensearch.sql.planner.logical.LogicalHighlight;
import org.opensearch.sql.planner.logical.LogicalLimit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import org.opensearch.script.ScriptContext;
import org.opensearch.script.ScriptEngine;
import org.opensearch.sql.expression.Expression;
import org.opensearch.sql.expression.serialization.ExpressionSerializer;
import org.opensearch.sql.opensearch.storage.script.aggregation.ExpressionAggregationScriptFactory;
import org.opensearch.sql.opensearch.storage.script.filter.ExpressionFilterScriptFactory;
import org.opensearch.sql.expression.serialization.ExpressionSerializer;

/**
* Custom expression script engine that supports using core engine expression code in DSL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
import org.opensearch.sql.expression.NamedExpression;
import org.opensearch.sql.expression.ReferenceExpression;
import org.opensearch.sql.expression.aggregation.NamedAggregator;
import org.opensearch.sql.expression.serialization.ExpressionSerializer;
import org.opensearch.sql.opensearch.response.agg.CompositeAggregationParser;
import org.opensearch.sql.opensearch.response.agg.MetricParser;
import org.opensearch.sql.opensearch.response.agg.NoBucketAggregationParser;
import org.opensearch.sql.opensearch.response.agg.OpenSearchAggregationResponseParser;
import org.opensearch.sql.opensearch.storage.script.aggregation.dsl.BucketAggregationBuilder;
import org.opensearch.sql.opensearch.storage.script.aggregation.dsl.MetricAggregationBuilder;
import org.opensearch.sql.expression.serialization.ExpressionSerializer;

/**
* Build the AggregationBuilder from the list of {@link NamedAggregator}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.opensearch.sql.expression.FunctionExpression;
import org.opensearch.sql.expression.LiteralExpression;
import org.opensearch.sql.expression.ReferenceExpression;
import org.opensearch.sql.opensearch.storage.script.ScriptUtils;
import org.opensearch.sql.expression.serialization.ExpressionSerializer;
import org.opensearch.sql.opensearch.storage.script.ScriptUtils;

/**
* Abstract Aggregation Builder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.opensearch.search.sort.SortOrder;
import org.opensearch.sql.ast.expression.SpanUnit;
import org.opensearch.sql.expression.NamedExpression;
import org.opensearch.sql.expression.span.SpanExpression;
import org.opensearch.sql.expression.serialization.ExpressionSerializer;
import org.opensearch.sql.expression.span.SpanExpression;

/**
* Bucket Aggregation Builder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
import org.opensearch.sql.expression.LiteralExpression;
import org.opensearch.sql.expression.ReferenceExpression;
import org.opensearch.sql.expression.aggregation.NamedAggregator;
import org.opensearch.sql.expression.serialization.ExpressionSerializer;
import org.opensearch.sql.opensearch.response.agg.FilterParser;
import org.opensearch.sql.opensearch.response.agg.MetricParser;
import org.opensearch.sql.opensearch.response.agg.SingleValueParser;
import org.opensearch.sql.opensearch.response.agg.StatsParser;
import org.opensearch.sql.opensearch.response.agg.TopHitsParser;
import org.opensearch.sql.opensearch.storage.script.filter.FilterQueryBuilder;
import org.opensearch.sql.expression.serialization.ExpressionSerializer;

/**
* Build the Metric Aggregation and List of {@link MetricParser} from {@link NamedAggregator}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.opensearch.sql.expression.FunctionExpression;
import org.opensearch.sql.expression.function.BuiltinFunctionName;
import org.opensearch.sql.expression.function.FunctionName;
import org.opensearch.sql.expression.serialization.ExpressionSerializer;
import org.opensearch.sql.opensearch.storage.script.filter.lucene.LikeQuery;
import org.opensearch.sql.opensearch.storage.script.filter.lucene.LuceneQuery;
import org.opensearch.sql.opensearch.storage.script.filter.lucene.RangeQuery;
Expand All @@ -38,7 +39,6 @@
import org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance.QueryStringQuery;
import org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance.SimpleQueryStringQuery;
import org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance.WildcardQuery;
import org.opensearch.sql.expression.serialization.ExpressionSerializer;

@RequiredArgsConstructor
public class FilterQueryBuilder extends ExpressionNodeVisitor<QueryBuilder, Object> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
class CursorTest {

@Test
void EmptyArrayIsNone() {
void emptyArrayIsNone() {
Assertions.assertEquals(Cursor.None, new Cursor(new byte[]{}));
}

@Test
void ToStringIsArrayValue() {
void toStringIsArrayValue() {
String cursorTxt = "This is a test";
Assertions.assertEquals(cursorTxt, new Cursor(cursorTxt.getBytes()).toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
import org.opensearch.sql.common.response.ResponseListener;
import org.opensearch.sql.common.setting.Settings;
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.executor.PaginatedPlanCache;
import org.opensearch.sql.executor.ExecutionContext;
import org.opensearch.sql.executor.ExecutionEngine;
import org.opensearch.sql.executor.ExecutionEngine.ExplainResponse;
import org.opensearch.sql.executor.PaginatedPlanCache;
import org.opensearch.sql.opensearch.client.OpenSearchClient;
import org.opensearch.sql.opensearch.data.value.OpenSearchExprValueFactory;
import org.opensearch.sql.opensearch.executor.protector.OpenSearchExecutionProtector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import org.opensearch.script.ScriptEngine;
import org.opensearch.sql.expression.DSL;
import org.opensearch.sql.expression.Expression;
import org.opensearch.sql.opensearch.storage.script.filter.ExpressionFilterScriptFactory;
import org.opensearch.sql.expression.serialization.ExpressionSerializer;
import org.opensearch.sql.opensearch.storage.script.filter.ExpressionFilterScriptFactory;

@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
@ExtendWith(MockitoExtension.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.opensearch.sql.datasource.DataSourceServiceImpl;
import org.opensearch.sql.datasource.model.DataSource;
import org.opensearch.sql.datasource.model.DataSourceMetadata;
import org.opensearch.sql.expression.serialization.DefaultExpressionSerializer;
import org.opensearch.sql.legacy.esdomain.LocalClusterState;
import org.opensearch.sql.legacy.executor.AsyncRestExecutor;
import org.opensearch.sql.legacy.metrics.Metrics;
Expand All @@ -68,7 +69,6 @@
import org.opensearch.sql.opensearch.setting.OpenSearchSettings;
import org.opensearch.sql.opensearch.storage.OpenSearchDataSourceFactory;
import org.opensearch.sql.opensearch.storage.script.ExpressionScriptEngine;
import org.opensearch.sql.expression.serialization.DefaultExpressionSerializer;
import org.opensearch.sql.plugin.config.OpenSearchPluginModule;
import org.opensearch.sql.plugin.datasource.DataSourceSettings;
import org.opensearch.sql.plugin.rest.RestPPLQueryAction;
Expand Down
6 changes: 5 additions & 1 deletion ppl/src/test/java/org/opensearch/sql/ppl/PPLServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.opensearch.sql.executor.ExecutionEngine.QueryResponse;
import org.opensearch.sql.executor.PaginatedPlanCache;
import org.opensearch.sql.executor.QueryService;
import org.opensearch.sql.executor.execution.PaginatedQueryService;
import org.opensearch.sql.executor.execution.QueryPlanFactory;
import org.opensearch.sql.opensearch.executor.Cursor;
import org.opensearch.sql.ppl.antlr.PPLSyntaxParser;
Expand All @@ -45,6 +46,9 @@ public class PPLServiceTest {
@Mock
private QueryService queryService;

@Mock
private PaginatedQueryService paginatedQueryService;

@Mock
private ExecutionEngine.Schema schema;

Expand All @@ -59,7 +63,7 @@ public void setUp() {
queryManager = DefaultQueryManager.defaultQueryManager();

pplService = new PPLService(new PPLSyntaxParser(), queryManager,
new QueryPlanFactory(queryService, paginatedPlanCache));
new QueryPlanFactory(queryService, paginatedQueryService, paginatedPlanCache));
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public void buildQueryStatement() {
"search source=t a=1",
new Query(
project(
filter(relation("t"), compare("=", field("a"), intLiteral(1))), AllFields.of()), 0));
filter(relation("t"), compare("=", field("a"),
intLiteral(1))), AllFields.of()), 0));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,20 @@ public class SQLQueryRequest {
private boolean sanitize = true;

private String cursor = "";

/**
* Constructor of SQLQueryRequest that passes request params.
*/
public SQLQueryRequest(
JSONObject jsonContent, String query, String path, Map<String, String> params, String cursor) {
public SQLQueryRequest(JSONObject jsonContent, String query, String path,
Map<String, String> params, String cursor) {
this.jsonContent = jsonContent;
this.query = query;
this.path = path;
this.params = params;
this.format = getFormat(params);
this.sanitize = shouldSanitize(params);
// TODO hack
this.cursor = cursor == null? "" : cursor;
this.cursor = cursor == null ? "" : cursor;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion sql/src/test/java/org/opensearch/sql/sql/SQLServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.opensearch.sql.executor.ExecutionEngine.ExplainResponseNode;
import org.opensearch.sql.executor.PaginatedPlanCache;
import org.opensearch.sql.executor.QueryService;
import org.opensearch.sql.executor.execution.PaginatedQueryService;
import org.opensearch.sql.executor.execution.QueryPlanFactory;
import org.opensearch.sql.opensearch.executor.Cursor;
import org.opensearch.sql.sql.antlr.SQLSyntaxParser;
Expand All @@ -47,6 +48,9 @@ class SQLServiceTest {
@Mock
private QueryService queryService;

@Mock
private PaginatedQueryService paginatedQueryService;

@Mock
private ExecutionEngine.Schema schema;

Expand All @@ -57,7 +61,7 @@ class SQLServiceTest {
public void setUp() {
queryManager = DefaultQueryManager.defaultQueryManager();
sqlService = new SQLService(new SQLSyntaxParser(), queryManager,
new QueryPlanFactory(queryService, paginatedPlanCache));
new QueryPlanFactory(queryService, paginatedQueryService, paginatedPlanCache));
}

@AfterEach
Expand Down

0 comments on commit 11a18c1

Please sign in to comment.