Skip to content

Commit

Permalink
Fix create_index/create_index_with_IOException issue caused by OpenSe…
Browse files Browse the repository at this point in the history
…arch PR change (opensearch-project#1899)

* Added setDefaultMediaType for create_index and create_index_with_IOException

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>
(cherry picked from commit 7b932a7)
Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

Resolving merge conflicts for pre tag in java docs.

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

running spotless check on newly pre tagged javadocs.

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

Converts java doc table to proper java doc table.

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

Resolving merge conflicts for pre tag in java docs 2

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

running spotless check on newly pre tagged javadocs.

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

cherry pick 60c0018

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

Addressed PR comment for table format in AbstractExprValue.

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

Removed pre tag from ExpressionReferenceOptimizer.

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

Removed pre tag from AstDSL.java

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

Removed pre tag from AstDSL.java

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

Removed pre tag from SelectExpressionAnalyzer.java

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

fixed java doc in QualifiedName.java

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

Removing checkstyle test for core and added spotless for relevant directories.

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

Fixing spacing around headers in ExpressionReferenceOptimizer.java SelectExpressionAnalyzer.java

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

Fix breaking changes. Disable some flaky tests in legacy.

Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com>

(cherry picked from commit 809e656)
Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

Resolving merge conflicts for pre tag in java docs.

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

running spotless check on newly pre tagged javadocs.

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

Fixed java doc spelling and improving string concatination.

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

improving string concatination.

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

Improving failure format on some functions.

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>

spotless apply and fix of build.gradle

Signed-off-by: Mitchell Gale <Mitchell.Gale@improving.com>
  • Loading branch information
MitchellGale committed Aug 3, 2023
1 parent d0dccc4 commit 5ed6eec
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.analysis;

import com.google.common.collect.ImmutableList;
Expand All @@ -29,21 +30,23 @@
import org.opensearch.sql.expression.ReferenceExpression;

/**
* Analyze the select list in the {@link AnalysisContext} to construct the list of {@link
* NamedExpression}.
* Analyze the select list in the {@link AnalysisContext} to construct the list of
* {@link NamedExpression}.
*/
@RequiredArgsConstructor
public class SelectExpressionAnalyzer
extends AbstractNodeVisitor<List<NamedExpression>, AnalysisContext> {
extends
AbstractNodeVisitor<List<NamedExpression>, AnalysisContext> {
private final ExpressionAnalyzer expressionAnalyzer;

private ExpressionReferenceOptimizer optimizer;

/** Analyze Select fields. */
public List<NamedExpression> analyze(
List<UnresolvedExpression> selectList,
AnalysisContext analysisContext,
ExpressionReferenceOptimizer optimizer) {
/**
* Analyze Select fields.
*/
public List<NamedExpression> analyze(List<UnresolvedExpression> selectList,
AnalysisContext analysisContext,
ExpressionReferenceOptimizer optimizer) {
this.optimizer = optimizer;
ImmutableList.Builder<NamedExpression> builder = new ImmutableList.Builder<>();
for (UnresolvedExpression unresolvedExpression : selectList) {
Expand All @@ -65,8 +68,10 @@ public List<NamedExpression> visitAlias(Alias node, AnalysisContext context) {
}

Expression expr = referenceIfSymbolDefined(node, context);
return Collections.singletonList(
DSL.named(unqualifiedNameIfFieldOnly(node, context), expr, node.getAlias()));
return Collections.singletonList(DSL.named(
unqualifiedNameIfFieldOnly(node, context),
expr,
node.getAlias()));
}

/**
Expand All @@ -83,32 +88,32 @@ public List<NamedExpression> visitAlias(Alias node, AnalysisContext context) {
* Agg(Alias("AVG(age)", aggExpr), Alias("length(name)", groupExpr))</li>
* </ol>
*/
private Expression referenceIfSymbolDefined(Alias expr, AnalysisContext context) {
private Expression referenceIfSymbolDefined(Alias expr,
AnalysisContext context) {
UnresolvedExpression delegatedExpr = expr.getDelegated();

// Pass named expression because expression like window function loses full name
// (OVER clause) and thus depends on name in alias to be replaced correctly
return optimizer.optimize(
DSL.named(
expr.getName(), delegatedExpr.accept(expressionAnalyzer, context), expr.getAlias()),
expr.getName(),
delegatedExpr.accept(expressionAnalyzer, context),
expr.getAlias()),
context);
}

@Override
public List<NamedExpression> visitAllFields(AllFields node, AnalysisContext context) {
public List<NamedExpression> visitAllFields(AllFields node,
AnalysisContext context) {
TypeEnvironment environment = context.peek();
Map<String, ExprType> lookupAllFields = environment.lookupAllFields(Namespace.FIELD_NAME);
return lookupAllFields.entrySet().stream()
.map(
entry ->
DSL.named(
entry.getKey(), new ReferenceExpression(entry.getKey(), entry.getValue())))
.collect(Collectors.toList());
return lookupAllFields.entrySet().stream().map(entry -> DSL.named(entry.getKey(),
new ReferenceExpression(entry.getKey(), entry.getValue()))).collect(Collectors.toList());
}

@Override
public List<NamedExpression> visitNestedAllTupleFields(
NestedAllTupleFields node, AnalysisContext context) {
public List<NamedExpression> visitNestedAllTupleFields(NestedAllTupleFields node,
AnalysisContext context) {
TypeEnvironment environment = context.peek();
Map<String, ExprType> lookupAllTupleFields =
environment.lookupAllTupleFields(Namespace.FIELD_NAME);
Expand All @@ -118,25 +123,25 @@ public List<NamedExpression> visitNestedAllTupleFields(
Pattern p = Pattern.compile(node.getPath() + "\\.[^\\.]+$");
return lookupAllTupleFields.entrySet().stream()
.filter(field -> p.matcher(field.getKey()).find())
.map(
entry -> {
Expression nestedFunc =
new Function(
"nested",
List.of(new QualifiedName(List.of(entry.getKey().split("\\.")))))
.accept(expressionAnalyzer, context);
return DSL.named("nested(" + entry.getKey() + ")", nestedFunc);
})
.map(entry -> {
Expression nestedFunc = new Function(
"nested",
List.of(
new QualifiedName(List.of(entry.getKey().split("\\."))))
).accept(expressionAnalyzer, context);
return DSL.named("nested(" + entry.getKey() + ")", nestedFunc);
})
.collect(Collectors.toList());
}

/**
* Get unqualified name if select item is just a field. For example, suppose an index named
* "accounts", return "age" for "SELECT accounts.age". But do nothing for expression in "SELECT
* ABS(accounts.age)". Note that an assumption is made implicitly that original name field in
* Alias must be the same as the values in QualifiedName. This is true because AST builder does
* this. Otherwise, what unqualified() returns will override Alias's name as NamedExpression's
* name even though the QualifiedName doesn't have qualifier.
* Get unqualified name if select item is just a field. For example, suppose an index
* named "accounts", return "age" for "SELECT accounts.age". But do nothing for expression
* in "SELECT ABS(accounts.age)".
* Note that an assumption is made implicitly that original name field in Alias must be
* the same as the values in QualifiedName. This is true because AST builder does this.
* Otherwise, what unqualified() returns will override Alias's name as NamedExpression's name
* even though the QualifiedName doesn't have qualifier.
*/
private String unqualifiedNameIfFieldOnly(Alias node, AnalysisContext context) {
UnresolvedExpression selectItem = node.getDelegated();
Expand All @@ -146,4 +151,5 @@ private String unqualifiedNameIfFieldOnly(Alias node, AnalysisContext context) {
}
return node.getName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import lombok.SneakyThrows;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.lucene.search.TotalHits;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
Expand Down

0 comments on commit 5ed6eec

Please sign in to comment.