This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 186
Adding simple In support #1114
Open
FreCap
wants to merge
2
commits into
opendistro-for-elasticsearch:develop
Choose a base branch
from
FreCap:IN_support
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Adding simple In support #1114
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,7 +88,7 @@ public static ExprValue tupleValue(Map<String, Object> map) { | |
/** | ||
* {@link ExprCollectionValue} constructor. | ||
*/ | ||
public static ExprValue collectionValue(List<Object> list) { | ||
public static <T> ExprValue collectionValue(List<T> list) { | ||
List<ExprValue> valueList = new ArrayList<>(); | ||
list.forEach(o -> valueList.add(fromObjectValue(o))); | ||
return new ExprCollectionValue(valueList); | ||
|
@@ -129,6 +129,10 @@ public static ExprValue fromObjectValue(Object o) { | |
return stringValue((String) o); | ||
} else if (o instanceof Float) { | ||
return floatValue((Float) o); | ||
} else if (o instanceof ExprValue) { | ||
// since there is no primitive in Java for differentiating TIMESTAMP DATETIME and DATE | ||
// we can allow passing a ExprValue that already contains this information | ||
return (ExprValue) o; | ||
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. Any insights here? @penghuo 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. I'll wait for a few more comment/suggestions before making changes to the rest. |
||
} else { | ||
throw new ExpressionEvaluationException("unsupported object " + o.getClass()); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,13 +215,24 @@ public void invalidConvertExprValue(ExprValue value, Function<ExprValue, Object> | |
assertThat(exception.getMessage(), Matchers.containsString("invalid")); | ||
} | ||
|
||
// disabling test because in case of expr collections, we could pass ExprValues | ||
// @Test | ||
// public void unSupportedObject() { | ||
// Exception exception = assertThrows(ExpressionEvaluationException.class, | ||
// () -> ExprValueUtils.fromObjectValue(integerValue(1))); | ||
// assertEquals( | ||
// "unsupported object " | ||
// + "class com.amazon.opendistroforelasticsearch.sql.data.model.ExprIntegerValue", | ||
// exception.getMessage()); | ||
// } | ||
|
||
Comment on lines
+218
to
+228
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. Remove these lines? 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. ok |
||
@Test | ||
public void unSupportedObject() { | ||
Exception exception = assertThrows(ExpressionEvaluationException.class, | ||
() -> ExprValueUtils.fromObjectValue(integerValue(1))); | ||
() -> ExprValueUtils.fromObjectValue(new Object())); | ||
assertEquals( | ||
"unsupported object " | ||
+ "class com.amazon.opendistroforelasticsearch.sql.data.model.ExprIntegerValue", | ||
+ "class java.lang.Object", | ||
exception.getMessage()); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...opendistroforelasticsearch/sql/elasticsearch/storage/script/filter/lucene/TermsQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 com.amazon.opendistroforelasticsearch.sql.elasticsearch.storage.script.filter.lucene; | ||
|
||
import com.amazon.opendistroforelasticsearch.sql.data.model.ExprValue; | ||
import com.amazon.opendistroforelasticsearch.sql.data.type.ExprType; | ||
import java.util.stream.Collectors; | ||
import org.elasticsearch.index.query.QueryBuilder; | ||
import org.elasticsearch.index.query.QueryBuilders; | ||
|
||
|
||
/** | ||
* Lucene query that build terms query for equality comparison. | ||
*/ | ||
public class TermsQuery extends LuceneQuery { | ||
|
||
@Override | ||
protected QueryBuilder doBuild(String fieldName, ExprType fieldType, ExprValue literal) { | ||
fieldName = convertTextToKeyword(fieldName, fieldType); | ||
return QueryBuilders.termsQuery(fieldName, | ||
literal.collectionValue().stream().map(ExprValue::value) | ||
.collect(Collectors.toList())); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think it's fine to remove this file if the code base has no dependency on it.
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.
ok