user_properties-6ren">
gpt4 book ai didi

java - BigQuery,如何以编程方式定义类似字段的数组?

转载 作者:行者123 更新时间:2023-12-02 02:06:26 25 4
gpt4 key购买 nike

我正在尝试启动一个数据仓库项目,这就是我希望我的架构如下所示:

表:event_log架构:

 -> info
-> user_id: "xyz"
-> user_properties // <- I want this to be array like
-> 0
-> key: "name
-> value
-> int_value: null
-> string_value: "osp"
...
-> 1 // and it goes on

问题是我不知道如何以编程方式定义这个类似数组的结构。

我的想法来自这里:

https://www.youtube.com/watch?v=pxNrkjBeHpw

到目前为止,这是我的代码(kotlin 使用 java google cloud 库):

    val tableId = TableId.of(datasetName, tableName)

// First part, general field
val generalInfoFields = ArrayList<Field>()
generalInfoFields.add(Field.of("user_id", LegacySQLTypeName.STRING))


generalInfoFields.add(Field.of("user_properties", {ARRAY LIKE TYPE??}))

val general_info = Field.of("general_info", LegacySQLTypeName.RECORD, FieldList.of(generalInfoFields))


// Combine fields and create table
val tableSchema = Schema.of(general_info)
val tableDefinition = StandardTableDefinition.of(tableSchema)
val tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build()
val table = bigquery.create(tableInfo)



log.info("dataset created " + dataset.datasetId.dataset)

任何帮助将不胜感激

最佳答案

要在 BigQuery 架构中定义数组,您需要使用 Field.Mode.REPEATED 修饰符。检查official docs .

您的代码将如下所示:

val arrayField = Field.newBuilder("user_properties", LegacySQLTypeName.RECORD, FieldList.of(<record nested fields here>))
.setMode(Field.Mode.REPEATED).build()

关于java - BigQuery,如何以编程方式定义类似字段的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50717198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com