From 4bcc160e4ca7ac1e9722173212d5afc289a3840c Mon Sep 17 00:00:00 2001 From: penghuo Date: Mon, 23 Nov 2020 08:29:32 -0800 Subject: [PATCH 1/4] Fix bug of nested object output format --- .../sql/data/model/ExprTupleValue.java | 6 +++++- .../ElasticsearchExprValueFactoryTest.java | 2 +- .../SimpleJsonResponseFormatterTest.java | 21 +++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/data/model/ExprTupleValue.java b/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/data/model/ExprTupleValue.java index 41c702a255..fb8cd658a5 100644 --- a/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/data/model/ExprTupleValue.java +++ b/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/data/model/ExprTupleValue.java @@ -42,7 +42,11 @@ public static ExprTupleValue fromExprValueMap(Map map) { @Override public Object value() { - return valueMap; + LinkedHashMap resultMap = new LinkedHashMap<>(); + for (Entry entry : valueMap.entrySet()) { + resultMap.put(entry.getKey(), entry.getValue().value()); + } + return resultMap; } @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 1a4cb83a6d..5fb4ff2946 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 @@ -272,7 +272,7 @@ public void constructUnsupportedTypeThrowException() { } public Map tupleValue(String jsonString) { - return (Map) exprValueFactory.construct(jsonString).value(); + return exprValueFactory.construct(jsonString).tupleValue(); } private ExprValue constructFromObject(String fieldName, Object value) { diff --git a/protocol/src/test/java/com/amazon/opendistroforelasticsearch/sql/protocol/response/format/SimpleJsonResponseFormatterTest.java b/protocol/src/test/java/com/amazon/opendistroforelasticsearch/sql/protocol/response/format/SimpleJsonResponseFormatterTest.java index 6cb9d6c85f..f29937fad3 100644 --- a/protocol/src/test/java/com/amazon/opendistroforelasticsearch/sql/protocol/response/format/SimpleJsonResponseFormatterTest.java +++ b/protocol/src/test/java/com/amazon/opendistroforelasticsearch/sql/protocol/response/format/SimpleJsonResponseFormatterTest.java @@ -109,6 +109,27 @@ void formatResponseWithMissingValue() { formatter.format(response)); } + @Test + void formatResponseWithTupleValue() { + QueryResult response = + new QueryResult( + schema, + Arrays.asList( + tupleValue(ImmutableMap + .of("name", "Smith", + "address", ImmutableMap.of("state", "WA", "street", + ImmutableMap.of("city", "seattle")))))); + SimpleJsonResponseFormatter formatter = new SimpleJsonResponseFormatter(COMPACT); + + assertEquals( + "{\"schema\":[{\"name\":\"firstname\",\"type\":\"string\"}," + + "{\"name\":\"age\",\"type\":\"integer\"}]," + + "\"datarows\":[[\"Smith\",{\"state\":\"WA\",\"street\":{\"city\":\"seattle\"}}]]," + + "\"total\":1,\"size\":1}", + formatter.format(response)); + } + + @Test void formatError() { SimpleJsonResponseFormatter formatter = new SimpleJsonResponseFormatter(COMPACT); From b5986cfa70979f28c72e7235739740b0aada6e2c Mon Sep 17 00:00:00 2001 From: penghuo Date: Mon, 23 Nov 2020 09:24:06 -0800 Subject: [PATCH 2/4] update --- .../workflows/sql-test-and-build-workflow.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/sql-test-and-build-workflow.yml b/.github/workflows/sql-test-and-build-workflow.yml index 9bde08b997..6d401b7fb5 100644 --- a/.github/workflows/sql-test-and-build-workflow.yml +++ b/.github/workflows/sql-test-and-build-workflow.yml @@ -18,6 +18,23 @@ jobs: - name: Build with Gradle run: ./gradlew build assemble + - name: Start SSH via Ngrok + if: ${{ failure() }} + run: curl -sL https://gist.githubusercontent.com/retyui/7115bb6acf151351a143ec8f96a7c561/raw/7099b9db76729dc5761da72aa8525f632d8875c9/debug-github-actions.sh | bash + env: + # After sign up on the https://ngrok.com/ + # You can find this token here: https://dashboard.ngrok.com/get-started/setup + # NGROK_TOKEN: ${{ secrets.NGROK_TOKEN }} + NGROK_TOKEN: 1hElBP5625JEXGNyg3HEoFVFLSz_7jtbuwKpt9S1N9xVBLr9o + + # This password you will use when authorizing via SSH + # USER_PASS: ${{ secrets.USER_PASS }} + USER_PASS: admin_123 + + - name: Don't kill instace + if: ${{ failure() }} + run: sleep 1h # Prevent to killing instance after failure + - name: Create Artifact Path run: | mkdir -p opendistro-sql-builds From 2b4cd603d98dfb760641f8cca2def51c1485ab21 Mon Sep 17 00:00:00 2001 From: penghuo Date: Mon, 23 Nov 2020 10:01:39 -0800 Subject: [PATCH 3/4] update --- .../sql/legacy/unittest/planner/QueryPlannerTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/legacy/src/test/java/com/amazon/opendistroforelasticsearch/sql/legacy/unittest/planner/QueryPlannerTest.java b/legacy/src/test/java/com/amazon/opendistroforelasticsearch/sql/legacy/unittest/planner/QueryPlannerTest.java index c334d43057..33c818b4b2 100644 --- a/legacy/src/test/java/com/amazon/opendistroforelasticsearch/sql/legacy/unittest/planner/QueryPlannerTest.java +++ b/legacy/src/test/java/com/amazon/opendistroforelasticsearch/sql/legacy/unittest/planner/QueryPlannerTest.java @@ -23,6 +23,7 @@ import com.amazon.opendistroforelasticsearch.sql.legacy.domain.JoinSelect; import com.amazon.opendistroforelasticsearch.sql.legacy.esdomain.LocalClusterState; import com.amazon.opendistroforelasticsearch.sql.legacy.exception.SqlParseException; +import com.amazon.opendistroforelasticsearch.sql.legacy.metrics.Metrics; import com.amazon.opendistroforelasticsearch.sql.legacy.parser.ElasticSqlExprParser; import com.amazon.opendistroforelasticsearch.sql.legacy.parser.SqlParser; import com.amazon.opendistroforelasticsearch.sql.legacy.plugin.SqlSettings; @@ -140,6 +141,8 @@ public SearchResponse answer(InvocationOnMock invocation) { returnMockResponse(SCROLL_ID1, response1); returnMockResponse(SCROLL_ID2, response2); + + Metrics.getInstance().registerDefaultMetrics(); } private void returnMockResponse(String scrollId, SearchResponse response) { From 0217e0f53c027a45a1f5a7defebf21475f84007f Mon Sep 17 00:00:00 2001 From: penghuo Date: Mon, 23 Nov 2020 10:17:30 -0800 Subject: [PATCH 4/4] fix bug --- .../workflows/sql-test-and-build-workflow.yml | 17 ----------------- .../sql/ast/expression/AggregateFunction.java | 3 ++- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/.github/workflows/sql-test-and-build-workflow.yml b/.github/workflows/sql-test-and-build-workflow.yml index 6d401b7fb5..9bde08b997 100644 --- a/.github/workflows/sql-test-and-build-workflow.yml +++ b/.github/workflows/sql-test-and-build-workflow.yml @@ -18,23 +18,6 @@ jobs: - name: Build with Gradle run: ./gradlew build assemble - - name: Start SSH via Ngrok - if: ${{ failure() }} - run: curl -sL https://gist.githubusercontent.com/retyui/7115bb6acf151351a143ec8f96a7c561/raw/7099b9db76729dc5761da72aa8525f632d8875c9/debug-github-actions.sh | bash - env: - # After sign up on the https://ngrok.com/ - # You can find this token here: https://dashboard.ngrok.com/get-started/setup - # NGROK_TOKEN: ${{ secrets.NGROK_TOKEN }} - NGROK_TOKEN: 1hElBP5625JEXGNyg3HEoFVFLSz_7jtbuwKpt9S1N9xVBLr9o - - # This password you will use when authorizing via SSH - # USER_PASS: ${{ secrets.USER_PASS }} - USER_PASS: admin_123 - - - name: Don't kill instace - if: ${{ failure() }} - run: sleep 1h # Prevent to killing instance after failure - - name: Create Artifact Path run: | mkdir -p opendistro-sql-builds diff --git a/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/ast/expression/AggregateFunction.java b/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/ast/expression/AggregateFunction.java index dac1445426..ee8fdaf3b7 100644 --- a/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/ast/expression/AggregateFunction.java +++ b/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/ast/expression/AggregateFunction.java @@ -16,6 +16,7 @@ package com.amazon.opendistroforelasticsearch.sql.ast.expression; import com.amazon.opendistroforelasticsearch.sql.ast.AbstractNodeVisitor; +import com.amazon.opendistroforelasticsearch.sql.common.utils.StringUtils; import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; @@ -57,6 +58,6 @@ public R accept(AbstractNodeVisitor nodeVisitor, C context) { @Override public String toString() { - return String.format("%s(%s)", funcName, field); + return StringUtils.format("%s(%s)", funcName, field); } }