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 a regression issue of parsing datetime string with custom time format in Span #3079

Merged
merged 5 commits into from
Nov 1, 2024

Conversation

LantaoJin
Copy link
Member

@LantaoJin LantaoJin commented Oct 18, 2024

Description

This seems a regression issue from #2762. Query of StatsBy with Span on a custom formatted date type will fail.

Here is the reproduce:

PUT /ltjin-test1
{
    "mappings":{
        "properties": {
            "Time1": {
                "type": "date",
                "format": "yyyy-MM-dd"
            },
            "Time2": {
                "type": "date",
                "format": "epoch_millis"
            }
        }
    }
}

POST _bulk
{ "index" : { "_index" : "ltjin-test1", "_id" : "1" } }
{ "Time1": "2005-12-05", "Time2": 1133654400000 }

POST /_plugins/_ppl/
{
    "query": """
    source=ltjin-test1 | eval a = 1 | stats Count(a) as a by span(Time1, 1d)
    """
}

POST /_plugins/_ppl/
{
    "query": """
    source=ltjin-test1 | eval a = 1 | stats Count(a) as a by span(Time2, 1d)
    """
}

Throws NPE.

Related Issues

Resolves #3078

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • 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.

YANG-DB
YANG-DB previously approved these changes Oct 18, 2024
Copy link
Collaborator

@MaxKsyunz MaxKsyunz left a comment

Choose a reason for hiding this comment

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

Please increase unit test coverage and resolve now failing integration tests.

jacoco results

-----------
* What went wrong:
Execution failed for task ':core:jacocoTestCoverageVerification'.
> Rule violated for class org.opensearch.sql.planner.physical.collector.Rounding: branches covered ratio is 0.8, but expected minimum is 1.0

test failures

DateTimeFormatsIT > testIncompleteFormats FAILED
    java.lang.AssertionError: 
    Expected: iterable with items [[1984-01-01 00:00:00, null, null, 10:00:00, 1999-01-01], [2012-01-01 00:00:00, null, null, 20:00:00, 3021-01-01]] in any order
         but: not matched: <["1984-01-01 00:00:00",null,null,"1970-01-01","1999-01-01"]>
        at __randomizedtesting.SeedInfo.seed([2C68C17CE23C9F5D:B917EF6B60642A6C]:0)
        at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:18)
        at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:6)
        at org.opensearch.sql.util.MatcherUtils.verify(MatcherUtils.java:188)
        at org.opensearch.sql.util.MatcherUtils.verifyDataRows(MatcherUtils.java:159)
        at org.opensearch.sql.sql.DateTimeFormatsIT.testIncompleteFormats(DateTimeFormatsIT.java:124)

DateTimeFormatsIT > testCustomFormats FAILED
    java.lang.AssertionError: 
    Expected: iterable with items [[09:07:42, 1984-04-12 09:07:42, 1984-04-12, 1961-04-12 00:00:00, 23:44:36.321], [21:07:42, 1984-04-12 22:07:42, 1984-04-12, 1970-01-01 09:07:00, 09:01:16.542]] in any order
         but: not matched: <["09:07:42","1984-04-12 09:07:42","1984-04-12","1961-04-12","1970-01-01"]>
        at __randomizedtesting.SeedInfo.seed([2C68C17CE23C9F5D:203B87710DB1C56E]:0)
        at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:18)
        at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:6)
        at org.opensearch.sql.util.MatcherUtils.verify(MatcherUtils.java:188)
        at org.opensearch.sql.util.MatcherUtils.verifyDataRows(MatcherUtils.java:159)
        at org.opensearch.sql.sql.DateTimeFormatsIT.testCustomFormats(DateTimeFormatsIT.java:76)

DateTimeFormatsIT > testDateFormatsWithOr FAILED
    java.lang.AssertionError: 
    Expected: iterable with items [[1984-04-12 00:00:00], [1984-04-12 09:07:42.000123456]] in any order
         but: not matched: <["1984-04-12"]>
        at __randomizedtesting.SeedInfo.seed([2C68C17CE23C9F5D:51D930CA323C2C64]:0)
        at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:18)
        at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:6)
        at org.opensearch.sql.util.MatcherUtils.verify(MatcherUtils.java:188)
        at org.opensearch.sql.util.MatcherUtils.verifyDataRows(MatcherUtils.java:159)
        at org.opensearch.sql.sql.DateTimeFormatsIT.testDateFormatsWithOr(DateTimeFormatsIT.java:57)

DateTimeFormatsIT > testDateNanosWithNanos PASSED

DateTimeFormatsIT > testCustomFormats2 FAILED
    java.lang.AssertionError: 
    Expected: iterable with items [[1984-10-20, 10:20:30, 1984-10-20 15:35:48], [1961-04-12, 09:07:00, 1961-04-12 09:07:00]] in any order
         but: not matched: <["1970-01-01","1970-01-01","2598-09-26"]>
        at __randomizedtesting.SeedInfo.seed([2C68C17CE23C9F5D:75DB39273E844970]:0)
        at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:18)
        at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:6)
        at org.opensearch.sql.util.MatcherUtils.verify(MatcherUtils.java:188)
        at org.opensearch.sql.util.MatcherUtils.verifyDataRows(MatcherUtils.java:159)
        at org.opensearch.sql.sql.DateTimeFormatsIT.testCustomFormats2(DateTimeFormatsIT.java:102)

@LantaoJin
Copy link
Member Author

LantaoJin commented Oct 24, 2024

Please increase unit test coverage and resolve now failing integration tests.

The unit test coverage can't be fixed since jacoco report is module-level based. What's the bug here is missing the OpenSearchDateType handling in Rounding logic , but OpenSearchDateType is not a class in the core module. And the current fixing is straightforward.
I fixed the previous failures in DateTimeFormatsIT and add a new test case to DateTimeImplementationIT.

@LantaoJin LantaoJin added bug Something isn't working backport 2.x backport 2.18 labels Oct 24, 2024
@LantaoJin LantaoJin added the v2.18.0 Issues targeting release v2.18.0 label Oct 24, 2024
@LantaoJin
Copy link
Member Author

@YANG-DB @MaxKsyunz @penghuo , since this seems a regression issue introduced from v2.16.0. I'd like this fixing could be merged in v2.18.0

Signed-off-by: Lantao Jin <[email protected]>
@@ -295,7 +295,7 @@ private static ExprValue createOpenSearchDateType(Content value, ExprType type)
}
} else {
// custom format
return parseDateTimeString(value.stringValue(), dt);
return parseDateTimeString(value.objectValue().toString(), dt);
Copy link
Collaborator

Choose a reason for hiding this comment

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

could u elberate more? value is number value? why objectValue().toString()?

Copy link
Member Author

Choose a reason for hiding this comment

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

The value is an instance of ObjectContent and isNumber() is true, stringValue() will return the string representation of the object, such as ObjectContent@1234. We should convert it to Java Object then use toString() here. Or value.longValue().toString(). Not sure the value here is a Long type, so value.objectValue().toString() would be best.

@penghuo
Copy link
Collaborator

penghuo commented Oct 25, 2024

could u exclude Rounding from TestCoverage and address it later. otherwise, following PR will failed with test coverage?

@LantaoJin
Copy link
Member Author

LantaoJin commented Oct 25, 2024

could u exclude Rounding from TestCoverage and address it later. otherwise, following PR will failed with test coverage?

Excluding Rounding is not what we expected, there are many logic in class Rounding, IMO jacoco only fail the incremental codes which is less than the threshold of coverage, the following PR shouldn't be impacted.

Does anyone else could help to confirm?^ cc @dai-chen @ykmr1224

YANG-DB
YANG-DB previously approved these changes Oct 25, 2024
Signed-off-by: Lantao Jin <[email protected]>
@LantaoJin
Copy link
Member Author

I added some unit tests in a mock way to fix the missing test coverage. Now CI passed! Please take a review again @YANG-DB @MaxKsyunz @penghuo @dai-chen @ykmr1224. This patch could be marked as critical for 2.18.0!

Copy link
Collaborator

@penghuo penghuo left a comment

Choose a reason for hiding this comment

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

Thx!

@LantaoJin LantaoJin merged commit 4ff1fe3 into opensearch-project:main Nov 1, 2024
14 of 15 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/sql/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/sql/backport-2.x
# Create a new branch
git switch --create backport/backport-3079-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 4ff1fe3cb48a17ff17b0cf134131283fc0282205
# Push it to GitHub
git push --set-upstream origin backport/backport-3079-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/sql/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-3079-to-2.x.

@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.18 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/sql/backport-2.18 2.18
# Navigate to the new working tree
pushd ../.worktrees/sql/backport-2.18
# Create a new branch
git switch --create backport/backport-3079-to-2.18
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 4ff1fe3cb48a17ff17b0cf134131283fc0282205
# Push it to GitHub
git push --set-upstream origin backport/backport-3079-to-2.18
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/sql/backport-2.18

Then, create a pull request where the base branch is 2.18 and the compare/head branch is backport/backport-3079-to-2.18.

LantaoJin added a commit to LantaoJin/search-plugins-sql that referenced this pull request Nov 1, 2024
LantaoJin added a commit to LantaoJin/search-plugins-sql that referenced this pull request Nov 1, 2024
Swiddis pushed a commit that referenced this pull request Nov 6, 2024
… custom time format in Span (#3079) (#3146)

* Fix a regression issue of parsing datetime string with custom time format in Span (#3079)

(cherry picked from commit 4ff1fe3)

* fix compile error

Signed-off-by: Lantao Jin <[email protected]>

* fix coverage

Signed-off-by: Lantao Jin <[email protected]>

---------

Signed-off-by: Lantao Jin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x backport 2.18 backport-failed bug Something isn't working v2.18.0 Issues targeting release v2.18.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] PPL gets error but looks syntax correct
5 participants