【问题标题】:Schema to load json data to google big query将 json 数据加载到谷歌大查询的架构
【发布时间】:2014-08-28 16:43:27
【问题描述】:

我对我们正在进行的项目有一个问题......

我尝试将此 JSON 提取到 Google Big Query,但无法从 JSON 输入中获取 JSON 投票对象字段。我尝试了架构中的“记录”和“字符串”类型。

{
    "votes": {
        "funny": 10,
        "useful": 10,
        "cool": 10
    },
    "user_id": "OlMjqqzWZUv2-62CSqKq_A",
    "review_id": "LMy8UOKOeh0b9qrz-s1fQA",
    "stars": 4,
    "date": "2008-07-02",
    "text": "This is what this 4-star bar is all about.",
    "type": "review",
    "business_id": "81IjU5L-t-QQwsE38C63hQ"
}

我也无法从下面的 JSON 中为类别和邻域 JSON 数组填充表格?这些输入的架构应该是什么?不幸的是,在这种情况下,文档并没有太大帮助,或者我看的地方不对..

{
    "business_id": "Iu-oeVzv8ZgP18NIB0UMqg",
    "full_address": "3320 S Hill St\nSouth East LA\nLos Angeles, CA 90007",
    "schools": [
        "University of Southern California"
    ],
    "open": true,
    "categories": [
        "Medical Centers",
        "Health and Medical"
    ],
    "neighborhoods": [
        "South East LA"
    ]
}

我能够获得常规字段,但仅此而已...感谢任何帮助!

【问题讨论】:

  • 输入 JSON: {"business_id": "Iu-oeVzv8ZgP18NIB0UMqg", "full_address": "3320 S Hill St\nSouth East LA\nLos Angeles, CA 90007", "schools": ["University of Southern California"], "open": true} 解析模式:business_id:string,full_address:string,schools:string,open:boolean 错误字段:schools,为非重复字段指定的数组
  • 另一个输入:{"votes": {"funny": 0, "useful": 1, "cool": 0}, "name": "LiiLii C."} 给定模式:投票:字符串,名称:字符串错误:字段:投票,为非记录字段指定的 JSON 映射

标签: json google-bigquery


【解决方案1】:

对于business,您似乎希望学校成为一个重复的领域。您的架构应该是:

"schema": {
    "fields": [
        {
            "name": "business_id",
            "type": "string"
        }.
        {
            "name": "full_address",
            "type": "string"
        },
        {
            "name": "schools",
            "type": "string",
            "mode": "repeated"
        },
        {
            "name": "open",
            "type": "boolean"
        }
    ]
}

对于votes,您似乎想要记录。您的架构应该是:

"schema": {
    "fields": [
        {
            "name": "name",
            "type": "string"
        }.
        {
            "name": "votes",
            "type": "record",
            "fields": [
                {
                    "name": "funny",
                    "type": "integer",
                },
                {
                    "name": "useful",
                    "type": "integer"
                },
                {
                    "name": "cool",
                    "type": "integer"
                }
            ]
        },
    ]
}

Source

【讨论】:

    【解决方案2】:

    我也被这个问题困住了,但我面临的问题是因为必须记住将模式标记为重复记录source

    另外请注意,这些不能有空值source

    【讨论】:

    • 您应该将问题标记为重复,而不是使用问题链接回答
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多