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 bug for not able to get sourceTables from metadata #883

Merged

Conversation

seankao-az
Copy link
Collaborator

@seankao-az seankao-az commented Nov 8, 2024

Description

Using custom implementation for FlintIndexMetadataService exposes a bug where we incorrectly get empty sourceTables from FlintMetadata.
Depending on how the FlintMetadata is generated, the metadata.properties.get("sourceTables") could either be of type java array or scala array.
This PR fixes the bug, now considering both cases.

Also added some logs for troubleshooting in production environment.

Related Issues

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.

Signed-off-by: Sean Kao <seankao@amazon.com>
Signed-off-by: Sean Kao <seankao@amazon.com>
Signed-off-by: Sean Kao <seankao@amazon.com>
*/
def getSourceTablesFromMetadata(metadata: FlintMetadata): Array[String] = {
logInfo(s"Getting source tables from metadata $metadata")
metadata.properties.get("sourceTables") match {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can metadata.properties to be null?

Copy link
Collaborator Author

@seankao-az seankao-az Nov 11, 2024

Choose a reason for hiding this comment

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

no
FlintMetadata is constructed with an empty properties map as member when there isn't any property

Copy link
Collaborator

@dai-chen dai-chen left a comment

Choose a reason for hiding this comment

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

Is it possible to enforce a single and language-independent format in metadata, e.g. JSON array?

@seankao-az
Copy link
Collaborator Author

Is it possible to enforce a single and language-independent format in metadata, e.g. JSON array?

Not quite sure..
Since when reading from OpenSearch index mappings, we use jackson library to deserialize into FlintMetadata, and jackson library will use java.util.ArrayList. I'll try using this type instead.

Or do you mean using json string? Like

{"sourceTables": "[\"a.b.c\"], [\"d.e.f\"]"}

@dai-chen
Copy link
Collaborator

Is it possible to enforce a single and language-independent format in metadata, e.g. JSON array?

Not quite sure.. Since when reading from OpenSearch index mappings, we use jackson library to deserialize into FlintMetadata, and jackson library will use java.util.ArrayList. I'll try using this type instead.

Or do you mean using json string? Like

{"sourceTables": "[\"a.b.c\"], [\"d.e.f\"]"}

Yeah, just trying to understand where this problem comes from? Is Scala or Java array stored in metadata?

Signed-off-by: Sean Kao <seankao@amazon.com>
@seankao-az seankao-az force-pushed the empty-source-tables-fix branch from 76c9e0e to ce5fea8 Compare November 12, 2024 17:02
@seankao-az
Copy link
Collaborator Author

mainly comes from this line of scala code. I was putting scala Array[String] here.
https://github.com/opensearch-project/opensearch-spark/pull/883/files#diff-1e6cbb4cde65f1142862f3b539a438d534fd70a229499efd671ef9aae67ff29fR75

Now I've changed it to use ArrayList. so for both cases (mv.metadata() and deserialized metadata from index mapping) will have ArrayList. Do you think this is better? @dai-chen

@seankao-az seankao-az merged commit dd9c0cf into opensearch-project:main Nov 12, 2024
4 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Nov 12, 2024
* add logs

Signed-off-by: Sean Kao <seankao@amazon.com>

* match Array when reading sourceTables

Signed-off-by: Sean Kao <seankao@amazon.com>

* add test cases

Signed-off-by: Sean Kao <seankao@amazon.com>

* use ArrayList only

Signed-off-by: Sean Kao <seankao@amazon.com>

---------

Signed-off-by: Sean Kao <seankao@amazon.com>
(cherry picked from commit dd9c0cf)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
opensearch-trigger-bot bot pushed a commit that referenced this pull request Nov 12, 2024
* add logs

Signed-off-by: Sean Kao <seankao@amazon.com>

* match Array when reading sourceTables

Signed-off-by: Sean Kao <seankao@amazon.com>

* add test cases

Signed-off-by: Sean Kao <seankao@amazon.com>

* use ArrayList only

Signed-off-by: Sean Kao <seankao@amazon.com>

---------

Signed-off-by: Sean Kao <seankao@amazon.com>
(cherry picked from commit dd9c0cf)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
seankao-az pushed a commit that referenced this pull request Nov 12, 2024
* add logs



* match Array when reading sourceTables



* add test cases



* use ArrayList only



---------


(cherry picked from commit dd9c0cf)

Signed-off-by: Sean Kao <seankao@amazon.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>
saranrajnk pushed a commit to saranrajnk/opensearch-spark that referenced this pull request Nov 12, 2024
…oject#883) (opensearch-project#893)

* add logs



* match Array when reading sourceTables



* add test cases



* use ArrayList only



---------


(cherry picked from commit dd9c0cf)

Signed-off-by: Sean Kao <seankao@amazon.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>
seankao-az pushed a commit that referenced this pull request Nov 13, 2024
* add logs



* match Array when reading sourceTables



* add test cases



* use ArrayList only



---------


(cherry picked from commit dd9c0cf)

Signed-off-by: Sean Kao <seankao@amazon.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>
kenrickyap pushed a commit to Bit-Quill/opensearch-spark that referenced this pull request Dec 11, 2024
…oject#883)

* add logs

Signed-off-by: Sean Kao <seankao@amazon.com>

* match Array when reading sourceTables

Signed-off-by: Sean Kao <seankao@amazon.com>

* add test cases

Signed-off-by: Sean Kao <seankao@amazon.com>

* use ArrayList only

Signed-off-by: Sean Kao <seankao@amazon.com>

---------

Signed-off-by: Sean Kao <seankao@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants