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

feat(): add support for DateOnly and TimeOnly #680 #734

Merged
merged 10 commits into from
Jul 31, 2024

Conversation

joefeser
Copy link
Contributor

Description

Add support for DateOnly and TimeOnly that were both added in .net 6

Issues Resolved

Closes #680.

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
Collaborator

@Xtansia Xtansia left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this @joefeser!
Some relatively small issues other than those already commented in particular files:

  • Looks like there's a compile error with the change in SDK.
  • Please add an entry to the CHANGELOG.md under the ### Added section
  • The DCO check requires commits to be signed off, you can do this for your existing commits via git rebase HEAD~2 --signoff and then make sure to pass --signoff to any future commits for this repo

@@ -1,10 +1,10 @@
{
"sdk": {
"version": "6.0.403",
"version": "8.0.107",
Copy link
Collaborator

Choose a reason for hiding this comment

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

The github workflow setup-dotnet steps can be updated to change the sdk versions being installed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved

#if NETSTANDARD2_1
public static PostData ReadOnlyMemory(ReadOnlyMemory<byte> bytes) => new PostData<object>(bytes);
#if NETSTANDARD2_1 || NET6_0_OR_GREATER
public static PostData ReadOnlyMemory(ReadOnlyMemory<byte> bytes) => new PostData<object>(bytes.ToArray());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove the .ToArray(), this should be using the constructor here: https://github.com/opensearch-project/opensearch-net/blob/main/src/OpenSearch.Net/Transport/PostData.cs#L149

You'll just need to update the #ifs further down.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I understood this comment, it is in this commit bcbd1a2

Comment on lines 1 to 2
#pragma warning disable IDE1006 // Naming Styles
#pragma warning disable IDE0044 // Add readonly modifier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please move these #pragmas below the license header

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved

@joefeser
Copy link
Contributor Author

Working on the changes as we speak. Thank you for being so proactive on my PR

Signed-off-by: Joe Feser <joseph.feser@gmail.com>
Signed-off-by: Joe Feser <joseph.feser@gmail.com>
@joefeser
Copy link
Contributor Author

Thanks for tackling this @joefeser! Some relatively small issues other than those already commented in particular files:

  • Looks like there's a compile error with the change in SDK.
  • Please add an entry to the CHANGELOG.md under the ### Added section
  • The DCO check requires commits to be signed off, you can do this for your existing commits via git rebase HEAD~2 --signoff and then make sure to pass --signoff to any future commits for this repo

All of these tasks are completed

Signed-off-by: Joe Feser <joseph.feser@gmail.com>
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
@Xtansia Xtansia merged commit f3bae74 into opensearch-project:main Jul 31, 2024
38 checks passed
@Xtansia Xtansia added the backport 1.x Backport to 1.x branch label Jul 31, 2024
@opensearch-trigger-bot
Copy link
Contributor

The backport to 1.x failed:

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

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-1.x 1.x
# Navigate to the new working tree
cd .worktrees/backport-1.x
# Create a new branch
git switch --create backport/backport-734-to-1.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 f3bae74a0e5f7146127262b566259898d8a45ebc
# Push it to GitHub
git push --set-upstream origin backport/backport-734-to-1.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-1.x

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

Xtansia pushed a commit to Xtansia/opensearch-net that referenced this pull request Jul 31, 2024
…pensearch-project#734)

* feat(): add .net6 and .net8 to core project and get it to compile opensearch-project#680

Signed-off-by: Joe Feser <joseph.feser@gmail.com>

* feat(): add support for DateOnly and TimeOnly from .net 6 opensearch-project#680

Signed-off-by: Joe Feser <joseph.feser@gmail.com>

* PR Comments

Signed-off-by: Joe Feser <joseph.feser@gmail.com>

* PR Comments

Signed-off-by: Joe Feser <joseph.feser@gmail.com>

* modified the added section of changelog.md

Signed-off-by: Joe Feser <joseph.feser@gmail.com>

* Fix compilation/indentation error

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

* Fix code conventions unit test

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

* Fix remaining `#if`s

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

* Fix changelog ordering

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

* Fix CI errors

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

---------

Signed-off-by: Joe Feser <joseph.feser@gmail.com>
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
Co-authored-by: Thomas Farr <tsfarr@amazon.com>
(cherry picked from commit f3bae74)
@Xtansia
Copy link
Collaborator

Xtansia commented Jul 31, 2024

Thank you for this @joefeser, would you mind making a follow up PR adding the DateOnly and TimeOnly types into the unit test here: https://github.com/opensearch-project/opensearch-net/blob/main/tests/Tests.Reproduce/DateSerialization.cs

@joefeser joefeser deleted the feat/datetime-only-680 branch July 31, 2024 05:30
@joefeser
Copy link
Contributor Author

@Xtansia I will add it in the next few days. I wasn't sure where to write the tests. I am going to do a POC also to add NodaTime support and at least get that conversation going

Xtansia added a commit that referenced this pull request Jul 31, 2024
* feat(): add .net6 and .net8 to core project and get it to compile #680

Signed-off-by: Joe Feser <joseph.feser@gmail.com>

* feat(): add support for DateOnly and TimeOnly from .net 6 #680

Signed-off-by: Joe Feser <joseph.feser@gmail.com>

* PR Comments

Signed-off-by: Joe Feser <joseph.feser@gmail.com>

* PR Comments

Signed-off-by: Joe Feser <joseph.feser@gmail.com>

* modified the added section of changelog.md

Signed-off-by: Joe Feser <joseph.feser@gmail.com>

* Fix compilation/indentation error

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

* Fix code conventions unit test

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

* Fix remaining `#if`s

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

* Fix changelog ordering

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

* Fix CI errors

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

---------

Signed-off-by: Joe Feser <joseph.feser@gmail.com>
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
Co-authored-by: Thomas Farr <tsfarr@amazon.com>
(cherry picked from commit f3bae74)

Co-authored-by: Joe Feser <joseph.feser@gmail.com>
@nalka0
Copy link

nalka0 commented Aug 8, 2024

I have played a bit with this PR and I think we still have some likely problems :

  • If you don't do anything to the mappings, your TimeOnly fields are mapped as strings with
"type": "text",
"fields": {
    "keyword": {
        "type": "keyword",
        "ignore_above": 256
    }
}

instead of something with "type": "date"

I tried fixing this second issue and for DateOnly, it seems like adding a case "DateOnly" next to the DateTime one above on the method I linked is sufficient.

On the other hand for TimeOnly it seems like we need more than that since you get a parsing error when trying to put data in your index. From my understanding, the format is responsible there but adding the following case

case "TimeOnly":
    return new DateProperty()
    {
        Format = "strict_hour_minute_second_millis"
    };

seems unsuccesful (for some reasons, doing Format = ... there doesn't seem to change anything to the resulting mappings).

PS : I pulled the value for Format = here but am unsure if strict_hour_minute_second_millis is really the best fit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.x Backport to 1.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Serialize DateOnly as a date instead of serializing its properties individually
3 participants