我试图弄清楚field在下面的示例中找不到时如何停止我的程序的执行。
如果FieldByName(key)返回零值,我如何警告用户未找到该字段?
field := mutable.FieldByName(key)
// need to figure out if the field exists before calling .Type() on it
if field.X == Y {
log.Fatalf("Unable to find [%s] in Config object", key)
}
switch field.Type().Name() {
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将重复记录的 col 类型从STRING更改为TIMESTAMP。这里有一些来自 BQ 文档的建议(手动更改架构)。但是,我遇到了每个推荐建议的问题。
这是一个示例架构:
{
'name' => 'id',
'type' => 'STRING',
'mode' => 'REQUIRED'
},
{
'name' => 'name',
'type' => 'STRING',
'mode' => 'REQUIRED'
},
// many more fields including nested records and repeated records
{
'name' => 'locations',
'type' => 'RECORD',
'mode' => 'REPEATED',
'fields' => [
{
'name' => 'city',
'type' => 'STRING',
'mode' => 'REQUIRED'
},
{
'name' => 'updated_at',
'type' => 'STRING', // ** want this as …Run Code Online (Sandbox Code Playgroud)