Skip to content

Commit 3fdf753

Browse files
committed
[Feature] implement transpose command as in the roadmap opensearch-project#4786 (opensearch-project#5011)
* transpose command implementation Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * transpose rows to columns Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * added argument type missing map and hashmap Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * added tests Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * added tests Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * added tests Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * added tests Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * added tests Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * added tests Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * added tests Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * added tests Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * added more validations Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * added validation Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * index.md formatting fix Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * doc format Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * coderabbit review fixes Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * added recommended changes Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * added recommended changes Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * for cross cluster failure debugging Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * for cross cluster failure debugging Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * for cross cluster failure debugging Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * trim columnName Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * per review moved to class varialble. Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * per review moved to class varialble. Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * added field resolution Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * fix by removing metadata field Signed-off-by: Asif Bashar <asif.bashar@gmail.com> * fixed explain test after removing of metadata fields in transpose result Signed-off-by: Asif Bashar <asif.bashar@gmail.com> --------- Signed-off-by: Asif Bashar <asif.bashar@gmail.com>
1 parent caabe38 commit 3fdf753

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

integ-test/src/test/java/org/opensearch/sql/ppl/NewAddedCommandsIT.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,6 @@ public void testAddColTotalCommand() throws IOException {
202202
}
203203
}
204204

205-
@Test
206-
public void testFieldFormatCommand() throws IOException {
207-
JSONObject result;
208-
try {
209-
executeQuery(
210-
String.format(
211-
"search source=%s | fieldformat double_balance = balance * 2 ", TEST_INDEX_BANK));
212-
} catch (ResponseException e) {
213-
result = new JSONObject(TestUtils.getResponseBody(e.getResponse()));
214-
verifyQuery(result);
215-
}
216-
}
217-
218205
@Test
219206
public void testTransposeCommand() throws IOException {
220207
JSONObject result;
@@ -226,6 +213,20 @@ public void testTransposeCommand() throws IOException {
226213
}
227214
}
228215

216+
@Test
217+
public void testFieldFormatCommand() throws IOException {
218+
JSONObject result;
219+
try {
220+
executeQuery(
221+
String.format(
222+
"search source=%s | fieldformat double_balance = balance * 2 ", TEST_INDEX_BANK));
223+
} catch (ResponseException e) {
224+
result = new JSONObject(TestUtils.getResponseBody(e.getResponse()));
225+
verifyQuery(result);
226+
}
227+
}
228+
229+
229230
private void verifyQuery(JSONObject result) throws IOException {
230231
if (isCalciteEnabled()) {
231232
assertFalse(result.getJSONArray("datarows").isEmpty());

ppl/src/main/antlr/OpenSearchPPLLexer.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ ML: 'ML';
4747
FILLNULL: 'FILLNULL';
4848
FLATTEN: 'FLATTEN';
4949
TRENDLINE: 'TRENDLINE';
50+
TRANSPOSE: 'TRANSPOSE';
5051
CHART: 'CHART';
5152
TIMECHART: 'TIMECHART';
5253
APPENDCOL: 'APPENDCOL';
@@ -162,7 +163,6 @@ INPUT: 'INPUT';
162163
OUTPUT: 'OUTPUT';
163164
PATH: 'PATH';
164165

165-
166166
// COMPARISON FUNCTION KEYWORDS
167167
CASE: 'CASE';
168168
ELSE: 'ELSE';

ppl/src/main/antlr/OpenSearchPPLParser.g4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ expression
860860
| expression NOT? BETWEEN expression AND expression # between
861861
;
862862

863+
863864
valueExpression
864865
: left = valueExpression binaryOperator = (STAR | DIVIDE | MODULE) right = valueExpression # binaryArithmetic
865866
| left = valueExpression binaryOperator = (PLUS | MINUS) right = valueExpression # binaryArithmetic
@@ -1687,5 +1688,6 @@ searchableKeyWord
16871688
| FIELDNAME
16881689
| ROW
16891690
| COL
1691+
| COLUMN_NAME
16901692
;
16911693

0 commit comments

Comments
 (0)