Skip to content

Commit

Permalink
Add a handler for TDSRequest (finos#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
gayathrir11 authored Feb 21, 2024
1 parent 1b3e6e6 commit e88f213
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.impl.utility.Iterate;
import org.finos.legend.engine.ide.lsp.extension.AbstractLegacyParserLSPGrammarExtension;
import org.finos.legend.engine.ide.lsp.extension.LegendTDSRequestHandler;
import org.finos.legend.engine.ide.lsp.extension.SourceInformationUtil;
import org.finos.legend.engine.ide.lsp.extension.agGrid.FunctionTDSRequest;
import org.finos.legend.engine.ide.lsp.extension.completion.LegendCompletion;
Expand Down Expand Up @@ -87,7 +88,7 @@
/**
* Extension for the Pure grammar.
*/
public class PureLSPGrammarExtension extends AbstractLegacyParserLSPGrammarExtension
public class PureLSPGrammarExtension extends AbstractLegacyParserLSPGrammarExtension implements LegendTDSRequestHandler
{
private static final Logger LOGGER = LoggerFactory.getLogger(PureLSPGrammarExtension.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import java.util.Optional;

import org.finos.legend.engine.ide.lsp.extension.agGrid.FunctionTDSRequest;
import org.finos.legend.engine.ide.lsp.extension.completion.LegendCompletion;
import org.finos.legend.engine.ide.lsp.extension.declaration.LegendDeclaration;
import org.finos.legend.engine.ide.lsp.extension.diagnostic.LegendDiagnostic;
Expand Down Expand Up @@ -87,11 +86,6 @@ default Iterable<? extends LegendCommand> getCommands(SectionState section)
return Collections.emptyList();
}

default LegendExecutionResult executeLegendTDSRequest(SectionState section, FunctionTDSRequest request)
{
return null;
}

/**
* Execute a Legend command on an entity in a section.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2024 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.finos.legend.engine.ide.lsp.extension;

import org.finos.legend.engine.ide.lsp.extension.agGrid.FunctionTDSRequest;
import org.finos.legend.engine.ide.lsp.extension.execution.LegendExecutionResult;
import org.finos.legend.engine.ide.lsp.extension.state.SectionState;

public interface LegendTDSRequestHandler
{
/**
* Return the Legend execution result for the given tds request by client.
*
* @param section grammar section state
* @param request request made by ag-grid
* @return Legend execution result
*/
default LegendExecutionResult executeLegendTDSRequest(SectionState section, FunctionTDSRequest request)
{
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,44 @@

public enum FilterOperation
{
/**
* Equals filter on a query column.
*/
EQUALS("equals"),

/**
* Not equal filter on a query column.
*/
NOT_EQUAL("notEqual"),

/**
* Greater than filter on a query column.
*/
GREATER_THAN("greaterThan"),

/**
* Greater than or equal filter on a query column.
*/
GREATER_THAN_OR_EQUAL("greaterThanOrEqual"),

/**
* Less than filter on a query column.
*/
LESS_THAN("lessThan"),

/**
* Less than or equal filter on a query column.
*/
LESS_THAN_OR_EQUAL("lessThanOrEqual"),

/**
* Blank(is empty) filter on a query column.
*/
BLANK("blank"),

/**
* Not blank(is not empty) filter on a query column.
*/
NOT_BLANK("notBlank");

private final String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,39 @@

public enum TDSAggregationFunction
{
/**
* Sum aggregation operation on a query column.
*/
SUM("sum"),

/**
* Minimum aggregation operation on a query column.
*/
MIN("min"),

/**
* Maximum aggregation operation on a query column.
*/
MAX("max"),

/**
* Count aggregation operation on a query column.
*/
COUNT("count"),

/**
* Average aggregation operation on a query column.
*/
AVG("avg"),

/**
* First aggregation operation on a query column.
*/
FIRST("first"),

/**
* Last aggregation operation on a query column.
*/
LAST("last");

private final String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@

public enum TDSSortOrder
{
/**
* Ascending sort operation on a query column.
*/
ASCENDING("asc"),

/**
* Descending sort operation on a query column.
*/
DESCENDING("desc");

private final String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.eclipse.lsp4j.services.LanguageClient;
import org.eclipse.lsp4j.services.TextDocumentService;
import org.finos.legend.engine.ide.lsp.extension.LegendLSPGrammarExtension;
import org.finos.legend.engine.ide.lsp.extension.LegendTDSRequestHandler;
import org.finos.legend.engine.ide.lsp.extension.agGrid.FunctionTDSRequest;
import org.finos.legend.engine.ide.lsp.extension.completion.LegendCompletion;
import org.finos.legend.engine.ide.lsp.extension.diagnostic.LegendDiagnostic;
Expand Down Expand Up @@ -527,7 +528,14 @@ public CompletableFuture<Object> legendTDSRequest(Object rq)
}
try
{
result = extension.executeLegendTDSRequest(sectionState, request);
if (extension instanceof LegendTDSRequestHandler)
{
result = ((LegendTDSRequestHandler) extension).executeLegendTDSRequest(sectionState, request);
}
else
{
throw new RuntimeException("Could not execute legend TDS request for entity " + entity + " in section " + sectionNum + " of " + uri + ": extension does not support executing tds request");
}
}
catch (Throwable e)
{
Expand Down

0 comments on commit e88f213

Please sign in to comment.