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
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public EqlSearchRequest(StreamInput in) throws IOException {
fetchFields = in.readList(FieldAndFormat::new);
}
runtimeMappings = in.readMap();
} else {
runtimeMappings = emptyMap();
}
}

Expand Down Expand Up @@ -220,7 +222,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
if (fetchFields != null && fetchFields.isEmpty() == false) {
builder.field(KEY_FETCH_FIELDS, fetchFields);
}
if (runtimeMappings != null && runtimeMappings.isEmpty() == false) {
if (runtimeMappings != null) {
builder.field(KEY_RUNTIME_MAPPINGS, runtimeMappings);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Collections;
import java.util.List;

import static java.util.Collections.emptyMap;
import static org.elasticsearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder;
import static org.elasticsearch.xpack.ql.TestUtils.randomRuntimeMappings;

Expand Down Expand Up @@ -119,7 +120,7 @@ protected EqlSearchRequest mutateInstanceForVersion(EqlSearchRequest instance, V
mutatedInstance.keepAlive(instance.keepAlive());
mutatedInstance.keepOnCompletion(instance.keepOnCompletion());
mutatedInstance.fetchFields(version.onOrAfter(Version.V_7_13_0) ? instance.fetchFields() : null);
mutatedInstance.runtimeMappings(version.onOrAfter(Version.V_7_13_0) ? instance.runtimeMappings() : null);
mutatedInstance.runtimeMappings(version.onOrAfter(Version.V_7_13_0) ? instance.runtimeMappings() : emptyMap());

return mutatedInstance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ private static void loadEmpDatasetIntoEs(RestClient client, String index, String
// define the runtime field
createIndex.startObject("runtime");
{
createIndex.startObject("birth_date_day_of_week").field("type", "keyword");
createIndex.startObject("name").field("type", "keyword");
createIndex.startObject("script")
.field(
"source",
"if (doc['birth_date'].size()==0) return; "
+ "else emit(doc['birth_date'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
"if (doc['first_name.keyword'].size()==0) emit(' '.concat(doc['last_name.keyword'].value));"
+ " else emit(doc['first_name.keyword'].value.concat(' ').concat(doc['last_name.keyword'].value))"
);
createIndex.endObject();
createIndex.endObject();
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugin/sql/qa/server/src/main/resources/alias.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ DESCRIBE test_alias;
column | type | mapping
----------------------+---------------+---------------
birth_date |TIMESTAMP |datetime
birth_date_day_of_week|VARCHAR |keyword
dep |STRUCT |nested
dep.dep_id |VARCHAR |keyword
dep.dep_name |VARCHAR |text
Expand All @@ -51,6 +50,7 @@ hire_date |TIMESTAMP |datetime
languages |TINYINT |byte
last_name |VARCHAR |text
last_name.keyword |VARCHAR |keyword
name |VARCHAR |keyword
null_constant |VARCHAR |keyword
salary |INTEGER |integer
wildcard_name |VARCHAR |keyword
Expand All @@ -62,7 +62,6 @@ DESCRIBE "test_*";
column | type | mapping
----------------------+---------------+---------------
birth_date |TIMESTAMP |datetime
birth_date_day_of_week|VARCHAR |keyword
dep |STRUCT |nested
dep.dep_id |VARCHAR |keyword
dep.dep_name |VARCHAR |text
Expand All @@ -82,6 +81,7 @@ hire_date |TIMESTAMP |datetime
languages |TINYINT |byte
last_name |VARCHAR |text
last_name.keyword |VARCHAR |keyword
name |VARCHAR |keyword
null_constant |VARCHAR |keyword
salary |INTEGER |integer
wildcard_name |VARCHAR |keyword
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ DESCRIBE LIKE 'test_emp';
column | type | mapping
----------------------+---------------+---------------
birth_date |TIMESTAMP |datetime
birth_date_day_of_week|VARCHAR |keyword
dep |STRUCT |nested
dep.dep_id |VARCHAR |keyword
dep.dep_name |VARCHAR |text
Expand All @@ -297,6 +296,7 @@ hire_date |TIMESTAMP |datetime
languages |TINYINT |byte
last_name |VARCHAR |text
last_name.keyword |VARCHAR |keyword
name |VARCHAR |keyword
null_constant |VARCHAR |keyword
salary |INTEGER |integer
wildcard_name |VARCHAR |keyword
Expand All @@ -308,7 +308,6 @@ DESCRIBE LIKE 'test_emp%';
column | type | mapping
----------------------+---------------+---------------
birth_date |TIMESTAMP |datetime
birth_date_day_of_week|VARCHAR |keyword
dep |STRUCT |nested
dep.dep_id |VARCHAR |keyword
dep.dep_name |VARCHAR |text
Expand All @@ -328,6 +327,7 @@ hire_date |TIMESTAMP |datetime
languages |TINYINT |byte
last_name |VARCHAR |text
last_name.keyword |VARCHAR |keyword
name |VARCHAR |keyword
null_constant |VARCHAR |keyword
salary |INTEGER |integer
wildcard_name |VARCHAR |keyword
Expand All @@ -339,7 +339,6 @@ DESCRIBE "test_emp";
column | type | mapping
----------------------+---------------+---------------
birth_date |TIMESTAMP |datetime
birth_date_day_of_week|VARCHAR |keyword
dep |STRUCT |nested
dep.dep_id |VARCHAR |keyword
dep.dep_name |VARCHAR |text
Expand All @@ -354,6 +353,7 @@ hire_date |TIMESTAMP |datetime
languages |TINYINT |byte
last_name |VARCHAR |text
last_name.keyword |VARCHAR |keyword
name |VARCHAR |keyword
salary |INTEGER |integer
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,16 +534,18 @@ SELECT GREATEST(null, null, birth_date + INTERVAL 25 YEARS, hire_date + INTERVAL
;

ifNullWithRuntimeField
SELECT COUNT(*) c, IFNULL(birth_date_day_of_week, 'no day') AS day FROM test_emp GROUP BY day ORDER BY c;
SELECT COUNT(*) c, LEFT(IFNULL(name, 'never'), 1) AS n FROM test_emp GROUP BY n ORDER BY n DESC LIMIT 10;

c:l | day:s
c:l | n:s
---------------+---------------
8 |Monday
10 |Sunday
10 |no day
12 |Friday
13 |Saturday
14 |Wednesday
15 |Thursday
18 |Tuesday
2 |Z
3 |Y
1 |X
1 |W
3 |V
2 |U
3 |T
11 |S
3 |R
5 |P
;
23 changes: 4 additions & 19 deletions x-pack/plugin/sql/qa/server/src/main/resources/datetime.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,6 @@ SELECT ISO_DAY_OF_WEEK(birth_date) AS d, SUM(salary) s FROM test_emp GROUP BY d
null |430039
;

runtimeFieldDayOfWeek
SELECT birth_date_day_of_week, SUM(salary) s FROM test_emp GROUP BY birth_date_day_of_week ORDER BY birth_date_day_of_week DESC;

birth_date_day_of_week:s| s:i
------------------------+---------------
Wednesday |655169
Tuesday |888011
Thursday |740669
Sunday |386466
Saturday |643304
Monday |428067
Friday |653130
null |430039
;

isoWeekOfYear
schema::birth_date:ts|iso_week:i|week:i
SELECT birth_date, IW(birth_date) iso_week, WEEK(birth_date) week FROM test_emp WHERE IW(birth_date) < 8 AND week >2 ORDER BY iso_week;
Expand Down Expand Up @@ -1339,9 +1324,9 @@ SELECT CAST(hire_date AS LONG) AS date FROM test_emp GROUP BY date ORDER BY date
;

dateTimeAggByIsoDayOfWeekWithFilter
SELECT IDOW(birth_date) day, DAY_NAME(birth_date) name, COUNT(*) c FROM test_emp WHERE IDOW(birth_date) < 6 GROUP BY day, name ORDER BY day desc;
SELECT IDOW(birth_date) day, DAY_NAME(birth_date) dayname, COUNT(*) c FROM test_emp WHERE IDOW(birth_date) < 6 GROUP BY day, dayname ORDER BY day desc;

day:i | name:s | c:l
day:i | dayname:s | c:l
---------------+---------------+---------------
5 |Friday |12
4 |Thursday |15
Expand All @@ -1351,9 +1336,9 @@ SELECT IDOW(birth_date) day, DAY_NAME(birth_date) name, COUNT(*) c FROM test_emp
;

dateTimeAggByIsoDayOfWeek
SELECT IDOW(birth_date) day, DAY_NAME(birth_date) name, COUNT(*) c FROM test_emp GROUP BY day, name ORDER BY day desc;
SELECT IDOW(birth_date) day, DAY_NAME(birth_date) dayname, COUNT(*) c FROM test_emp GROUP BY day, dayname ORDER BY day desc;

day:i | name:s | c:l
day:i | dayname:s | c:l
---------------+---------------+---------------
7 |Sunday |10
6 |Saturday |13
Expand Down
94 changes: 47 additions & 47 deletions x-pack/plugin/sql/qa/server/src/main/resources/docs/docs.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ describeTable
// tag::describeTable
DESCRIBE emp;

column | type | mapping
----------------------+---------------+---------------
birth_date |TIMESTAMP |datetime
birth_date_day_of_week|VARCHAR |keyword
dep |STRUCT |nested
dep.dep_id |VARCHAR |keyword
dep.dep_name |VARCHAR |text
dep.dep_name.keyword |VARCHAR |keyword
dep.from_date |TIMESTAMP |datetime
dep.to_date |TIMESTAMP |datetime
emp_no |INTEGER |integer
first_name |VARCHAR |text
first_name.keyword |VARCHAR |keyword
gender |VARCHAR |keyword
hire_date |TIMESTAMP |datetime
languages |TINYINT |byte
last_name |VARCHAR |text
last_name.keyword |VARCHAR |keyword
salary |INTEGER |integer
column | type | mapping
--------------------+---------------+---------------
birth_date |TIMESTAMP |datetime
dep |STRUCT |nested
dep.dep_id |VARCHAR |keyword
dep.dep_name |VARCHAR |text
dep.dep_name.keyword|VARCHAR |keyword
dep.from_date |TIMESTAMP |datetime
dep.to_date |TIMESTAMP |datetime
emp_no |INTEGER |integer
first_name |VARCHAR |text
first_name.keyword |VARCHAR |keyword
gender |VARCHAR |keyword
hire_date |TIMESTAMP |datetime
languages |TINYINT |byte
last_name |VARCHAR |text
last_name.keyword |VARCHAR |keyword
name |VARCHAR |keyword
salary |INTEGER |integer

// end::describeTable
;
Expand All @@ -54,25 +54,25 @@ showColumns
// tag::showColumns
SHOW COLUMNS IN emp;

column | type | mapping
----------------------+---------------+---------------
birth_date |TIMESTAMP |datetime
birth_date_day_of_week|VARCHAR |keyword
dep |STRUCT |nested
dep.dep_id |VARCHAR |keyword
dep.dep_name |VARCHAR |text
dep.dep_name.keyword |VARCHAR |keyword
dep.from_date |TIMESTAMP |datetime
dep.to_date |TIMESTAMP |datetime
emp_no |INTEGER |integer
first_name |VARCHAR |text
first_name.keyword |VARCHAR |keyword
gender |VARCHAR |keyword
hire_date |TIMESTAMP |datetime
languages |TINYINT |byte
last_name |VARCHAR |text
last_name.keyword |VARCHAR |keyword
salary |INTEGER |integer
column | type | mapping
--------------------+---------------+---------------
birth_date |TIMESTAMP |datetime
dep |STRUCT |nested
dep.dep_id |VARCHAR |keyword
dep.dep_name |VARCHAR |text
dep.dep_name.keyword|VARCHAR |keyword
dep.from_date |TIMESTAMP |datetime
dep.to_date |TIMESTAMP |datetime
emp_no |INTEGER |integer
first_name |VARCHAR |text
first_name.keyword |VARCHAR |keyword
gender |VARCHAR |keyword
hire_date |TIMESTAMP |datetime
languages |TINYINT |byte
last_name |VARCHAR |text
last_name.keyword |VARCHAR |keyword
name |VARCHAR |keyword
salary |INTEGER |integer

// end::showColumns
;
Expand Down Expand Up @@ -487,9 +487,9 @@ wildcardWithOrder
// tag::wildcardWithOrder
SELECT * FROM emp LIMIT 1;

birth_date |birth_date_day_of_week| emp_no | first_name | gender | hire_date | languages | last_name | salary
--------------------+----------------------+---------------+---------------+---------------+--------------------+---------------+---------------+---------------
1953-09-02T00:00:00Z|Wednesday |10001 |Georgi |M |1986-06-26T00:00:00Z|2 |Facello |57305
birth_date | emp_no | first_name | gender | hire_date | languages | last_name | name | salary
--------------------+---------------+---------------+---------------+------------------------+---------------+---------------+---------------+---------------
1953-09-02T00:00:00Z|10001 |Georgi |M |1986-06-26T00:00:00.000Z|2 |Facello |Georgi Facello |57305

// end::wildcardWithOrder
;
Expand All @@ -498,9 +498,9 @@ fromTable
// tag::fromTable
SELECT * FROM emp LIMIT 1;

birth_date |birth_date_day_of_week| emp_no | first_name | gender | hire_date | languages | last_name | salary
--------------------+----------------------+---------------+---------------+---------------+--------------------+---------------+---------------+---------------
1953-09-02T00:00:00Z|Wednesday |10001 |Georgi |M |1986-06-26T00:00:00Z|2 |Facello |57305
birth_date | emp_no | first_name | gender | hire_date | languages | last_name | name | salary
--------------------+---------------+---------------+---------------+------------------------+---------------+---------------+---------------+---------------
1953-09-02T00:00:00Z|10001 |Georgi |M |1986-06-26T00:00:00.000Z|2 |Facello |Georgi Facello |57305


// end::fromTable
Expand All @@ -510,9 +510,9 @@ fromTableQuoted
// tag::fromTableQuoted
SELECT * FROM "emp" LIMIT 1;

birth_date |birth_date_day_of_week| emp_no | first_name | gender | hire_date | languages | last_name | salary
--------------------+----------------------+---------------+---------------+---------------+--------------------+---------------+---------------+---------------
1953-09-02T00:00:00Z|Wednesday |10001 |Georgi |M |1986-06-26T00:00:00Z|2 |Facello |57305
birth_date | emp_no | first_name | gender | hire_date | languages | last_name | name | salary
--------------------+---------------+---------------+---------------+------------------------+---------------+---------------+---------------+---------------
1953-09-02T00:00:00Z|10001 |Georgi |M |1986-06-26T00:00:00.000Z|2 |Facello |Georgi Facello |57305

// end::fromTableQuoted
;
Expand Down
24 changes: 13 additions & 11 deletions x-pack/plugin/sql/qa/server/src/main/resources/filter.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,21 @@ SELECT count(*) AS c FROM test_emp WHERE birth_date::time IN ('00:00:00Z'::TIME,
;

inWithRuntimeField
SELECT COUNT(*) AS c, birth_date_day_of_week FROM test_emp WHERE birth_date_day_of_week IN ('Saturday', 'Sunday') GROUP BY birth_date_day_of_week;
SELECT COUNT(*) AS c, LEFT(name, 1) AS first_letter FROM test_emp WHERE first_letter IN ('X', 'Y', 'Z') GROUP BY first_letter;

c:l |birth_date_day_of_week:s
---------------+------------------------
13 |Saturday
10 |Sunday
c:l |first_letter:s
---------------+--------------
1 |X
3 |Y
2 |Z
;

inWithDayName
SELECT COUNT(*) AS c, DAY_NAME(birth_date) FROM test_emp WHERE DAY_NAME(birth_date) IN ('Saturday', 'Sunday') GROUP BY DAY_NAME(birth_date);
inWithConcat
SELECT COUNT(*) AS c, LEFT(CONCAT(first_name, last_name), 1) AS first_letter FROM test_emp WHERE first_letter IN ('X', 'Y', 'Z') GROUP BY first_letter;

c:l |DAY_NAME(birth_date):s
---------------+----------------------
13 |Saturday
10 |Sunday
c:l |first_letter:s
---------------+--------------
1 |X
3 |Y
2 |Z
;
16 changes: 8 additions & 8 deletions x-pack/plugin/sql/qa/server/src/main/resources/fulltext.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ null |1.9161749939033146|0.1480828817161133 |74999 |28336
;

runtimeFieldWithQuery
SELECT COUNT(*) AS c, birth_date_day_of_week FROM test_emp WHERE QUERY('T*','default_field=birth_date_day_of_week') OR QUERY('S*','default_field=birth_date_day_of_week') GROUP BY birth_date_day_of_week ORDER BY c;

c:l |birth_date_day_of_week:s
---------------+------------------------
10 |Sunday
13 |Saturday
15 |Thursday
18 |Tuesday
SELECT COUNT(*) AS c, name FROM test_emp WHERE QUERY('T*','default_field=name') OR QUERY('O*','default_field=name') GROUP BY name ORDER BY c;

c:l | name:s
---------------+-----------------
1 |Otmar Herbst
1 |Tse Herber
1 |Tuval Kalloufi
1 |Tzvetan Zielinski
;
Loading