使用 useAvroLogicalTypes 不正确的字段类型的 BigQuery Avro 加载作业
BigQuery Avro load job with useAvroLogicalTypes incorrect field types
我正在使用 node.js 来:
- 使用
avsc
NPM 包创建一个 Avro 文件
- 使用
@google-cloud/storage
NPM 包上传到 GCS
- 调用 BQ API 使用
@google-cloud/bigquery
NPM 包将 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
}
我让它工作的唯一方法是在加载作业的元数据变量中再次指定模式。我的问题是,指定 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' }
]
}
]
}
}
回答您关于在创建加载作业期间指定 Avro 架构的问题。可以省略架构 属性,这是目标 table:
的架构
The schema can be omitted if the destination table already exists, or if you're loading data from Google Cloud Datastore.
如果您想阅读更多相关信息,请参阅documentation。
此外,您还可以查看替换架构定义的--autodetect flag。
希望对你有所帮助
我正在使用 node.js 来:
- 使用
avsc
NPM 包创建一个 Avro 文件 - 使用
@google-cloud/storage
NPM 包上传到 GCS - 调用 BQ API 使用
@google-cloud/bigquery
NPM 包将 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
}
我让它工作的唯一方法是在加载作业的元数据变量中再次指定模式。我的问题是,指定 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' }
]
}
]
}
}
回答您关于在创建加载作业期间指定 Avro 架构的问题。可以省略架构 属性,这是目标 table:
的架构The schema can be omitted if the destination table already exists, or if you're loading data from Google Cloud Datastore.
如果您想阅读更多相关信息,请参阅documentation。
此外,您还可以查看替换架构定义的--autodetect flag。
希望对你有所帮助