【发布时间】:2019-12-30 09:55:59
【问题描述】:
我使用 node.js 来:
- 使用
avscNPM 包创建 Avro 文件 - 使用
@google-cloud/storageNPM 包上传到 GCS - 使用
@google-cloud/bigqueryNPM 包调用 BQ API 以将 Avro 从 GCS 加载到 BQ
我的问题是,即使我在创建加载作业时设置了useAvroLogicalTypes,我的日期数据也永远不会在 BQ 中正确创建为TIMESTAMP,总是INTEGER - which should be the normal behavior 当useAvroLogicalTypes 是不设置。
根据相同的文档,如果在 Avro 架构定义中设置了 timestamp-millis,它应该加载为 TIMESTAMP。
我的配置:
Avro 架构
{
"name": "metadata",
"type": {
"name": "metadata",
"type": "record",
"fields": [
{
"name": "creationTime",
"type": "long",
"logicalType": "timestamp-millis"
},
{
"name": "lastActivity",
"type": ["null", "long"],
"logicalType": "timestamp-millis"
},
{
"name": "deletionTime",
"type": ["null", "long"],
"logicalType": "timestamp-millis"
},
{
"name": "lastSignInTime",
"type": ["null", "long"],
"logicalType": "timestamp-millis"
}
]
}
}
创建加载作业
const metadata = {
sourceFormat: 'AVRO',
useAvroLogicalTypes: true
}
我可以让它工作的唯一方法是在加载作业的元数据变量中再次指定 scema。我的问题是,指定 Avro 架构并打开 useAvroLogicalTypes 以避免必须再次显式指定加载作业元数据的架构不是重点吗?
工作设置
const metadata = {
sourceFormat: 'AVRO',
useAvroLogicalTypes: true,
schema: {
fields: [
...otherFields,
{
name: 'metadata',
type: 'STRUCT',
mode: 'REQUIRED',
fields: [
{ name: 'creationTime', type: 'TIMESTAMP', mode: 'REQUIRED' },
{ name: 'lastActivity', type: 'TIMESTAMP', mode: 'NULLABLE' },
{ name: 'deletionTime', type: 'TIMESTAMP', mode: 'NULLABLE' },
{ name: 'lastSignInTime', type: 'TIMESTAMP', mode: 'NULLABLE' }
]
}
]
}
}
【问题讨论】:
标签: google-bigquery avro