Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
[BEAM-12385] Handle VARCHAR and other SQL specific logical types in AvroUtils #14858
[BEAM-12385] Handle VARCHAR and other SQL specific logical types in AvroUtils #14858
Changes from 6 commits
1efc744
e2a50f6
bf99251
7758d60
0b64485
499eba0
de939da
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, optionally you can create Avro schemas in a more readable way:
This is for info -- they should (must!) be equivalent to using the Parser. This snippet is small but builders are a good practice for larger schemas!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RyanSkraba thanks for the suggestion, one specific reason I didn't use the
SchemaBuilder
is due to the need to use a an Integer (non-String) value for the property. The Schema produced by usingSchemaBuilder
looks like:{"type":"string","logicalType":"LONGVARCHAR","maxLength": "50"}
vs. the expected:
{"type":"string","logicalType":"LONGVARCHAR","maxLength": 50}
I think its the same reason, Hive's TypeInfoToSchema#L116 also uses the JSON based parsing approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, I'm surprised -- thanks for pointing this out. It might be an Avro bug! I'm pretty sure that if size is an
int
it's a JSON number.Regardless, thanks for the update, let's use the Hive approach then!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate to be this annoying @anantdamle but since we are trying to 'align' with Hive/Spark maybe it is good that we name the logicalType names to coincide with the ones in the class you mention which are in lowercase.
https://github.com/apache/hive/blob/135629b8d6b538fed092641537034a9fbc59c7a0/serde/src/java/org/apache/hadoop/hive/serde2/avro/AvroSerDe.java#L59
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries @iemejia, concern in using is that Hive only provides
varchar
, how to then deal with others like longvarchar etc.If I use lowercase then converting back to JDBCType would become hard.
Do you suggest converting all the string based logical types to just varchar with appropriate maxLength?
The approach in JdbcIO schema is to represent them with Uppercase logical type of JDBC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the logicalTypes that Hive/Spark define are spelled with lowercase so let's do like them.
It is a bit odd compared with the Java SQL Types (on uppercase), at least SQL should be casing agnostic so it should not matter in that front.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iemejia made the changes, with following mapping as per Hive, as there are only two categories:
Variable Length Strings:
[
VARCHAR
,LONGVARCHAR
,NVARCHAR
,LONGNVARCHAR
] ->varchar
Fixed Length Strings:
[
CHAR
,NCHAR
] ->char