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

Created Avro Schema to BigQuerySchema Convertor #188

Merged
merged 10 commits into from
Dec 13, 2024

Conversation

shashambhavi
Copy link
Collaborator

@shashambhavi shashambhavi commented Nov 20, 2024

This PR introduces a new utility class, AvroToBigQuerySchemaTransform, to convert Avro schemas to BigQuery schemas. This is necessary for creating BigQuery tables dynamically based on the Avro schema of the incoming record in a Flink connector sink.

The following Type Conversions take place:
Reference: Type Conversions while loading avro file in BigQuery

Data Type Transformation:

Avro Type BigQuery Type Notes
string STRING
bytes BYTES
int INT64
long INT64
float FLOAT64
double FLOAT64
boolean BOOL
enum STRING
fixed BYTES
record RECORD
array REPEATED
union(null, type) NULLABLE type
logicalType: date DATE
logicalType: time TIME
logicalType: timestamp TIMESTAMP
logicalType: local-timestamp DATETIME
logicalType: decimal NUMERIC/BIGNUMERIC Depending on precision; STRING if precision is out of range
logicalType: geography_wkt GEOGRAPHY
logicalType: uuid STRING
logicalType: Json JSON

Exception Handling:

Exception Cause
IllegalArgumentException
  • The Avro Schema is not of RECORD type.
  • Unsupported Avro Field of type UNION. Only ['datatype'], ['null', 'datatype'] or ['datatype', 'null'] are supported.
  • Precision of decimal field must be non-negative.
  • Scale of decimal field must be non-negative.
  • Scale of the field cannot exceed precision.
  • Array cannot have a NULLABLE element.
IllegalStateException BigQuery ARRAY cannot have recursive ARRAY fields.
UnsupportedOperationException
  • BigQuery fields can only be nested 15 times.
  • The Avro type of the field is not supported by BigQuery (e.g., MAP type).
  • NULLABLE ARRAYS in UNION types are not supported.

/gcbrun

@shashambhavi shashambhavi marked this pull request as draft November 20, 2024 18:32
@shashambhavi shashambhavi self-assigned this Nov 21, 2024
@shashambhavi shashambhavi marked this pull request as ready for review November 21, 2024 03:22
@shashambhavi shashambhavi marked this pull request as draft November 21, 2024 15:04
@shashambhavi shashambhavi marked this pull request as ready for review November 25, 2024 06:27
@jayehwhyehentee jayehwhyehentee self-requested a review December 13, 2024 09:02
@shashambhavi shashambhavi merged commit 4900b08 into GoogleCloudDataproc:main Dec 13, 2024
4 checks passed
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

Successfully merging this pull request may close these issues.

3 participants