BigQuery generally does a good job of loading Avro data, but "bq load" is having a lot of trouble with timestamps and other date/time fields that use the Avro logicalType attribute.
I guess I could workaround these problems by always loading the data into temporary fields and using queries to CAST or transform them to additional fields, but that doesn't scale or support schema evolution or stream nicely. Producing data in Avro with well-defined schemas is supposed to avoid that extra step of transforming data again for different consumers.
Is BigQuery really this incompatible with Avro dates and times? (or am I doing something dumb)
Or is "bq load" the problem here? Is there a better way to load Avro data?
Update: This feature is now supported, follow issuetracker.google.com/35905894 for more information.
As Hua said, Avro Logical Types are not supported in BigQuery but the supported way to load Avro data with timestamps is by using the LONG Avro type to load data into an existing BigQuery table that has a TIMESTAMP column. Also, the value should be microseconds (not seconds or milliseconds) from EPOCH. For example, the Avro file below has the a LONG field with value 1408452095000000 which will represent "2014-08-19 12:41:35".
The Avro file's schema:
% avro-tools getschema ~/dataset/simple_timestamp.avro
{
"type" : "record",
"name" : "FullName",
"fields" : [ {
"name" : "t",
"type" : "long"
} ]
}
Example of loading an Avro file to a table with a Timestamp field:
bq mk --schema t:TIMESTAMP -t vimota.simple_timestamp
bq load --source_format=AVRO vimota.simple_timestamp ~/dataset/simple_timestamp.avro
bq head vimota.simple_timestamp:
+---------------------+
| t |
+---------------------+
| 2014-08-19 12:41:35 |
+---------------------+
Native understanding for Avro Logical Types is now available publicly for all BigQuery users. Please refer to the documentation page here for more details: https://cloud.google.com/bigquery/docs/loading-data-cloud-storage-avro#logical_types
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With