Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Commit 353c1c8

Browse files
authored
Add ElasticsearchExprValueFactory in StorageEngine (#608)
* Add ElasticsearchExprValueFactory in StorageEngine * update
1 parent 49883b9 commit 353c1c8

File tree

18 files changed

+636
-76
lines changed

18 files changed

+636
-76
lines changed

core/src/main/java/com/amazon/opendistroforelasticsearch/sql/data/model/ExprBooleanValue.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,17 @@
2020

2121
@EqualsAndHashCode
2222
public class ExprBooleanValue implements ExprValue {
23-
private static final ExprValue TRUE = new ExprBooleanValue(true);
24-
private static final ExprValue FALSE = new ExprBooleanValue(false);
23+
private static final ExprBooleanValue TRUE = new ExprBooleanValue(true);
24+
private static final ExprBooleanValue FALSE = new ExprBooleanValue(false);
2525

2626
private final Boolean value;
2727

2828
private ExprBooleanValue(Boolean value) {
2929
this.value = value;
3030
}
3131

32-
public static ExprValue ofTrue() {
33-
return TRUE;
34-
}
35-
36-
public static ExprValue ofFalse() {
37-
return FALSE;
32+
public static ExprBooleanValue of(Boolean value) {
33+
return value ? TRUE : FALSE;
3834
}
3935

4036
@Override

core/src/main/java/com/amazon/opendistroforelasticsearch/sql/data/model/ExprValueUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
*/
3636
@UtilityClass
3737
public class ExprValueUtils {
38-
public static final ExprValue LITERAL_TRUE = ExprBooleanValue.ofTrue();
39-
public static final ExprValue LITERAL_FALSE = ExprBooleanValue.ofFalse();
38+
public static final ExprValue LITERAL_TRUE = ExprBooleanValue.of(true);
39+
public static final ExprValue LITERAL_FALSE = ExprBooleanValue.of(false);
4040
public static final ExprValue LITERAL_NULL = ExprNullValue.of();
4141
public static final ExprValue LITERAL_MISSING = ExprMissingValue.of();
4242

core/src/test/java/com/amazon/opendistroforelasticsearch/sql/planner/DefaultImplementorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void visitShouldReturnDefaultPhysicalOperator() {
6262
ReferenceExpression include = ref("age", INTEGER);
6363
ReferenceExpression exclude = ref("name", STRING);
6464
ReferenceExpression dedupeField = ref("name", STRING);
65-
Expression filterExpr = literal(ExprBooleanValue.ofTrue());
65+
Expression filterExpr = literal(ExprBooleanValue.of(true));
6666
List<Expression> groupByExprs = Arrays.asList(ref("age", INTEGER));
6767
List<Aggregator> aggregators =
6868
Arrays.asList(new AvgAggregator(groupByExprs, ExprCoreType.DOUBLE));

docs/experiment/ppl/cmd/search.rst

+14-14
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ PPL query::
3232

3333
od> source=accounts;
3434
fetched rows / total rows = 4/4
35-
+------------------+-------------+----------------------+-----------+----------+--------+------------+---------+-------+-----------------------+------------+
36-
| account_number | firstname | address | balance | gender | city | employer | state | age | email | lastname |
37-
|------------------+-------------+----------------------+-----------+----------+--------+------------+---------+-------+-----------------------+------------|
38-
| 1 | Amber | 880 Holmes Lane | 39225 | M | Brogan | Pyrami | IL | 32 | [email protected] | Duke |
39-
| 6 | Hattie | 671 Bristol Street | 5686 | M | Dante | Netagy | TN | 36 | [email protected] | Bond |
40-
| 13 | Nanette | 789 Madison Street | 32838 | F | Nogal | Quility | VA | 28 | null | Bates |
41-
| 18 | Dale | 467 Hutchinson Court | 4180 | M | Orick | null | MD | 33 | [email protected] | Adams |
42-
+------------------+-------------+----------------------+-----------+----------+--------+------------+---------+-------+-----------------------+------------+
35+
+------------------+-----------+-------------+------------+-------+----------+----------------------+------------+-----------------------+--------+---------+
36+
| account_number | balance | firstname | lastname | age | gender | address | employer | email | city | state |
37+
|------------------+-----------+-------------+------------+-------+----------+----------------------+------------+-----------------------+--------+---------|
38+
| 1 | 39225 | Amber | Duke | 32 | M | 880 Holmes Lane | Pyrami | [email protected] | Brogan | IL |
39+
| 6 | 5686 | Hattie | Bond | 36 | M | 671 Bristol Street | Netagy | [email protected] | Dante | TN |
40+
| 13 | 32838 | Nanette | Bates | 28 | F | 789 Madison Street | Quility | null | Nogal | VA |
41+
| 18 | 4180 | Dale | Adams | 33 | M | 467 Hutchinson Court | null | [email protected] | Orick | MD |
42+
+------------------+-----------+-------------+------------+-------+----------+----------------------+------------+-----------------------+--------+---------+
4343

4444
Example 2: Fetch data with condition
4545
====================================
@@ -50,10 +50,10 @@ PPL query::
5050

5151
od> source=accounts account_number=1 or gender="F";
5252
fetched rows / total rows = 2/2
53-
+------------------+-------------+--------------------+-----------+----------+--------+------------+---------+-------+----------------------+------------+
54-
| account_number | firstname | address | balance | gender | city | employer | state | age | email | lastname |
55-
|------------------+-------------+--------------------+-----------+----------+--------+------------+---------+-------+----------------------+------------|
56-
| 1 | Amber | 880 Holmes Lane | 39225 | M | Brogan | Pyrami | IL | 32 | [email protected] | Duke |
57-
| 13 | Nanette | 789 Madison Street | 32838 | F | Nogal | Quility | VA | 28 | null | Bates |
58-
+------------------+-------------+--------------------+-----------+----------+--------+------------+---------+-------+----------------------+------------+
53+
+------------------+-----------+-------------+------------+-------+----------+--------------------+------------+----------------------+--------+---------+
54+
| account_number | balance | firstname | lastname | age | gender | address | employer | email | city | state |
55+
|------------------+-----------+-------------+------------+-------+----------+--------------------+------------+----------------------+--------+---------|
56+
| 1 | 39225 | Amber | Duke | 32 | M | 880 Holmes Lane | Pyrami | [email protected] | Brogan | IL |
57+
| 13 | 32838 | Nanette | Bates | 28 | F | 789 Madison Street | Quility | null | Nogal | VA |
58+
+------------------+-----------+-------------+------------+-------+----------+--------------------+------------+----------------------+--------+---------+
5959

docs/experiment/ppl/cmd/where.rst

+7-7
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ The example show fetch all the document from accounts index with .
2727

2828
PPL query::
2929

30-
od> source=accounts | where account_number=1 or gender="F";
30+
od> source=accounts | where account_number=1 or gender="F" | fields account_number, gender;
3131
fetched rows / total rows = 2/2
32-
+------------------+-------------+--------------------+-----------+----------+--------+------------+---------+-------+----------------------+------------+
33-
| account_number | firstname | address | balance | gender | city | employer | state | age | email | lastname |
34-
|------------------+-------------+--------------------+-----------+----------+--------+------------+---------+-------+----------------------+------------|
35-
| 1 | Amber | 880 Holmes Lane | 39225 | M | Brogan | Pyrami | IL | 32 | [email protected] | Duke |
36-
| 13 | Nanette | 789 Madison Street | 32838 | F | Nogal | Quility | VA | 28 | null | Bates |
37-
+------------------+-------------+--------------------+-----------+----------+--------+------------+---------+-------+----------------------+------------+
32+
+------------------+----------+
33+
| account_number | gender |
34+
|------------------+----------|
35+
| 1 | M |
36+
| 13 | F |
37+
+------------------+----------+
3838

docs/user/general/identifiers.rst

+16-16
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ Here are examples for using index pattern directly without quotes::
4040

4141
od> SELECT * FROM *cc*nt*;
4242
fetched rows / total rows = 4/4
43-
+------------------+-------------+----------------------+-----------+----------+--------+------------+---------+-------+-----------------------+------------+
44-
| account_number | firstname | address | balance | gender | city | employer | state | age | email | lastname |
45-
|------------------+-------------+----------------------+-----------+----------+--------+------------+---------+-------+-----------------------+------------|
46-
| 1 | Amber | 880 Holmes Lane | 39225 | M | Brogan | Pyrami | IL | 32 | [email protected] | Duke |
47-
| 6 | Hattie | 671 Bristol Street | 5686 | M | Dante | Netagy | TN | 36 | [email protected] | Bond |
48-
| 13 | Nanette | 789 Madison Street | 32838 | F | Nogal | Quility | VA | 28 | null | Bates |
49-
| 18 | Dale | 467 Hutchinson Court | 4180 | M | Orick | null | MD | 33 | [email protected] | Adams |
50-
+------------------+-------------+----------------------+-----------+----------+--------+------------+---------+-------+-----------------------+------------+
43+
+------------------+-----------+-------------+------------+-------+----------+----------------------+------------+-----------------------+--------+---------+
44+
| account_number | balance | firstname | lastname | age | gender | address | employer | email | city | state |
45+
|------------------+-----------+-------------+------------+-------+----------+----------------------+------------+-----------------------+--------+---------|
46+
| 1 | 39225 | Amber | Duke | 32 | M | 880 Holmes Lane | Pyrami | [email protected] | Brogan | IL |
47+
| 6 | 5686 | Hattie | Bond | 36 | M | 671 Bristol Street | Netagy | [email protected] | Dante | TN |
48+
| 13 | 32838 | Nanette | Bates | 28 | F | 789 Madison Street | Quility | null | Nogal | VA |
49+
| 18 | 4180 | Dale | Adams | 33 | M | 467 Hutchinson Court | null | [email protected] | Orick | MD |
50+
+------------------+-----------+-------------+------------+-------+----------+----------------------+------------+-----------------------+--------+---------+
5151

5252

5353
Delimited Identifiers
@@ -76,14 +76,14 @@ Here are examples for quoting an index name by back ticks::
7676

7777
od> SELECT * FROM `accounts`;
7878
fetched rows / total rows = 4/4
79-
+------------------+-------------+----------------------+-----------+----------+--------+------------+---------+-------+-----------------------+------------+
80-
| account_number | firstname | address | balance | gender | city | employer | state | age | email | lastname |
81-
|------------------+-------------+----------------------+-----------+----------+--------+------------+---------+-------+-----------------------+------------|
82-
| 1 | Amber | 880 Holmes Lane | 39225 | M | Brogan | Pyrami | IL | 32 | [email protected] | Duke |
83-
| 6 | Hattie | 671 Bristol Street | 5686 | M | Dante | Netagy | TN | 36 | [email protected] | Bond |
84-
| 13 | Nanette | 789 Madison Street | 32838 | F | Nogal | Quility | VA | 28 | null | Bates |
85-
| 18 | Dale | 467 Hutchinson Court | 4180 | M | Orick | null | MD | 33 | [email protected] | Adams |
86-
+------------------+-------------+----------------------+-----------+----------+--------+------------+---------+-------+-----------------------+------------+
79+
+------------------+-----------+-------------+------------+-------+----------+----------------------+------------+-----------------------+--------+---------+
80+
| account_number | balance | firstname | lastname | age | gender | address | employer | email | city | state |
81+
|------------------+-----------+-------------+------------+-------+----------+----------------------+------------+-----------------------+--------+---------|
82+
| 1 | 39225 | Amber | Duke | 32 | M | 880 Holmes Lane | Pyrami | [email protected] | Brogan | IL |
83+
| 6 | 5686 | Hattie | Bond | 36 | M | 671 Bristol Street | Netagy | [email protected] | Dante | TN |
84+
| 13 | 32838 | Nanette | Bates | 28 | F | 789 Madison Street | Quility | null | Nogal | VA |
85+
| 18 | 4180 | Dale | Adams | 33 | M | 467 Hutchinson Court | null | [email protected] | Orick | MD |
86+
+------------------+-----------+-------------+------------+-------+----------+----------------------+------------+-----------------------+--------+---------+
8787

8888

8989
Case Sensitivity

elasticsearch/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ dependencies {
1313
compile group: 'org.elasticsearch', name: 'elasticsearch', version: "${es_version}"
1414
compile group: 'org.elasticsearch.client', name: 'elasticsearch-rest-high-level-client', version: "${es_version}"
1515
compile "io.github.resilience4j:resilience4j-retry:1.5.0"
16+
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.10.4'
17+
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.10.4'
1618

1719
testImplementation('org.junit.jupiter:junit-jupiter:5.6.2')
1820
testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '2.1'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
*
3+
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License").
6+
* You may not use this file except in compliance with the License.
7+
* A copy of the License is located at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* or in the "license" file accompanying this file. This file is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*
16+
*/
17+
18+
package com.amazon.opendistroforelasticsearch.sql.elasticsearch.data.value;
19+
20+
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
21+
import static java.time.temporal.ChronoField.HOUR_OF_DAY;
22+
import static java.time.temporal.ChronoField.MINUTE_OF_HOUR;
23+
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
24+
import static java.time.temporal.ChronoField.NANO_OF_SECOND;
25+
import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
26+
27+
import java.time.format.DateTimeFormatter;
28+
import java.time.format.DateTimeFormatterBuilder;
29+
import java.time.format.ResolverStyle;
30+
import java.time.format.SignStyle;
31+
import java.time.temporal.ChronoField;
32+
import java.util.Locale;
33+
import lombok.experimental.UtilityClass;
34+
35+
/**
36+
* DateTimeFormatter.
37+
* Reference org.elasticsearch.common.time.DateFormatters.
38+
*/
39+
@UtilityClass
40+
public class ElasticsearchDateFormatters {
41+
42+
public static final DateTimeFormatter TIME_ZONE_FORMATTER_NO_COLON =
43+
new DateTimeFormatterBuilder()
44+
.appendOffset("+HHmm", "Z")
45+
.toFormatter(Locale.ROOT)
46+
.withResolverStyle(ResolverStyle.STRICT);
47+
48+
public static final DateTimeFormatter STRICT_YEAR_MONTH_DAY_FORMATTER =
49+
new DateTimeFormatterBuilder()
50+
.appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
51+
.optionalStart()
52+
.appendLiteral("-")
53+
.appendValue(MONTH_OF_YEAR, 2, 2, SignStyle.NOT_NEGATIVE)
54+
.optionalStart()
55+
.appendLiteral('-')
56+
.appendValue(DAY_OF_MONTH, 2, 2, SignStyle.NOT_NEGATIVE)
57+
.optionalEnd()
58+
.optionalEnd()
59+
.toFormatter(Locale.ROOT)
60+
.withResolverStyle(ResolverStyle.STRICT);
61+
62+
public static final DateTimeFormatter STRICT_DATE_OPTIONAL_TIME_FORMATTER =
63+
new DateTimeFormatterBuilder()
64+
.append(STRICT_YEAR_MONTH_DAY_FORMATTER)
65+
.optionalStart()
66+
.appendLiteral('T')
67+
.optionalStart()
68+
.appendValue(HOUR_OF_DAY, 2, 2, SignStyle.NOT_NEGATIVE)
69+
.optionalStart()
70+
.appendLiteral(':')
71+
.appendValue(MINUTE_OF_HOUR, 2, 2, SignStyle.NOT_NEGATIVE)
72+
.optionalStart()
73+
.appendLiteral(':')
74+
.appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE)
75+
.optionalStart()
76+
.appendFraction(NANO_OF_SECOND, 1, 9, true)
77+
.optionalEnd()
78+
.optionalStart()
79+
.appendLiteral(',')
80+
.appendFraction(NANO_OF_SECOND, 1, 9, false)
81+
.optionalEnd()
82+
.optionalEnd()
83+
.optionalEnd()
84+
.optionalStart()
85+
.appendZoneOrOffsetId()
86+
.optionalEnd()
87+
.optionalStart()
88+
.append(TIME_ZONE_FORMATTER_NO_COLON)
89+
.optionalEnd()
90+
.optionalEnd()
91+
.optionalEnd()
92+
.toFormatter(Locale.ROOT)
93+
.withResolverStyle(ResolverStyle.STRICT);
94+
95+
public static final DateTimeFormatter SQL_LITERAL_DATE_TIME_FORMAT = DateTimeFormatter
96+
.ofPattern("yyyy-MM-dd HH:mm:ss");
97+
}

0 commit comments

Comments
 (0)