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

System.Datetime is not handled consistently #302

Closed
TomBruns opened this issue Feb 19, 2024 · 1 comment
Closed

System.Datetime is not handled consistently #302

TomBruns opened this issue Feb 19, 2024 · 1 comment

Comments

@TomBruns
Copy link

TomBruns commented Feb 19, 2024

Summary

System.DateTime properties are converted to strings in AVRO
AVRO long > timestamp-millis are generated as System.DateTime POCO class properties

Details

Using create...

Datetime .NET types are generated as a string

dotnet avro create --type System.DateTime
"string"

Using generate...

dotnet avro generate --id 2 --registry-url http://localhost:8081 --registry-config schema.registry.basic.auth.user.info=PLAINTEXT:PLAINTEXT

This fragment of an AVRO definition

      "default": null,
      "name": "Timestamp",
      "type": [
        "null",
        {
          "logicalType": "timestamp-millis",
          "type": "long"
        }
      ]

Generates this C# property

        public global::System.DateTime? Timestamp { get; set; }

Would you accept a PR from my fork?
ex:

.\Chr.Avro.Cli.exe create --type System.DateTime
{"type":"long","logicalType":"timestamp-millis"}

Note: I also added a -f command line option to read the avsc input from a local file. I found that to be easier to use.

-f, --schema-file The full pathname of the avsc schema file on disk.

@dstelljes
Copy link
Member

Chr.Avro prefers to map to ISO 8601 strings for the reasons outlined at https://engineering.chrobinson.com/dotnet-avro/internals/mapping/#dates-and-times.

Would you accept a PR from my fork?

We wouldn't accept a PR to change the current behavior, but we would accept a PR to introduce hints on the schema similar to the Java client (see #173).

I also added a -f command line option to read the avsc input from a local file.

The generate command supports piping (see the Generate code from a local schema examples at https://engineering.chrobinson.com/dotnet-avro/cli/generate/), but feel free to submit the -f option in a separate PR if you think it'd be valuable.

@dstelljes dstelljes closed this as not planned Won't fix, can't repro, duplicate, stale May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants