go - BigQuery 中的数据库设计

标签 go database-design google-bigquery

我有一个名为“Acquisition”的主表,其中有多个列将引用其他表(例如:“Source”、“Application”等 - 例如,“Source”将有多个可能的值,这些值将用于多个“Acquisition”表的行)。让我有点困扰的是,“Acquisition”表的行会返回这样的数据:

id > 1 ;值(value) > 23.4 ; source_id > 1 ; application_id > 3 ;platform_id > 1 ; country_id > 1 ;等

您认为还有另一种设计方法可以使其更具可读性/用户友好性吗?

这里是架构代码的摘录:

acquisitionSchema = bigquery.Schema {
    &bigquery.FieldSchema{Name: "id", Required: true, Type: bigquery.StringFieldType},
    &bigquery.FieldSchema{Name: "value", Required: true, Type: bigquery.FloatFieldType},
    &bigquery.FieldSchema{Name: "source_id", Required: true, Type: bigquery.StringFieldType},
    &bigquery.FieldSchema{Name: "application_id", Required: true, Type: bigquery.StringFieldType},
    &bigquery.FieldSchema{Name: "platform_id", Required: true, Type: bigquery.StringFieldType},
    &bigquery.FieldSchema{Name: "country_id", Required: true, Type: bigquery.StringFieldType},
    &bigquery.FieldSchema{Name: "adtype_id", Required: true, Type: bigquery.StringFieldType},
    &bigquery.FieldSchema{Name: "date", Required: true, Type: bigquery.dateFieldType},
    &bigquery.FieldSchema{Name: "download", Required: false, Type: bigquery.IntegerFieldType}   } 

sourceSchema = bigquery.Schema {
    &bigquery.FieldSchema{Name: "id", Required: true, Type: bigquery.StringFieldType},
    &bigquery.FieldSchema{Name: "value", Required: true, Type: bigquery.StringFieldType},
}

我想过直接输入源、平台等的值,但是当我通过 API 从多个源获取数据时,它可能会变得困惑,除非我在代码中进行所有必要的控制。

谢谢!

最佳答案

通常我们做一个RECORD有两列(id,name)

-country
 |id
 |name

这样在我们的查询中,我们可以使用 country.id 来按整数查询,或者使用 country.name 来显示值以便快速检查。

由于现在存储很便宜,我们可以负担得起在每一列中存储文字表示。由于 BQ 在设计上是仅附加的,而且我们通常读取最近的行,如果 name 同时发生变化,那已经包含了新值。使用 LAST_VALUE 函数,我们始终可以选择包含最后一个 name 的最后一条记录。

关于go - BigQuery 中的数据库设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42986325/

相关文章:

sql - 数字 ID 与字符串 ID

java - hibernate 。如何正确组织带有注释的一对多关系?

elasticsearch - 我们应该在应用程序中创建多少个 elasticsearch 客户端连接

image - Golang 将原始图像 []byte 转换为 image.Image

mysql - 试图避免 "Polymorphic Associations"并维护外键参照完整性

google-bigquery - 大查询 : Cast float64 to date in SQL Standard

python - 有没有办法使用 BigQuery 从 Google Analytics 导出原始数据?

google-bigquery - 大查询 : Querying multiple datasets and tables using Standard SQL

linux - 我应该如何在后台运行我的 Golang 进程?

pointers - Golang 使用反射在结构中设置 nil 字符串指针值