Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions core/src/main/java/org/opensearch/sql/analysis/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import static org.opensearch.sql.ast.tree.Sort.NullOrder.NULL_LAST;
import static org.opensearch.sql.ast.tree.Sort.SortOrder.ASC;
import static org.opensearch.sql.ast.tree.Sort.SortOrder.DESC;
import static org.opensearch.sql.common.setting.Settings.Key.CALCITE_ENGINE_ENABLED;
import static org.opensearch.sql.calcite.utils.CalciteUtils.getOnlyForCalciteException;
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
import static org.opensearch.sql.data.type.ExprCoreType.STRUCT;
import static org.opensearch.sql.data.type.ExprCoreType.TIME;
Expand Down Expand Up @@ -181,8 +181,7 @@ public LogicalPlan visitSubqueryAlias(SubqueryAlias node, AnalysisContext contex
STRUCT);
return child;
} else {
throw new UnsupportedOperationException(
"Subsearch is supported only when " + CALCITE_ENGINE_ENABLED.getKeyValue() + "=true");
throw getOnlyForCalciteException("Subsearch");
}
}

Expand Down Expand Up @@ -672,14 +671,12 @@ public LogicalPlan visitML(ML node, AnalysisContext context) {

@Override
public LogicalPlan visitBin(Bin node, AnalysisContext context) {
throw new UnsupportedOperationException(
"Bin command is supported only when " + CALCITE_ENGINE_ENABLED.getKeyValue() + "=true");
throw getOnlyForCalciteException("Bin");
}

@Override
public LogicalPlan visitExpand(Expand expand, AnalysisContext context) {
throw new UnsupportedOperationException(
"Expand is supported only when " + CALCITE_ENGINE_ENABLED.getKeyValue() + "=true");
throw getOnlyForCalciteException("Expand");
}

/** Build {@link LogicalTrendline} for Trendline command. */
Expand Down Expand Up @@ -733,14 +730,12 @@ public LogicalPlan visitTrendline(Trendline node, AnalysisContext context) {

@Override
public LogicalPlan visitFlatten(Flatten node, AnalysisContext context) {
throw new UnsupportedOperationException(
"FLATTEN is supported only when " + CALCITE_ENGINE_ENABLED.getKeyValue() + "=true");
throw getOnlyForCalciteException("Flatten");
}

@Override
public LogicalPlan visitReverse(Reverse node, AnalysisContext context) {
throw new UnsupportedOperationException(
"REVERSE is supported only when " + CALCITE_ENGINE_ENABLED.getKeyValue() + "=true");
throw getOnlyForCalciteException("Reverse");
}

@Override
Expand All @@ -763,20 +758,17 @@ public LogicalPlan visitCloseCursor(CloseCursor closeCursor, AnalysisContext con

@Override
public LogicalPlan visitJoin(Join node, AnalysisContext context) {
throw new UnsupportedOperationException(
"Join is supported only when " + CALCITE_ENGINE_ENABLED.getKeyValue() + "=true");
throw getOnlyForCalciteException("Join");
}

@Override
public LogicalPlan visitLookup(Lookup node, AnalysisContext context) {
throw new UnsupportedOperationException(
"Lookup is supported only when " + CALCITE_ENGINE_ENABLED.getKeyValue() + "=true");
throw getOnlyForCalciteException("Lookup");
}

@Override
public LogicalPlan visitAppendCol(AppendCol node, AnalysisContext context) {
throw new UnsupportedOperationException(
"AppendCol is supported only when " + CALCITE_ENGINE_ENABLED.getKeyValue() + "=true");
throw getOnlyForCalciteException("Appendcol");
}

private LogicalSort buildSort(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import static org.opensearch.sql.ast.dsl.AstDSL.and;
import static org.opensearch.sql.ast.dsl.AstDSL.compare;
import static org.opensearch.sql.common.setting.Settings.Key.CALCITE_ENGINE_ENABLED;
import static org.opensearch.sql.calcite.utils.CalciteUtils.getOnlyForCalciteException;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -435,20 +435,17 @@ public Expression visitArgument(Argument node, AnalysisContext context) {

@Override
public Expression visitScalarSubquery(ScalarSubquery node, AnalysisContext context) {
throw new UnsupportedOperationException(
"Subsearch is supported only when " + CALCITE_ENGINE_ENABLED.getKeyValue() + "=true");
throw getOnlyForCalciteException("Subsearch");
}

@Override
public Expression visitExistsSubquery(ExistsSubquery node, AnalysisContext context) {
throw new UnsupportedOperationException(
"Subsearch is supported only when " + CALCITE_ENGINE_ENABLED.getKeyValue() + "=true");
throw getOnlyForCalciteException("Subsearch");
}

@Override
public Expression visitInSubquery(InSubquery node, AnalysisContext context) {
throw new UnsupportedOperationException(
"Subsearch is supported only when " + CALCITE_ENGINE_ENABLED.getKeyValue() + "=true");
throw getOnlyForCalciteException("Subsearch");
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.sql.calcite.utils;

import static org.opensearch.sql.common.setting.Settings.Key.CALCITE_ENGINE_ENABLED;

import lombok.experimental.UtilityClass;

@UtilityClass
public class CalciteUtils {

public static UnsupportedOperationException getOnlyForCalciteException(String feature) {
return new UnsupportedOperationException(
feature + " is supported only when " + CALCITE_ENGINE_ENABLED.getKeyValue() + "=true");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,45 +139,18 @@ public void testMergedObjectFields() throws IOException {
}

@Test
public void testEnhancedFieldFeaturesBlockedWhenCalciteDisabled() {
// Test wildcards are blocked
Exception e1 =
assertThrows(
Exception.class,
() -> executeQuery(String.format("source=%s | fields *", TEST_INDEX_ACCOUNT)));
verifyErrorMessageContains(
e1, "Enhanced fields features are supported only when" + " plugins.calcite.enabled=true");

Exception e2 =
assertThrows(
Exception.class,
() -> executeQuery(String.format("source=%s | fields account_*", TEST_INDEX_ACCOUNT)));
verifyErrorMessageContains(
e2, "Enhanced fields features are supported only when" + " plugins.calcite.enabled=true");

// Test space-delimited fields are blocked
Exception e3 =
assertThrows(
Exception.class,
() ->
executeQuery(
String.format(
"source=%s | fields account_number balance firstname",
TEST_INDEX_ACCOUNT)));
verifyErrorMessageContains(
e3, "Enhanced fields features are supported only when" + " plugins.calcite.enabled=true");
public void testEnhancedFieldsWhenCalciteDisabled() {
verifyQueryThrowsCalciteError("source=%s | fields *");
verifyQueryThrowsCalciteError("source=%s | fields account_*");
verifyQueryThrowsCalciteError("source=%s | fields account_number balance firstname");
verifyQueryThrowsCalciteError("source=%s | fields account_number balance, firstname");
}

// Test mixed delimiters are blocked
Exception e4 =
assertThrows(
Exception.class,
() ->
executeQuery(
String.format(
"source=%s | fields account_number balance, firstname",
TEST_INDEX_ACCOUNT)));
private void verifyQueryThrowsCalciteError(String query) {
Exception e =
assertThrows(Exception.class, () -> executeQuery(String.format(query, TEST_INDEX_ACCOUNT)));
verifyErrorMessageContains(
e4, "Enhanced fields features are supported only when" + " plugins.calcite.enabled=true");
e, "Enhanced fields feature is supported only when plugins.calcite.enabled=true");
}

@Ignore(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static java.util.Collections.emptyMap;
import static org.opensearch.sql.ast.dsl.AstDSL.booleanLiteral;
import static org.opensearch.sql.ast.dsl.AstDSL.qualifiedName;
import static org.opensearch.sql.calcite.utils.CalciteUtils.getOnlyForCalciteException;
import static org.opensearch.sql.lang.PPLLangSpec.PPL_SPEC;
import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.BinCommandContext;
import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.DedupCommandContext;
Expand Down Expand Up @@ -294,10 +295,7 @@ public UnresolvedPlan visitTableCommand(TableCommandContext ctx) {
: new Argument("exclude", new Literal(false, DataType.BOOLEAN)));
return buildProjectCommand(ctx.fieldsCommandBody(), arguments);
}
throw new UnsupportedOperationException(
"Table command is supported only when "
+ Key.CALCITE_ENGINE_ENABLED.getKeyValue()
+ "=true");
throw getOnlyForCalciteException("Table command");
}

private UnresolvedPlan buildProjectCommand(
Expand All @@ -308,10 +306,7 @@ private UnresolvedPlan buildProjectCommand(
if (settings != null
&& Boolean.FALSE.equals(settings.getSettingValue(Key.CALCITE_ENGINE_ENABLED))) {
if (hasEnhancedFieldFeatures(bodyCtx, fields)) {
throw new UnsupportedOperationException(
"Enhanced fields features are supported only when "
+ Key.CALCITE_ENGINE_ENABLED.getKeyValue()
+ "=true");
throw getOnlyForCalciteException("Enhanced fields feature");
}
}

Expand Down
Loading