diff --git a/docs/experiment/ppl/cmd/rare.rst b/docs/experiment/ppl/cmd/rare.rst index 90611b408c..5450a794f9 100644 --- a/docs/experiment/ppl/cmd/rare.rst +++ b/docs/experiment/ppl/cmd/rare.rst @@ -13,7 +13,7 @@ Description ============ | Using ``rare`` command to find the least common tuple of values of all fields in the field list. -A maximum of 10 results is returned for each distinct tuple of values of the group-by fields. +**Note**: A maximum of 10 results is returned for each distinct tuple of values of the group-by fields. Syntax ============ diff --git a/docs/experiment/ppl/cmd/sort.rst b/docs/experiment/ppl/cmd/sort.rst index 2c83c15b7d..022fa54f7e 100644 --- a/docs/experiment/ppl/cmd/sort.rst +++ b/docs/experiment/ppl/cmd/sort.rst @@ -19,7 +19,7 @@ Syntax sort <[+|-] sort-field>... -* [+|-]: optional. The plus [+] for ascending order and a minus [-] for descending order. **Default:** ascending order. +* [+|-]: optional. The plus [+] stands for ascending order and NULL/MISSING first and a minus [-] stands for descending order and NULL/MISSING last. **Default:** ascending order and NULL/MISSING first. * sort-field: mandatory. The field used to sort. @@ -97,3 +97,20 @@ PPL query:: | 1 | M | 32 | +------------------+----------+-------+ +Example 4: Sort by field include null value +=========================================== + +The example show sort employer field by default option (ascending order and null first), the result show that null value is in the first row. + +PPL query:: + + od> source=accounts | sort employer | fields employer; + fetched rows / total rows = 4/4 + +------------+ + | employer | + |------------| + | null | + | Netagy | + | Pyrami | + | Quility | + +------------+ diff --git a/docs/experiment/ppl/cmd/stats.rst b/docs/experiment/ppl/cmd/stats.rst index 88e8d6ce94..ea8cd82c8f 100644 --- a/docs/experiment/ppl/cmd/stats.rst +++ b/docs/experiment/ppl/cmd/stats.rst @@ -13,7 +13,7 @@ Description ============ | Using ``stats`` command to calculate the aggregation from search result. -The following table catalogs the aggregation functions and also indicates how each one handles NULL/MISSING values is handled: +The following table catalogs the aggregation functions and also indicates how the NULL/MISSING values is handled: +----------+-------------+-------------+ | Function | NULL | MISSING | @@ -35,7 +35,7 @@ Syntax stats ... [by-clause]... -* aggregation: mandatory. A statistical aggregation function. The argument of aggregation must be field. +* aggregation: mandatory. A aggregation function. The argument of aggregation must be field. * by-clause: optional. The one or more fields to group the results by. **Default**: If no is specified, the stats command returns only one row, which is the aggregation over the entire result set. Example 1: Calculate the count of events diff --git a/elasticsearch/src/main/java/com/amazon/opendistroforelasticsearch/sql/elasticsearch/data/utils/ElasticsearchJsonContent.java b/elasticsearch/src/main/java/com/amazon/opendistroforelasticsearch/sql/elasticsearch/data/utils/ElasticsearchJsonContent.java index dd6bf6330c..e5b0ae64cb 100644 --- a/elasticsearch/src/main/java/com/amazon/opendistroforelasticsearch/sql/elasticsearch/data/utils/ElasticsearchJsonContent.java +++ b/elasticsearch/src/main/java/com/amazon/opendistroforelasticsearch/sql/elasticsearch/data/utils/ElasticsearchJsonContent.java @@ -90,7 +90,7 @@ public Iterator array() { @Override public boolean isNull() { - return value == null || value.isNull(); + return value == null || value.isNull() || (value.isArray() && value.isEmpty()); } @Override diff --git a/elasticsearch/src/test/java/com/amazon/opendistroforelasticsearch/sql/elasticsearch/data/value/ElasticsearchExprValueFactoryTest.java b/elasticsearch/src/test/java/com/amazon/opendistroforelasticsearch/sql/elasticsearch/data/value/ElasticsearchExprValueFactoryTest.java index f4e8b816f7..9fb03562bb 100644 --- a/elasticsearch/src/test/java/com/amazon/opendistroforelasticsearch/sql/elasticsearch/data/value/ElasticsearchExprValueFactoryTest.java +++ b/elasticsearch/src/test/java/com/amazon/opendistroforelasticsearch/sql/elasticsearch/data/value/ElasticsearchExprValueFactoryTest.java @@ -105,6 +105,11 @@ public void constructNullValue() { assertTrue(new ElasticsearchJsonContent(null).isNull()); } + @Test + public void constructNullArrayValue() { + assertEquals(nullValue(), tupleValue("{\"intV\":[]}").get("intV")); + } + @Test public void constructByte() { assertEquals(byteValue((byte) 1), tupleValue("{\"byteV\":1}").get("byteV")); diff --git a/workbench/.cypress/integration/ui.spec.js b/workbench/.cypress/integration/ui.spec.js index 11f03c8598..43301c047f 100644 --- a/workbench/.cypress/integration/ui.spec.js +++ b/workbench/.cypress/integration/ui.spec.js @@ -133,7 +133,7 @@ describe('Test SQL UI', () => { cy.wait(delay); // hard to get euiCodeBlock content, check length instead - cy.get('.euiCodeBlock__code').children().should('have.length', 37); + cy.get('.euiCodeBlock__code').children().should('have.length', 13); }); it('Test Clear button', () => { @@ -175,7 +175,12 @@ describe('Test and verify SQL downloads', () => { 'query': 'select * from accounts where balance > 49500' } }).then((response) => { - expect(response.body.data.resp).to.have.string(files[file]); + if (title === 'Download and verify CSV') { + expect(response.body.data.body).to.have.string(files[file]); + } + else { + expect(response.body.data.resp).to.have.string(files[file]); + } }); }); }); @@ -223,7 +228,7 @@ describe('Test table display', () => { cy.get('span.euiTableCellContent__text') .eq(24) .should((cell) => { - expect(cell).to.contain('2018-06-23'); + expect(cell).to.contain('comment_2_1'); }); }); }); diff --git a/workbench/.cypress/utils/constants.js b/workbench/.cypress/utils/constants.js index 9f696d0244..069c0e9b35 100644 --- a/workbench/.cypress/utils/constants.js +++ b/workbench/.cypress/utils/constants.js @@ -43,19 +43,19 @@ export const testQueries = [ title: 'Test GROUP BY', query: 'select count(*) from accounts group by gender;', cell_idx: 3, - expected_string: '507' + expected_string: '493' }, { title: 'Test GROUP BY with aliases and scalar function', query: 'SELECT ABS(age) AS a FROM accounts GROUP BY ABS(age);', cell_idx: 17, - expected_string: '28.0' + expected_string: '27' }, { title: 'Test GROUP BY and HAVING', query: 'SELECT age, MAX(balance) FROM accounts GROUP BY age HAVING MIN(balance) > 3000;', cell_idx: 5, - expected_string: '47257' + expected_string: '49119' }, { title: 'Test ORDER BY', @@ -75,7 +75,7 @@ export const files = { JSONFile: `"hits":[{"_index":"accounts","_type":"_doc","_id":"842","_score":0,"_source":{"account_number":842,"balance":49587,"firstname":"Meagan","lastname":"Buckner","age":23,"gender":"F","address":"833 Bushwick Court","employer":"Biospan","email":"meaganbuckner@biospan.com","city":"Craig","state":"TX"}},{"_index":"accounts","_type":"_doc","_id":"854","_score":0,"_source":{"account_number":854,"balance":49795,"firstname":"Jimenez","lastname":"Barry","age":25,"gender":"F","address":"603 Cooper Street","employer":"Verton","email":"jimenezbarry@verton.com","city":"Moscow","state":"AL"}},{"_index":"accounts","_type":"_doc","_id":"97","_score":0,"_source":{"account_number":97,"balance":49671,"firstname":"Karen","lastname":"Trujillo","age":40,"gender":"F","address":"512 Cumberland Walk","employer":"Tsunamia","email":"karentrujillo@tsunamia.com","city":"Fredericktown","state":"MO"}},{"_index":"accounts","_type":"_doc","_id":"168","_score":0,"_source":{"account_number":168,"balance":49568,"firstname":"Carissa","lastname":"Simon","age":20,"gender":"M","address":"975 Flatbush Avenue","employer":"Zillacom","email":"carissasimon@zillacom.com","city":"Neibert","state":"IL"}},{"_index":"accounts","_type":"_doc","_id":"240","_score":0,"_source":{"account_number":240,"balance":49741,"firstname":"Oconnor","lastname":"Clay","age":35,"gender":"F","address":"659 Highland Boulevard","employer":"Franscene","email":"oconnorclay@franscene.com","city":"Kilbourne","state":"NH"}},{"_index":"accounts","_type":"_doc","_id":"803","_score":0,"_source":{"account_number":803,"balance":49567,"firstname":"Marissa","lastname":"Spears","age":25,"gender":"M","address":"963 Highland Avenue","employer":"Centregy","email":"marissaspears@centregy.com","city":"Bloomington","state":"MS"}},{"_index":"accounts","_type":"_doc","_id":"248","_score":0,"_source":{"account_number":248,"balance":49989,"firstname":"West","lastname":"England","age":36,"gender":"M","address":"717 Hendrickson Place","employer":"Obliq","email":"westengland@obliq.com","city":"Maury","state":"WA"}}]`, JDBCFile: - `{"schema":[{"name":"account_number","type":"long"},{"name":"firstname","type":"text"},{"name":"gender","type":"text"},{"name":"city","type":"text"},{"name":"balance","type":"long"},{"name":"employer","type":"text"},{"name":"state","type":"text"},{"name":"email","type":"text"},{"name":"address","type":"text"},{"name":"lastname","type":"text"},{"name":"age","type":"long"}],"total":7,"datarows":[[842,"Meagan","F","Craig",49587,"Biospan","TX","meaganbuckner@biospan.com","833 Bushwick Court","Buckner",23],[854,"Jimenez","F","Moscow",49795,"Verton","AL","jimenezbarry@verton.com","603 Cooper Street","Barry",25],[97,"Karen","F","Fredericktown",49671,"Tsunamia","MO","karentrujillo@tsunamia.com","512 Cumberland Walk","Trujillo",40],[168,"Carissa","M","Neibert",49568,"Zillacom","IL","carissasimon@zillacom.com","975 Flatbush Avenue","Simon",20],[240,"Oconnor","F","Kilbourne",49741,"Franscene","NH","oconnorclay@franscene.com","659 Highland Boulevard","Clay",35],[803,"Marissa","M","Bloomington",49567,"Centregy","MS","marissaspears@centregy.com","963 Highland Avenue","Spears",25],[248,"West","M","Maury",49989,"Obliq","WA","westengland@obliq.com","717 Hendrickson Place","England",36]],"size":7,"status":200}`, + `{"schema":[{"name":"account_number","type":"long"},{"name":"firstname","type":"text"},{"name":"address","type":"text"},{"name":"balance","type":"long"},{"name":"gender","type":"text"},{"name":"city","type":"text"},{"name":"employer","type":"text"},{"name":"state","type":"text"},{"name":"age","type":"long"},{"name":"email","type":"text"},{"name":"lastname","type":"text"}],"datarows":[[842,"Meagan","833 Bushwick Court",49587,"F","Craig","Biospan","TX",23,"meaganbuckner@biospan.com","Buckner"],[854,"Jimenez","603 Cooper Street",49795,"F","Moscow","Verton","AL",25,"jimenezbarry@verton.com","Barry"],[97,"Karen","512 Cumberland Walk",49671,"F","Fredericktown","Tsunamia","MO",40,"karentrujillo@tsunamia.com","Trujillo"],[168,"Carissa","975 Flatbush Avenue",49568,"M","Neibert","Zillacom","IL",20,"carissasimon@zillacom.com","Simon"],[240,"Oconnor","659 Highland Boulevard",49741,"F","Kilbourne","Franscene","NH",35,"oconnorclay@franscene.com","Clay"],[803,"Marissa","963 Highland Avenue",49567,"M","Bloomington","Centregy","MS",25,"marissaspears@centregy.com","Spears"],[248,"West","717 Hendrickson Place",49989,"M","Maury","Obliq","WA",36,"westengland@obliq.com","England"]],"total":7,"size":7,"status":200}`, CSVFile: `account_number,firstname,address,balance,gender,city,employer,state,age,email,lastname 842,Meagan,833 Bushwick Court,49587,F,Craig,Biospan,TX,23,meaganbuckner@biospan.com,Buckner