diff --git a/.github/workflows/sql-test-and-build-workflow.yml b/.github/workflows/sql-test-and-build-workflow.yml index b70092713e..3d063a2bfc 100644 --- a/.github/workflows/sql-test-and-build-workflow.yml +++ b/.github/workflows/sql-test-and-build-workflow.yml @@ -20,25 +20,32 @@ on: jobs: build: strategy: + # Run all jobs + fail-fast: false matrix: - java: - - 11 - - 17 - runs-on: ubuntu-latest + entry: + - { os: ubuntu-latest, java: 11 } + - { os: windows-latest, java: 11, os_build_args: -x doctest -x integTest -x jacocoTestReport -x compileJdbc} + - { os: macos-latest, java: 11, os_build_args: -x doctest -x integTest -x jacocoTestReport -x compileJdbc } + - { os: ubuntu-latest, java: 17 } + - { os: windows-latest, java: 17, os_build_args: -x doctest -x integTest -x jacocoTestReport -x compileJdbc } + - { os: macos-latest, java: 17, os_build_args: -x doctest -x integTest -x jacocoTestReport -x compileJdbc } + runs-on: ${{ matrix.entry.os }} steps: - uses: actions/checkout@v3 - + - name: Set up JDK ${{ matrix.java }} uses: actions/setup-java@v3 with: distribution: 'temurin' - java-version: ${{ matrix.java }} - + java-version: ${{ matrix.entry.java }} + - name: Build with Gradle - run: ./gradlew --continue build assemble + run: ./gradlew --continue build ${{ matrix.entry.os_build_args }} - name: Run backward compatibility tests + if: ${{ matrix.entry.os == 'ubuntu-latest' }} run: ./scripts/bwctest.sh - name: Create Artifact Path @@ -48,7 +55,7 @@ jobs: # This step uses the codecov-action Github action: https://github.com/codecov/codecov-action - name: Upload SQL Coverage Report - if: always() + if: ${{ always() && matrix.entry.os == 'ubuntu-latest' }} uses: codecov/codecov-action@v3 with: flags: sql-engine @@ -57,11 +64,11 @@ jobs: - name: Upload Artifacts uses: actions/upload-artifact@v2 with: - name: opensearch-sql + name: opensearch-sql-${{ matrix.entry.os }} path: opensearch-sql-builds - name: Upload test reports - if: always() + if: ${{ always() && matrix.entry.os == 'ubuntu-latest' }} uses: actions/upload-artifact@v2 with: name: test-reports diff --git a/.github/workflows/sql-workbench-test-and-build-workflow.yml b/.github/workflows/sql-workbench-test-and-build-workflow.yml index 7c0e2549e7..e5f52065b6 100644 --- a/.github/workflows/sql-workbench-test-and-build-workflow.yml +++ b/.github/workflows/sql-workbench-test-and-build-workflow.yml @@ -16,8 +16,15 @@ env: jobs: build: - runs-on: ubuntu-latest + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.os }} steps: + - name: Enable longer filenames + if: ${{ matrix.os == 'windows-latest' }} + run: git config --system core.longpaths true + - name: Checkout Plugin uses: actions/checkout@v3 @@ -51,7 +58,7 @@ jobs: yarn test:jest --coverage - name: Upload coverage - if: always() + if: ${{ matrix.os == 'ubuntu-latest' }} uses: codecov/codecov-action@v3 with: flags: query-workbench @@ -68,5 +75,6 @@ jobs: if: always() uses: actions/upload-artifact@v1 # can't update to v3 because upload fails with: - name: workbench + name: workbench-${{ matrix.os }} path: ../OpenSearch-Dashboards/plugins/workbench/build + \ No newline at end of file diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/utils/PrettyFormatterTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/utils/PrettyFormatterTest.java index fc20d818e6..f876b14110 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/utils/PrettyFormatterTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/utils/PrettyFormatterTest.java @@ -31,11 +31,13 @@ public void assertFormatterWithoutContentInside() throws IOException { public void assertFormatterOutputsPrettyJson() throws IOException { String explainFormattedPrettyFilePath = TestUtils.getResourceFilePath( "/src/test/resources/expectedOutput/explain_format_pretty.json"); - String explainFormattedPretty = Files.toString(new File(explainFormattedPrettyFilePath), StandardCharsets.UTF_8); + String explainFormattedPretty = Files.toString(new File(explainFormattedPrettyFilePath), StandardCharsets.UTF_8) + .replaceAll("\r", ""); String explainFormattedOnelineFilePath = TestUtils.getResourceFilePath( "/src/test/resources/explain_format_oneline.json"); - String explainFormattedOneline = Files.toString(new File(explainFormattedOnelineFilePath), StandardCharsets.UTF_8); + String explainFormattedOneline = Files.toString(new File(explainFormattedOnelineFilePath), StandardCharsets.UTF_8) + .replaceAll("\r", ""); String result = JsonPrettyFormatter.format(explainFormattedOneline); assertThat(result, equalTo(explainFormattedPretty)); diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java index 04aedc0f01..3614d82e59 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/AggregationQueryBuilderTest.java @@ -12,6 +12,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; +import static org.opensearch.sql.common.utils.StringUtils.format; import static org.opensearch.sql.data.type.ExprCoreType.DATE; import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; @@ -72,31 +73,31 @@ void set_up() { @Test void should_build_composite_aggregation_for_field_reference() { - assertEquals( - "{\n" - + " \"composite_buckets\" : {\n" - + " \"composite\" : {\n" - + " \"size\" : 1000,\n" - + " \"sources\" : [ {\n" - + " \"name\" : {\n" - + " \"terms\" : {\n" - + " \"field\" : \"name\",\n" - + " \"missing_bucket\" : true,\n" - + " \"missing_order\" : \"first\",\n" - + " \"order\" : \"asc\"\n" - + " }\n" - + " }\n" - + " } ]\n" - + " },\n" - + " \"aggregations\" : {\n" - + " \"avg(age)\" : {\n" - + " \"avg\" : {\n" - + " \"field\" : \"age\"\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"composite_buckets\" : {%n" + + " \"composite\" : {%n" + + " \"size\" : 1000,%n" + + " \"sources\" : [ {%n" + + " \"name\" : {%n" + + " \"terms\" : {%n" + + " \"field\" : \"name\",%n" + + " \"missing_bucket\" : true,%n" + + " \"missing_order\" : \"first\",%n" + + " \"order\" : \"asc\"%n" + + " }%n" + + " }%n" + + " } ]%n" + + " },%n" + + " \"aggregations\" : {%n" + + " \"avg(age)\" : {%n" + + " \"avg\" : {%n" + + " \"field\" : \"age\"%n" + + " }%n" + + " }%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("avg(age)", new AvgAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER))), @@ -105,31 +106,31 @@ void should_build_composite_aggregation_for_field_reference() { @Test void should_build_composite_aggregation_for_field_reference_with_order() { - assertEquals( - "{\n" - + " \"composite_buckets\" : {\n" - + " \"composite\" : {\n" - + " \"size\" : 1000,\n" - + " \"sources\" : [ {\n" - + " \"name\" : {\n" - + " \"terms\" : {\n" - + " \"field\" : \"name\",\n" - + " \"missing_bucket\" : true,\n" - + " \"missing_order\" : \"last\",\n" - + " \"order\" : \"desc\"\n" - + " }\n" - + " }\n" - + " } ]\n" - + " },\n" - + " \"aggregations\" : {\n" - + " \"avg(age)\" : {\n" - + " \"avg\" : {\n" - + " \"field\" : \"age\"\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"composite_buckets\" : {%n" + + " \"composite\" : {%n" + + " \"size\" : 1000,%n" + + " \"sources\" : [ {%n" + + " \"name\" : {%n" + + " \"terms\" : {%n" + + " \"field\" : \"name\",%n" + + " \"missing_bucket\" : true,%n" + + " \"missing_order\" : \"last\",%n" + + " \"order\" : \"desc\"%n" + + " }%n" + + " }%n" + + " } ]%n" + + " },%n" + + " \"aggregations\" : {%n" + + " \"avg(age)\" : {%n" + + " \"avg\" : {%n" + + " \"field\" : \"age\"%n" + + " }%n" + + " }%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("avg(age)", new AvgAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER))), @@ -152,31 +153,31 @@ void should_build_type_mapping_for_field_reference() { @Test void should_build_composite_aggregation_for_field_reference_of_keyword() { - assertEquals( - "{\n" - + " \"composite_buckets\" : {\n" - + " \"composite\" : {\n" - + " \"size\" : 1000,\n" - + " \"sources\" : [ {\n" - + " \"name\" : {\n" - + " \"terms\" : {\n" - + " \"field\" : \"name.keyword\",\n" - + " \"missing_bucket\" : true,\n" - + " \"missing_order\" : \"first\",\n" - + " \"order\" : \"asc\"\n" - + " }\n" - + " }\n" - + " } ]\n" - + " },\n" - + " \"aggregations\" : {\n" - + " \"avg(age)\" : {\n" - + " \"avg\" : {\n" - + " \"field\" : \"age\"\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"composite_buckets\" : {%n" + + " \"composite\" : {%n" + + " \"size\" : 1000,%n" + + " \"sources\" : [ {%n" + + " \"name\" : {%n" + + " \"terms\" : {%n" + + " \"field\" : \"name.keyword\",%n" + + " \"missing_bucket\" : true,%n" + + " \"missing_order\" : \"first\",%n" + + " \"order\" : \"asc\"%n" + + " }%n" + + " }%n" + + " } ]%n" + + " },%n" + + " \"aggregations\" : {%n" + + " \"avg(age)\" : {%n" + + " \"avg\" : {%n" + + " \"field\" : \"age\"%n" + + " }%n" + + " }%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("avg(age)", new AvgAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER))), @@ -201,37 +202,37 @@ void should_build_composite_aggregation_for_expression() { Expression expr = invocation.getArgument(0); return expr.toString(); }).when(serializer).serialize(any()); - assertEquals( - "{\n" - + " \"composite_buckets\" : {\n" - + " \"composite\" : {\n" - + " \"size\" : 1000,\n" - + " \"sources\" : [ {\n" - + " \"age\" : {\n" - + " \"terms\" : {\n" - + " \"script\" : {\n" - + " \"source\" : \"asin(age)\",\n" - + " \"lang\" : \"opensearch_query_expression\"\n" - + " },\n" - + " \"missing_bucket\" : true,\n" - + " \"missing_order\" : \"first\",\n" - + " \"order\" : \"asc\"\n" - + " }\n" - + " }\n" - + " } ]\n" - + " },\n" - + " \"aggregations\" : {\n" - + " \"avg(balance)\" : {\n" - + " \"avg\" : {\n" - + " \"script\" : {\n" - + " \"source\" : \"abs(balance)\",\n" - + " \"lang\" : \"opensearch_query_expression\"\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"composite_buckets\" : {%n" + + " \"composite\" : {%n" + + " \"size\" : 1000,%n" + + " \"sources\" : [ {%n" + + " \"age\" : {%n" + + " \"terms\" : {%n" + + " \"script\" : {%n" + + " \"source\" : \"asin(age)\",%n" + + " \"lang\" : \"opensearch_query_expression\"%n" + + " },%n" + + " \"missing_bucket\" : true,%n" + + " \"missing_order\" : \"first\",%n" + + " \"order\" : \"asc\"%n" + + " }%n" + + " }%n" + + " } ]%n" + + " },%n" + + " \"aggregations\" : {%n" + + " \"avg(balance)\" : {%n" + + " \"avg\" : {%n" + + " \"script\" : {%n" + + " \"source\" : \"abs(balance)\",%n" + + " \"lang\" : \"opensearch_query_expression\"%n" + + " }%n" + + " }%n" + + " }%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("avg(balance)", new AvgAggregator( @@ -241,40 +242,40 @@ void should_build_composite_aggregation_for_expression() { @Test void should_build_composite_aggregation_follow_with_order_by_position() { - assertEquals( - "{\n" - + " \"composite_buckets\" : {\n" - + " \"composite\" : {\n" - + " \"size\" : 1000,\n" - + " \"sources\" : [ {\n" - + " \"name\" : {\n" - + " \"terms\" : {\n" - + " \"field\" : \"name\",\n" - + " \"missing_bucket\" : true,\n" - + " \"missing_order\" : \"last\",\n" - + " \"order\" : \"desc\"\n" - + " }\n" - + " }\n" - + " }, {\n" - + " \"age\" : {\n" - + " \"terms\" : {\n" - + " \"field\" : \"age\",\n" - + " \"missing_bucket\" : true,\n" - + " \"missing_order\" : \"first\",\n" - + " \"order\" : \"asc\"\n" - + " }\n" - + " }\n" - + " } ]\n" - + " },\n" - + " \"aggregations\" : {\n" - + " \"avg(balance)\" : {\n" - + " \"avg\" : {\n" - + " \"field\" : \"balance\"\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"composite_buckets\" : {%n" + + " \"composite\" : {%n" + + " \"size\" : 1000,%n" + + " \"sources\" : [ {%n" + + " \"name\" : {%n" + + " \"terms\" : {%n" + + " \"field\" : \"name\",%n" + + " \"missing_bucket\" : true,%n" + + " \"missing_order\" : \"last\",%n" + + " \"order\" : \"desc\"%n" + + " }%n" + + " }%n" + + " }, {%n" + + " \"age\" : {%n" + + " \"terms\" : {%n" + + " \"field\" : \"age\",%n" + + " \"missing_bucket\" : true,%n" + + " \"missing_order\" : \"first\",%n" + + " \"order\" : \"asc\"%n" + + " }%n" + + " }%n" + + " } ]%n" + + " },%n" + + " \"aggregations\" : {%n" + + " \"avg(balance)\" : {%n" + + " \"avg\" : {%n" + + " \"field\" : \"balance\"%n" + + " }%n" + + " }%n" + + " }%n" + + " }%n" + + "}"), buildQuery( agg(named("avg(balance)", avg(ref("balance", INTEGER), INTEGER))), group(named("age", ref("age", INTEGER)), named("name", ref("name", STRING))), @@ -298,14 +299,14 @@ void should_build_type_mapping_for_expression() { @Test void should_build_aggregation_without_bucket() { - assertEquals( - "{\n" - + " \"avg(balance)\" : {\n" - + " \"avg\" : {\n" - + " \"field\" : \"balance\"\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"avg(balance)\" : {%n" + + " \"avg\" : {%n" + + " \"field\" : \"balance\"%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("avg(balance)", new AvgAggregator( @@ -315,29 +316,29 @@ void should_build_aggregation_without_bucket() { @Test void should_build_filter_aggregation() { - assertEquals( - "{\n" - + " \"avg(age) filter(where age > 34)\" : {\n" - + " \"filter\" : {\n" - + " \"range\" : {\n" - + " \"age\" : {\n" - + " \"from\" : 20,\n" - + " \"to\" : null,\n" - + " \"include_lower\" : false,\n" - + " \"include_upper\" : true,\n" - + " \"boost\" : 1.0\n" - + " }\n" - + " }\n" - + " },\n" - + " \"aggregations\" : {\n" - + " \"avg(age) filter(where age > 34)\" : {\n" - + " \"avg\" : {\n" - + " \"field\" : \"age\"\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"avg(age) filter(where age > 34)\" : {%n" + + " \"filter\" : {%n" + + " \"range\" : {%n" + + " \"age\" : {%n" + + " \"from\" : 20,%n" + + " \"to\" : null,%n" + + " \"include_lower\" : false,%n" + + " \"include_upper\" : true,%n" + + " \"boost\" : 1.0%n" + + " }%n" + + " }%n" + + " },%n" + + " \"aggregations\" : {%n" + + " \"avg(age) filter(where age > 34)\" : {%n" + + " \"avg\" : {%n" + + " \"field\" : \"age\"%n" + + " }%n" + + " }%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList(named("avg(age) filter(where age > 34)", new AvgAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER) @@ -347,46 +348,46 @@ void should_build_filter_aggregation() { @Test void should_build_filter_aggregation_group_by() { - assertEquals( - "{\n" - + " \"composite_buckets\" : {\n" - + " \"composite\" : {\n" - + " \"size\" : 1000,\n" - + " \"sources\" : [ {\n" - + " \"gender\" : {\n" - + " \"terms\" : {\n" - + " \"field\" : \"gender\",\n" - + " \"missing_bucket\" : true,\n" - + " \"missing_order\" : \"first\",\n" - + " \"order\" : \"asc\"\n" - + " }\n" - + " }\n" - + " } ]\n" - + " },\n" - + " \"aggregations\" : {\n" - + " \"avg(age) filter(where age > 34)\" : {\n" - + " \"filter\" : {\n" - + " \"range\" : {\n" - + " \"age\" : {\n" - + " \"from\" : 20,\n" - + " \"to\" : null,\n" - + " \"include_lower\" : false,\n" - + " \"include_upper\" : true,\n" - + " \"boost\" : 1.0\n" - + " }\n" - + " }\n" - + " },\n" - + " \"aggregations\" : {\n" - + " \"avg(age) filter(where age > 34)\" : {\n" - + " \"avg\" : {\n" - + " \"field\" : \"age\"\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"composite_buckets\" : {%n" + + " \"composite\" : {%n" + + " \"size\" : 1000,%n" + + " \"sources\" : [ {%n" + + " \"gender\" : {%n" + + " \"terms\" : {%n" + + " \"field\" : \"gender\",%n" + + " \"missing_bucket\" : true,%n" + + " \"missing_order\" : \"first\",%n" + + " \"order\" : \"asc\"%n" + + " }%n" + + " }%n" + + " } ]%n" + + " },%n" + + " \"aggregations\" : {%n" + + " \"avg(age) filter(where age > 34)\" : {%n" + + " \"filter\" : {%n" + + " \"range\" : {%n" + + " \"age\" : {%n" + + " \"from\" : 20,%n" + + " \"to\" : null,%n" + + " \"include_lower\" : false,%n" + + " \"include_upper\" : true,%n" + + " \"boost\" : 1.0%n" + + " }%n" + + " }%n" + + " },%n" + + " \"aggregations\" : {%n" + + " \"avg(age) filter(where age > 34)\" : {%n" + + " \"avg\" : {%n" + + " \"field\" : \"age\"%n" + + " }%n" + + " }%n" + + " }%n" + + " }%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList(named("avg(age) filter(where age > 34)", new AvgAggregator(Arrays.asList(ref("age", INTEGER)), INTEGER) @@ -408,32 +409,32 @@ void should_build_type_mapping_without_bucket() { @Test void should_build_histogram() { - assertEquals( - "{\n" - + " \"composite_buckets\" : {\n" - + " \"composite\" : {\n" - + " \"size\" : 1000,\n" - + " \"sources\" : [ {\n" - + " \"SpanExpression(field=age, value=10, unit=NONE)\" : {\n" - + " \"histogram\" : {\n" - + " \"field\" : \"age\",\n" - + " \"missing_bucket\" : true,\n" - + " \"missing_order\" : \"first\",\n" - + " \"order\" : \"asc\",\n" - + " \"interval\" : 10.0\n" - + " }\n" - + " }\n" - + " } ]\n" - + " },\n" - + " \"aggregations\" : {\n" - + " \"count(a)\" : {\n" - + " \"value_count\" : {\n" - + " \"field\" : \"a\"\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"composite_buckets\" : {%n" + + " \"composite\" : {%n" + + " \"size\" : 1000,%n" + + " \"sources\" : [ {%n" + + " \"SpanExpression(field=age, value=10, unit=NONE)\" : {%n" + + " \"histogram\" : {%n" + + " \"field\" : \"age\",%n" + + " \"missing_bucket\" : true,%n" + + " \"missing_order\" : \"first\",%n" + + " \"order\" : \"asc\",%n" + + " \"interval\" : 10.0%n" + + " }%n" + + " }%n" + + " } ]%n" + + " },%n" + + " \"aggregations\" : {%n" + + " \"count(a)\" : {%n" + + " \"value_count\" : {%n" + + " \"field\" : \"a\"%n" + + " }%n" + + " }%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("count(a)", new CountAggregator(Arrays.asList(ref("a", INTEGER)), INTEGER))), @@ -442,37 +443,37 @@ void should_build_histogram() { @Test void should_build_histogram_two_metrics() { - assertEquals( - "{\n" - + " \"composite_buckets\" : {\n" - + " \"composite\" : {\n" - + " \"size\" : 1000,\n" - + " \"sources\" : [ {\n" - + " \"SpanExpression(field=age, value=10, unit=NONE)\" : {\n" - + " \"histogram\" : {\n" - + " \"field\" : \"age\",\n" - + " \"missing_bucket\" : true,\n" - + " \"missing_order\" : \"first\",\n" - + " \"order\" : \"asc\",\n" - + " \"interval\" : 10.0\n" - + " }\n" - + " }\n" - + " } ]\n" - + " },\n" - + " \"aggregations\" : {\n" - + " \"count(a)\" : {\n" - + " \"value_count\" : {\n" - + " \"field\" : \"a\"\n" - + " }\n" - + " },\n" - + " \"avg(b)\" : {\n" - + " \"avg\" : {\n" - + " \"field\" : \"b\"\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"composite_buckets\" : {%n" + + " \"composite\" : {%n" + + " \"size\" : 1000,%n" + + " \"sources\" : [ {%n" + + " \"SpanExpression(field=age, value=10, unit=NONE)\" : {%n" + + " \"histogram\" : {%n" + + " \"field\" : \"age\",%n" + + " \"missing_bucket\" : true,%n" + + " \"missing_order\" : \"first\",%n" + + " \"order\" : \"asc\",%n" + + " \"interval\" : 10.0%n" + + " }%n" + + " }%n" + + " } ]%n" + + " },%n" + + " \"aggregations\" : {%n" + + " \"count(a)\" : {%n" + + " \"value_count\" : {%n" + + " \"field\" : \"a\"%n" + + " }%n" + + " },%n" + + " \"avg(b)\" : {%n" + + " \"avg\" : {%n" + + " \"field\" : \"b\"%n" + + " }%n" + + " }%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("count(a)", new CountAggregator(Arrays.asList(ref("a", INTEGER)), INTEGER)), @@ -482,32 +483,32 @@ void should_build_histogram_two_metrics() { @Test void fixed_interval_time_span() { - assertEquals( - "{\n" - + " \"composite_buckets\" : {\n" - + " \"composite\" : {\n" - + " \"size\" : 1000,\n" - + " \"sources\" : [ {\n" - + " \"SpanExpression(field=timestamp, value=1, unit=H)\" : {\n" - + " \"date_histogram\" : {\n" - + " \"field\" : \"timestamp\",\n" - + " \"missing_bucket\" : true,\n" - + " \"missing_order\" : \"first\",\n" - + " \"order\" : \"asc\",\n" - + " \"fixed_interval\" : \"1h\"\n" - + " }\n" - + " }\n" - + " } ]\n" - + " },\n" - + " \"aggregations\" : {\n" - + " \"count(a)\" : {\n" - + " \"value_count\" : {\n" - + " \"field\" : \"a\"\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"composite_buckets\" : {%n" + + " \"composite\" : {%n" + + " \"size\" : 1000,%n" + + " \"sources\" : [ {%n" + + " \"SpanExpression(field=timestamp, value=1, unit=H)\" : {%n" + + " \"date_histogram\" : {%n" + + " \"field\" : \"timestamp\",%n" + + " \"missing_bucket\" : true,%n" + + " \"missing_order\" : \"first\",%n" + + " \"order\" : \"asc\",%n" + + " \"fixed_interval\" : \"1h\"%n" + + " }%n" + + " }%n" + + " } ]%n" + + " },%n" + + " \"aggregations\" : {%n" + + " \"count(a)\" : {%n" + + " \"value_count\" : {%n" + + " \"field\" : \"a\"%n" + + " }%n" + + " }%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("count(a)", new CountAggregator(Arrays.asList(ref("a", INTEGER)), INTEGER))), @@ -516,32 +517,32 @@ void fixed_interval_time_span() { @Test void calendar_interval_time_span() { - assertEquals( - "{\n" - + " \"composite_buckets\" : {\n" - + " \"composite\" : {\n" - + " \"size\" : 1000,\n" - + " \"sources\" : [ {\n" - + " \"SpanExpression(field=date, value=1, unit=W)\" : {\n" - + " \"date_histogram\" : {\n" - + " \"field\" : \"date\",\n" - + " \"missing_bucket\" : true,\n" - + " \"missing_order\" : \"first\",\n" - + " \"order\" : \"asc\",\n" - + " \"calendar_interval\" : \"1w\"\n" - + " }\n" - + " }\n" - + " } ]\n" - + " },\n" - + " \"aggregations\" : {\n" - + " \"count(a)\" : {\n" - + " \"value_count\" : {\n" - + " \"field\" : \"a\"\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"composite_buckets\" : {%n" + + " \"composite\" : {%n" + + " \"size\" : 1000,%n" + + " \"sources\" : [ {%n" + + " \"SpanExpression(field=date, value=1, unit=W)\" : {%n" + + " \"date_histogram\" : {%n" + + " \"field\" : \"date\",%n" + + " \"missing_bucket\" : true,%n" + + " \"missing_order\" : \"first\",%n" + + " \"order\" : \"asc\",%n" + + " \"calendar_interval\" : \"1w\"%n" + + " }%n" + + " }%n" + + " } ]%n" + + " },%n" + + " \"aggregations\" : {%n" + + " \"count(a)\" : {%n" + + " \"value_count\" : {%n" + + " \"field\" : \"a\"%n" + + " }%n" + + " }%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("count(a)", new CountAggregator(Arrays.asList(ref("a", INTEGER)), INTEGER))), @@ -550,32 +551,32 @@ void calendar_interval_time_span() { @Test void general_span() { - assertEquals( - "{\n" - + " \"composite_buckets\" : {\n" - + " \"composite\" : {\n" - + " \"size\" : 1000,\n" - + " \"sources\" : [ {\n" - + " \"SpanExpression(field=age, value=1, unit=NONE)\" : {\n" - + " \"histogram\" : {\n" - + " \"field\" : \"age\",\n" - + " \"missing_bucket\" : true,\n" - + " \"missing_order\" : \"first\",\n" - + " \"order\" : \"asc\",\n" - + " \"interval\" : 1.0\n" - + " }\n" - + " }\n" - + " } ]\n" - + " },\n" - + " \"aggregations\" : {\n" - + " \"count(a)\" : {\n" - + " \"value_count\" : {\n" - + " \"field\" : \"a\"\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"composite_buckets\" : {%n" + + " \"composite\" : {%n" + + " \"size\" : 1000,%n" + + " \"sources\" : [ {%n" + + " \"SpanExpression(field=age, value=1, unit=NONE)\" : {%n" + + " \"histogram\" : {%n" + + " \"field\" : \"age\",%n" + + " \"missing_bucket\" : true,%n" + + " \"missing_order\" : \"first\",%n" + + " \"order\" : \"asc\",%n" + + " \"interval\" : 1.0%n" + + " }%n" + + " }%n" + + " } ]%n" + + " },%n" + + " \"aggregations\" : {%n" + + " \"count(a)\" : {%n" + + " \"value_count\" : {%n" + + " \"field\" : \"a\"%n" + + " }%n" + + " }%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("count(a)", new CountAggregator(Arrays.asList(ref("a", INTEGER)), INTEGER))), diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/MetricAggregationBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/MetricAggregationBuilderTest.java index 845e32ba83..5161b35021 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/MetricAggregationBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/aggregation/dsl/MetricAggregationBuilderTest.java @@ -9,6 +9,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.when; +import static org.opensearch.sql.common.utils.StringUtils.format; import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; import static org.opensearch.sql.data.type.ExprCoreType.STRING; import static org.opensearch.sql.expression.DSL.literal; @@ -62,14 +63,14 @@ void set_up() { @Test void should_build_avg_aggregation() { - assertEquals( - "{\n" - + " \"avg(age)\" : {\n" - + " \"avg\" : {\n" - + " \"field\" : \"age\"\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"avg(age)\" : {%n" + + " \"avg\" : {%n" + + " \"field\" : \"age\"%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("avg(age)", @@ -78,14 +79,14 @@ void should_build_avg_aggregation() { @Test void should_build_sum_aggregation() { - assertEquals( - "{\n" - + " \"sum(age)\" : {\n" - + " \"sum\" : {\n" - + " \"field\" : \"age\"\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"sum(age)\" : {%n" + + " \"sum\" : {%n" + + " \"field\" : \"age\"%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("sum(age)", @@ -94,14 +95,14 @@ void should_build_sum_aggregation() { @Test void should_build_count_aggregation() { - assertEquals( - "{\n" - + " \"count(age)\" : {\n" - + " \"value_count\" : {\n" - + " \"field\" : \"age\"\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"count(age)\" : {%n" + + " \"value_count\" : {%n" + + " \"field\" : \"age\"%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("count(age)", @@ -110,14 +111,14 @@ void should_build_count_aggregation() { @Test void should_build_count_star_aggregation() { - assertEquals( - "{\n" - + " \"count(*)\" : {\n" - + " \"value_count\" : {\n" - + " \"field\" : \"_index\"\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"count(*)\" : {%n" + + " \"value_count\" : {%n" + + " \"field\" : \"_index\"%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("count(*)", @@ -126,14 +127,14 @@ void should_build_count_star_aggregation() { @Test void should_build_count_other_literal_aggregation() { - assertEquals( - "{\n" - + " \"count(1)\" : {\n" - + " \"value_count\" : {\n" - + " \"field\" : \"_index\"\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"count(1)\" : {%n" + + " \"value_count\" : {%n" + + " \"field\" : \"_index\"%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("count(1)", @@ -142,14 +143,14 @@ void should_build_count_other_literal_aggregation() { @Test void should_build_min_aggregation() { - assertEquals( - "{\n" - + " \"min(age)\" : {\n" - + " \"min\" : {\n" - + " \"field\" : \"age\"\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"min(age)\" : {%n" + + " \"min\" : {%n" + + " \"field\" : \"age\"%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("min(age)", @@ -158,14 +159,14 @@ void should_build_min_aggregation() { @Test void should_build_max_aggregation() { - assertEquals( - "{\n" - + " \"max(age)\" : {\n" - + " \"max\" : {\n" - + " \"field\" : \"age\"\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"max(age)\" : {%n" + + " \"max\" : {%n" + + " \"field\" : \"age\"%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("max(age)", @@ -174,15 +175,15 @@ void should_build_max_aggregation() { @Test void should_build_varPop_aggregation() { - assertEquals( - "{\n" - + " \"var_pop(age)\" : {\n" - + " \"extended_stats\" : {\n" - + " \"field\" : \"age\",\n" - + " \"sigma\" : 2.0\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"var_pop(age)\" : {%n" + + " \"extended_stats\" : {%n" + + " \"field\" : \"age\",%n" + + " \"sigma\" : 2.0%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("var_pop(age)", @@ -191,15 +192,15 @@ void should_build_varPop_aggregation() { @Test void should_build_varSamp_aggregation() { - assertEquals( - "{\n" - + " \"var_samp(age)\" : {\n" - + " \"extended_stats\" : {\n" - + " \"field\" : \"age\",\n" - + " \"sigma\" : 2.0\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"var_samp(age)\" : {%n" + + " \"extended_stats\" : {%n" + + " \"field\" : \"age\",%n" + + " \"sigma\" : 2.0%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("var_samp(age)", @@ -208,15 +209,15 @@ void should_build_varSamp_aggregation() { @Test void should_build_stddevPop_aggregation() { - assertEquals( - "{\n" - + " \"stddev_pop(age)\" : {\n" - + " \"extended_stats\" : {\n" - + " \"field\" : \"age\",\n" - + " \"sigma\" : 2.0\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"stddev_pop(age)\" : {%n" + + " \"extended_stats\" : {%n" + + " \"field\" : \"age\",%n" + + " \"sigma\" : 2.0%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("stddev_pop(age)", @@ -225,15 +226,15 @@ void should_build_stddevPop_aggregation() { @Test void should_build_stddevSamp_aggregation() { - assertEquals( - "{\n" - + " \"stddev_samp(age)\" : {\n" - + " \"extended_stats\" : {\n" - + " \"field\" : \"age\",\n" - + " \"sigma\" : 2.0\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"stddev_samp(age)\" : {%n" + + " \"extended_stats\" : {%n" + + " \"field\" : \"age\",%n" + + " \"sigma\" : 2.0%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Arrays.asList( named("stddev_samp(age)", @@ -242,14 +243,14 @@ void should_build_stddevSamp_aggregation() { @Test void should_build_cardinality_aggregation() { - assertEquals( - "{\n" - + " \"count(distinct name)\" : {\n" - + " \"cardinality\" : {\n" - + " \"field\" : \"name\"\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"count(distinct name)\" : {%n" + + " \"cardinality\" : {%n" + + " \"field\" : \"name\"%n" + + " }%n" + + " }%n" + + "}"), buildQuery( Collections.singletonList(named("count(distinct name)", new CountAggregator( Collections.singletonList(ref("name", STRING)), INTEGER).distinct(true))))); @@ -257,29 +258,29 @@ void should_build_cardinality_aggregation() { @Test void should_build_filtered_cardinality_aggregation() { - assertEquals( - "{\n" - + " \"count(distinct name) filter(where age > 30)\" : {\n" - + " \"filter\" : {\n" - + " \"range\" : {\n" - + " \"age\" : {\n" - + " \"from\" : 30,\n" - + " \"to\" : null,\n" - + " \"include_lower\" : false,\n" - + " \"include_upper\" : true,\n" - + " \"boost\" : 1.0\n" - + " }\n" - + " }\n" - + " },\n" - + " \"aggregations\" : {\n" - + " \"count(distinct name) filter(where age > 30)\" : {\n" - + " \"cardinality\" : {\n" - + " \"field\" : \"name\"\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + "}", + assertEquals(format( + "{%n" + + " \"count(distinct name) filter(where age > 30)\" : {%n" + + " \"filter\" : {%n" + + " \"range\" : {%n" + + " \"age\" : {%n" + + " \"from\" : 30,%n" + + " \"to\" : null,%n" + + " \"include_lower\" : false,%n" + + " \"include_upper\" : true,%n" + + " \"boost\" : 1.0%n" + + " }%n" + + " }%n" + + " },%n" + + " \"aggregations\" : {%n" + + " \"count(distinct name) filter(where age > 30)\" : {%n" + + " \"cardinality\" : {%n" + + " \"field\" : \"name\"%n" + + " }%n" + + " }%n" + + " }%n" + + " }%n" + + "}"), buildQuery(Collections.singletonList(named( "count(distinct name) filter(where age > 30)", new CountAggregator(Collections.singletonList(ref("name", STRING)), INTEGER) diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatterTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatterTest.java index 8998086afc..7008b51fa6 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatterTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/CsvResponseFormatterTest.java @@ -7,6 +7,7 @@ package org.opensearch.sql.protocol.response.format; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.opensearch.sql.common.utils.StringUtils.format; import static org.opensearch.sql.data.model.ExprValueUtils.LITERAL_MISSING; import static org.opensearch.sql.data.model.ExprValueUtils.LITERAL_NULL; import static org.opensearch.sql.data.model.ExprValueUtils.stringValue; @@ -37,8 +38,8 @@ void formatResponse() { tupleValue(ImmutableMap.of("name", "John", "age", 20)), tupleValue(ImmutableMap.of("name", "Smith", "age", 30)))); CsvResponseFormatter formatter = new CsvResponseFormatter(); - String expected = "name,age\nJohn,20\nSmith,30"; - assertEquals(expected, formatter.format(response)); + String expected = "name,age%nJohn,20%nSmith,30"; + assertEquals(format(expected), formatter.format(response)); } @Test @@ -51,9 +52,9 @@ void sanitizeHeaders() { QueryResult response = new QueryResult(schema, Arrays.asList( tupleValue(ImmutableMap.of( "=firstname", "John", "+lastname", "Smith", "-city", "Seattle", "@age", 20)))); - String expected = "'=firstname,'+lastname,'-city,'@age\n" + String expected = "'=firstname,'+lastname,'-city,'@age%n" + "John,Smith,Seattle,20"; - assertEquals(expected, formatter.format(response)); + assertEquals(format(expected), formatter.format(response)); } @Test @@ -67,14 +68,14 @@ void sanitizeData() { tupleValue(ImmutableMap.of("city", "-Seattle")), tupleValue(ImmutableMap.of("city", "@Seattle")), tupleValue(ImmutableMap.of("city", "Seattle=")))); - String expected = "city\n" - + "Seattle\n" - + "'=Seattle\n" - + "'+Seattle\n" - + "'-Seattle\n" - + "'@Seattle\n" + String expected = "city%n" + + "Seattle%n" + + "'=Seattle%n" + + "'+Seattle%n" + + "'-Seattle%n" + + "'@Seattle%n" + "Seattle="; - assertEquals(expected, formatter.format(response)); + assertEquals(format(expected), formatter.format(response)); } @Test @@ -84,9 +85,9 @@ void quoteIfRequired() { new ExecutionEngine.Schema.Column(",,age", ",,age", INTEGER))); QueryResult response = new QueryResult(schema, Arrays.asList( tupleValue(ImmutableMap.of("na,me", "John,Smith", ",,age", "30,,,")))); - String expected = "\"na,me\",\",,age\"\n" + String expected = "\"na,me\",\",,age\"%n" + "\"John,Smith\",\"30,,,\""; - assertEquals(expected, formatter.format(response)); + assertEquals(format(expected), formatter.format(response)); } @Test @@ -105,10 +106,10 @@ void escapeSanitize() { QueryResult response = new QueryResult(schema, Arrays.asList( tupleValue(ImmutableMap.of("city", "=Seattle")), tupleValue(ImmutableMap.of("city", ",,Seattle")))); - String expected = "city\n" - + "=Seattle\n" + String expected = "city%n" + + "=Seattle%n" + "\",,Seattle\""; - assertEquals(expected, escapeFormatter.format(response)); + assertEquals(format(expected), escapeFormatter.format(response)); } @Test @@ -122,11 +123,11 @@ void replaceNullValues() { ImmutableMap.of("firstname", LITERAL_NULL, "city", stringValue("Seattle"))), ExprTupleValue.fromExprValueMap( ImmutableMap.of("firstname", stringValue("John"), "city", LITERAL_MISSING)))); - String expected = "name,city\n" - + "John,Seattle\n" - + ",Seattle\n" + String expected = "name,city%n" + + "John,Seattle%n" + + ",Seattle%n" + "John,"; - assertEquals(expected, formatter.format(response)); + assertEquals(format(expected), formatter.format(response)); } } diff --git a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/RawResponseFormatterTest.java b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/RawResponseFormatterTest.java index 87d2d6f57f..24b5a4431d 100644 --- a/protocol/src/test/java/org/opensearch/sql/protocol/response/format/RawResponseFormatterTest.java +++ b/protocol/src/test/java/org/opensearch/sql/protocol/response/format/RawResponseFormatterTest.java @@ -7,6 +7,7 @@ package org.opensearch.sql.protocol.response.format; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.opensearch.sql.common.utils.StringUtils.format; import static org.opensearch.sql.data.model.ExprValueUtils.LITERAL_MISSING; import static org.opensearch.sql.data.model.ExprValueUtils.LITERAL_NULL; import static org.opensearch.sql.data.model.ExprValueUtils.stringValue; @@ -36,8 +37,8 @@ void formatResponse() { QueryResult response = new QueryResult(schema, Arrays.asList( tupleValue(ImmutableMap.of("name", "John", "age", 20)), tupleValue(ImmutableMap.of("name", "Smith", "age", 30)))); - String expected = "name|age\nJohn|20\nSmith|30"; - assertEquals(expected, rawFormater.format(response)); + String expected = "name|age%nJohn|20%nSmith|30"; + assertEquals(format(expected), rawFormater.format(response)); } @Test @@ -50,9 +51,9 @@ void sanitizeHeaders() { QueryResult response = new QueryResult(schema, Arrays.asList( tupleValue(ImmutableMap.of( "=firstname", "John", "+lastname", "Smith", "-city", "Seattle", "@age", 20)))); - String expected = "=firstname|+lastname|-city|@age\n" + String expected = "=firstname|+lastname|-city|@age%n" + "John|Smith|Seattle|20"; - assertEquals(expected, rawFormater.format(response)); + assertEquals(format(expected), rawFormater.format(response)); } @Test @@ -66,14 +67,14 @@ void sanitizeData() { tupleValue(ImmutableMap.of("city", "-Seattle")), tupleValue(ImmutableMap.of("city", "@Seattle")), tupleValue(ImmutableMap.of("city", "Seattle=")))); - String expected = "city\n" - + "Seattle\n" - + "=Seattle\n" - + "+Seattle\n" - + "-Seattle\n" - + "@Seattle\n" + String expected = "city%n" + + "Seattle%n" + + "=Seattle%n" + + "+Seattle%n" + + "-Seattle%n" + + "@Seattle%n" + "Seattle="; - assertEquals(expected, rawFormater.format(response)); + assertEquals(format(expected), rawFormater.format(response)); } @Test @@ -83,9 +84,9 @@ void quoteIfRequired() { new ExecutionEngine.Schema.Column("||age", "||age", INTEGER))); QueryResult response = new QueryResult(schema, Arrays.asList( tupleValue(ImmutableMap.of("na|me", "John|Smith", "||age", "30|||")))); - String expected = "\"na|me\"|\"||age\"\n" + String expected = "\"na|me\"|\"||age\"%n" + "\"John|Smith\"|\"30|||\""; - assertEquals(expected, rawFormater.format(response)); + assertEquals(format(expected), rawFormater.format(response)); } @Test @@ -104,10 +105,10 @@ void escapeSanitize() { QueryResult response = new QueryResult(schema, Arrays.asList( tupleValue(ImmutableMap.of("city", "=Seattle")), tupleValue(ImmutableMap.of("city", "||Seattle")))); - String expected = "city\n" - + "=Seattle\n" + String expected = "city%n" + + "=Seattle%n" + "\"||Seattle\""; - assertEquals(expected, escapeFormatter.format(response)); + assertEquals(format(expected), escapeFormatter.format(response)); } @Test @@ -117,10 +118,10 @@ void senstiveCharater() { QueryResult response = new QueryResult(schema, Arrays.asList( tupleValue(ImmutableMap.of("city", "@Seattle")), tupleValue(ImmutableMap.of("city", "++Seattle")))); - String expected = "city\n" - + "@Seattle\n" + String expected = "city%n" + + "@Seattle%n" + "++Seattle"; - assertEquals(expected, rawFormater.format(response)); + assertEquals(format(expected), rawFormater.format(response)); } @Test @@ -131,10 +132,10 @@ void senstiveCharaterWithSanitize() { QueryResult response = new QueryResult(schema, Arrays.asList( tupleValue(ImmutableMap.of("city", "@Seattle")), tupleValue(ImmutableMap.of("city", "++Seattle|||")))); - String expected = "city\n" - + "@Seattle\n" + String expected = "city%n" + + "@Seattle%n" + "\"++Seattle|||\""; - assertEquals(expected, testFormater.format(response)); + assertEquals(format(expected), testFormater.format(response)); } @Test @@ -148,11 +149,11 @@ void replaceNullValues() { ImmutableMap.of("firstname", LITERAL_NULL, "city", stringValue("Seattle"))), ExprTupleValue.fromExprValueMap( ImmutableMap.of("firstname", stringValue("John"), "city", LITERAL_MISSING)))); - String expected = "name|city\n" - + "John|Seattle\n" - + "|Seattle\n" + String expected = "name|city%n" + + "John|Seattle%n" + + "|Seattle%n" + "John|"; - assertEquals(expected, rawFormater.format(response)); + assertEquals(format(expected), rawFormater.format(response)); } } diff --git a/workbench/package.json b/workbench/package.json index aebf11b285..2360dc4d91 100644 --- a/workbench/package.json +++ b/workbench/package.json @@ -16,7 +16,7 @@ "start": "plugin-helpers start", "test:server": "plugin-helpers test:server", "test:browser": "plugin-helpers test:browser", - "test:jest": "NODE_PATH=../../node_modules ../../node_modules/.bin/jest --config ./test/jest.config.js", + "test:jest": "../../node_modules/.bin/jest --config ./test/jest.config.js", "build": "yarn plugin_helpers build", "plugin_helpers": "node ../../scripts/plugin_helpers" },