AVRO-2818: [ruby] Support ISO 8601 string input in IntDate logical type encode#3680
AVRO-2818: [ruby] Support ISO 8601 string input in IntDate logical type encode#3680abMatGit wants to merge 1 commit intoapache:mainfrom
Conversation
|
Thank you for this addition! Looks simple & clean. One request: could you please also add the date for -5, like the other tests do? |
|
My concern with this PR is that it makes the Ruby SDK different than the others. |
|
My first thought was this would just be a SDK-specific decision on how language-specific types map to the Avro types, and would be documented in the SDK documentation only, not in the Avro specification. However, it seems this change could cause ambiguity when encoding a Ruby string value "1970-01-01" using an Avro union schema like [
{ "type": "int", "logicalType": "date" },
{ "type": "string" }
]as the string would previously have matched only the second branch of the union, but this change would make it match the first branch too. In which case the Avro specification should perhaps advise schema authors to avoid defining unions like that. Or the Ruby SDK should provide a way to give the encoder a string that will not be coerced to a date. |
What is the purpose of the change
This pull request partially addresses AVRO-2818 by adding support for encoding ISO 8601 date strings (
YYYY-MM-DD) in the Ruby SDK'sIntDatelogical type.Previously,
IntDate.encodeonly acceptedNumericorDate/Timeobjects. Passing a string such as'1970-01-06'would raise aNoMethodErrorbecauseString#to_dateis not part of Ruby's standard library. This change adds aDate.parsecall when the input is aString, allowing callers to pass ISO 8601 date strings directly without pre-converting them toDateobjects.Verifying this change
This change added tests and can be verified as follows:
test_int_date_conversionintest/test_logical_types.rbto assert that ISO 8601 date strings are correctly encoded to their integer day offset from the Unix epoch'1970-01-06'encodes to5'1970-01-01'encodes to0Documentation