Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flat_object long field error #13259

Conversation

naomichi-y
Copy link
Contributor

@naomichi-y naomichi-y commented Apr 17, 2024

Description

Fixed an error 'Preview of field's value: 'null' that occurred when using flat_object with long field names in OpenSearch version 2.12 and later.

Related Issues

#13184

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Failing checks are inspected and point to the corresponding known issue(s) (See: Troubleshooting Failing Builds)
  • Commits are signed per the DCO using --signoff
  • Commit changes are listed out in CHANGELOG.md file (See: Changelog)
  • Public documentation issue/PR created

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Contributor

❌ Gradle check result for 5aa3812: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

❌ Gradle check result for 5e00cb7: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the values of path and currentFieldName that we end up with in the changed code and what is that code trying to do? I am just wondering what the side effects of setting path to blank are.

@msfroh take a look pls

CHANGELOG.md Outdated Show resolved Hide resolved
@dblock dblock added backport 2.x Backport to 2.x branch backport 1.1 Backport to 1.1 branch and removed backport 1.1 Backport to 1.1 branch labels Apr 17, 2024
@dblock
Copy link
Member

dblock commented Apr 17, 2024

* What went wrong:
Execution failed for task ':server:spotlessJavaCheck'.
> The following files had format violations:
      src/test/java/org/opensearch/index/mapper/FlatObjectFieldDataTests.java
          @@ -73,8 +73,12 @@
           ············.startObject("field")
           ············.startObject("detail")
           ············.startArray("fooooooooooo")
          -············.startObject().field("name",·"baz").endObject()
          -············.startObject().field("name",·"baz").endObject()
          +············.startObject()
          +············.field("name",·"baz")
          +············.endObject()
          +············.startObject()
          +············.field("name",·"baz")
          +············.endObject()
           ············.endArray()
           ············.endObject()
           ············.endObject()
          @@ -93,7 +97,6 @@
           ········assertEquals(1,·valueReaders.size());
           ····}
           
          -
           ····@Override
           ····protected·String·getFieldDataType()·{
           ········return·FIELD_TYPE;
  Run './gradlew :server:spotlessApply' to fix these violations.

^

Copy link
Contributor

✅ Gradle check result for 85dafbf: SUCCESS

@msfroh
Copy link
Collaborator

msfroh commented Apr 22, 2024

I will take a look soon. I'm getting on a plane in an hour and a half and should be able to review once the in-flight wifi kicks in.

Grr... the in-flight wifi is too slow to connect to the EC2 instance where I usually work on OpenSearch, and the connection is too flaky to clone the repo onto my laptop. I'd like to try debugging the added unit test to wrap my head around the specifics of the bug. I'll try again once I'm checked into my hotel this evening. Nevermind -- I managed to get it to clone to my laptop. As they say, seventh time's the charm.

@msfroh
Copy link
Collaborator

msfroh commented Apr 22, 2024

I played around with the unit test and added the following unit test to JsonToStringXContentParserTest:

    public void testArrayOfObjects() throws IOException {
        String jsonExample ="{" +
            "\"field\": {" +
            "  \"detail\": {" +
            "    \"foooooooooooo\": [" +
            "      {\"name\":\"baz\"}," +
            "      {\"name\":\"baz\"}" +
            "    ]" +
            "  }" +
            "}}";

        assertEquals("{" +
            "\"flat\":[\"field\",\"detail\",\"foooooooooooo\",\"name\",\"name\"]," +
            "\"flat._value\":[\"baz\",\"baz\"]," +
            "\"flat._valueAndPath\":[" +
            "\"flat.field.detail.foooooooooooo.name=baz\"," +
            "\"flat.field.detail.foooooooooooo.name=baz\"" +
            "]}",
            flattenJsonString("flat", jsonExample)
        );
    }

The bug is in the use of path.lastIndexOf(). On a StringBuilder, it goes from the end of the buffer, regardless of the assigned length of the buffer. It can be fixed by changing it to path.lastIndexOf(DOT_SYMBOL, path.length()).

Unfortunately, there's another problem -- with that fix (as well as yours), the above unit test fails, because the second flat._valueAndPath becomes flat.field.detail.name=baz. That's because of another bug: we pop foooooooooooo off after processing the first object in the array, so it's no longer there when we process the second object.

I was able to fix that by adding a boolean popName argument to parseToken and wrapped the name-popping logic in a check. For startObject, we pass true, but for startArray, we pass false. Here's the modified popping logic:

                if (popName) {
                    int dotIndex = path.lastIndexOf(DOT_SYMBOL, path.length());
                    if (dotIndex != -1) {
                        path.setLength(path.length() - currentFieldName.length() - 1);
                    }
                }

Signed-off-by: naomichi-y <n.yamakita@gmail.com>
Signed-off-by: naomichi-y <n.yamakita@gmail.com>
Signed-off-by: naomichi-y <n.yamakita@gmail.com>
Signed-off-by: naomichi-y <n.yamakita@gmail.com>
Copy link
Contributor

❌ Gradle check result for 5c276f0: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: naomichi-y <n.yamakita@gmail.com>
@naomichi-y naomichi-y force-pushed the feature/fix-flat_object-long-field-error branch from 5c276f0 to 4b58495 Compare April 23, 2024 06:46
Copy link
Contributor

❌ Gradle check result for 4b58495: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@naomichi-y
Copy link
Contributor Author

@msfroh
Thank you. I have changed the path.lastIndexOf argument, please confirm.
The other bug was confirmed in my environment. I guess a new Issue needs to be made.

@dblock
Copy link
Member

dblock commented Apr 23, 2024

❌ Gradle check result for 4b58495: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

org.opensearch.indices.store.IndicesStoreIntegrationIT.testShardActiveElseWhere {p0={"cluster.remote_store.state.enabled":"true"}}

#12788

@dblock
Copy link
Member

dblock commented Apr 23, 2024

@msfroh Thank you. I have changed the path.lastIndexOf argument, please confirm. The other bug was confirmed in my environment. I guess a new Issue needs to be made.

Please do open an issue or add a fix/test to this PR @naomichi-y. Appreciate it.

I propose we get this change in first as is? @msfroh wdyt?

@naomichi-y
Copy link
Contributor Author

I've opened a new issue.
#13351

Copy link
Contributor

❌ Gradle check result for 4b58495: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

❕ Gradle check result for 4b58495: UNSTABLE

  • TEST FAILURES:
      1 org.opensearch.cluster.MinimumClusterManagerNodesIT.testThreeNodesNoClusterManagerBlock
      1 org.opensearch.action.admin.indices.create.CreateIndexIT.testCreateAndDeleteIndexConcurrently
      1 org.opensearch.action.admin.indices.create.CreateIndexIT.classMethod

Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure.

@msfroh
Copy link
Collaborator

msfroh commented Apr 23, 2024

Thanks for tackling this, @naomichi-y! If you're willing to address the follow-up issue, that would be great!

Please feel free to steal the unit test that I posted above.

@msfroh msfroh merged commit 9e62ccf into opensearch-project:main Apr 23, 2024
28 of 29 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 23, 2024
…13259)

---------

Signed-off-by: naomichi-y <n.yamakita@gmail.com>
(cherry picked from commit 9e62ccf)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
dblock pushed a commit that referenced this pull request Apr 25, 2024
…13259)

---------

Signed-off-by: naomichi-y <n.yamakita@gmail.com>
(cherry picked from commit 9e62ccf)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
reta pushed a commit that referenced this pull request Apr 25, 2024
…13259)

---------

Signed-off-by: naomichi-y <n.yamakita@gmail.com>
(cherry picked from commit 9e62ccf)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
VachaShah pushed a commit that referenced this pull request Apr 25, 2024
…13259) (#13358)

---------


(cherry picked from commit 9e62ccf)

Signed-off-by: naomichi-y <n.yamakita@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@naomichi-y naomichi-y mentioned this pull request May 10, 2024
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants