将BigQuery表架构导出为JSON架构

时间:2019-11-27 10:55:14

标签: google-bigquery

可以将bigquery表模式导出到JSON文件,但是生成的JSON文件是bigquery表模式而不是JSON模式。 我正在寻找一种根据此处提供的标准使用bigquery表生成JSON模式的方法:https://json-schema.org/

这看起来像这样:

{
  "definitions": {},
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "http://example.com/root.json",
  "type": "object",
  "title": "The Root Schema",
  "required": [
    "glossary"
  ],
  "properties": {
    "glossary": {
      "$id": "#/properties/glossary",
      "type": "object",
      "title": "The Glossary Schema",
      "required": [
        "title",
        "GlossDiv"
      ],
      "properties": {
        "title": {
          "$id": "#/properties/glossary/properties/title",
          "type": "string",
          "title": "The Title Schema",
          "default": "",
          "examples": [
            "example glossary"
          ],
          "pattern": "^(.*)$"
        },
        "GlossDiv": {
          "$id": "#/properties/glossary/properties/GlossDiv",
          "type": "object",
          "title": "The Glossdiv Schema",
          "required": [
            "title",
            "GlossList"
          ],
          "properties": {
            "title": {
              "$id": "#/properties/glossary/properties/GlossDiv/properties/title",
              "type": "string",
              "title": "The Title Schema",
              "default": "",
              "examples": [
                "S"
              ],
              "pattern": "^(.*)$"
            },
            "GlossList": {
              "$id": "#/properties/glossary/properties/GlossDiv/properties/GlossList",
              "type": "object",
              "title": "The Glosslist Schema",
              "required": [
                "GlossEntry"
              ],
              "properties": {
                "GlossEntry": {
                  "$id": "#/properties/glossary/properties/GlossDiv/properties/GlossList/properties/GlossEntry",
                  "type": "object",
                  "title": "The Glossentry Schema",
                  "required": [
                    "ID",
                    "SortAs",
                    "GlossTerm",
                    "Acronym",
                    "Abbrev",
                    "GlossDef",
                    "GlossSee"
                  ],
                  "properties": {
                    "ID": {
                      "$id": "#/properties/glossary/properties/GlossDiv/properties/GlossList/properties/GlossEntry/properties/ID",
                      "type": "string",
                      "title": "The Id Schema",
                      "default": "",
                      "examples": [
                        "SGML"
                      ],
                      "pattern": "^(.*)$"
                    },
                    "SortAs": {
                      "$id": "#/properties/glossary/properties/GlossDiv/properties/GlossList/properties/GlossEntry/properties/SortAs",
                      "type": "string",
                      "title": "The Sortas Schema",
                      "default": "",
                      "examples": [
                        "SGML"
                      ],
                      "pattern": "^(.*)$"
                    },
                    "GlossTerm": {
                      "$id": "#/properties/glossary/properties/GlossDiv/properties/GlossList/properties/GlossEntry/properties/GlossTerm",
                      "type": "string",
                      "title": "The Glossterm Schema",
                      "default": "",
                      "examples": [
                        "Standard Generalized Markup Language"
                      ],
                      "pattern": "^(.*)$"
                    },
                    "Acronym": {
                      "$id": "#/properties/glossary/properties/GlossDiv/properties/GlossList/properties/GlossEntry/properties/Acronym",
                      "type": "string",
                      "title": "The Acronym Schema",
                      "default": "",
                      "examples": [
                        "SGML"
                      ],
                      "pattern": "^(.*)$"
                    },
                    "Abbrev": {
                      "$id": "#/properties/glossary/properties/GlossDiv/properties/GlossList/properties/GlossEntry/properties/Abbrev",
                      "type": "string",
                      "title": "The Abbrev Schema",
                      "default": "",
                      "examples": [
                        "ISO 8879:1986"
                      ],
                      "pattern": "^(.*)$"
                    },
                    "GlossDef": {
                      "$id": "#/properties/glossary/properties/GlossDiv/properties/GlossList/properties/GlossEntry/properties/GlossDef",
                      "type": "object",
                      "title": "The Glossdef Schema",
                      "required": [
                        "para",
                        "GlossSeeAlso"
                      ],
                      "properties": {
                        "para": {
                          "$id": "#/properties/glossary/properties/GlossDiv/properties/GlossList/properties/GlossEntry/properties/GlossDef/properties/para",
                          "type": "string",
                          "title": "The Para Schema",
                          "default": "",
                          "examples": [
                            "A meta-markup language, used to create markup languages such as DocBook."
                          ],
                          "pattern": "^(.*)$"
                        },
                        "GlossSeeAlso": {
                          "$id": "#/properties/glossary/properties/GlossDiv/properties/GlossList/properties/GlossEntry/properties/GlossDef/properties/GlossSeeAlso",
                          "type": "array",
                          "title": "The Glossseealso Schema",
                          "items": {
                            "$id": "#/properties/glossary/properties/GlossDiv/properties/GlossList/properties/GlossEntry/properties/GlossDef/properties/GlossSeeAlso/items",
                            "type": "string",
                            "title": "The Items Schema",
                            "default": "",
                            "examples": [
                              "GML",
                              "XML"
                            ],
                            "pattern": "^(.*)$"
                          }
                        }
                      }
                    },
                    "GlossSee": {
                      "$id": "#/properties/glossary/properties/GlossDiv/properties/GlossList/properties/GlossEntry/properties/GlossSee",
                      "type": "string",
                      "title": "The Glosssee Schema",
                      "default": "",
                      "examples": [
                        "markup"
                      ],
                      "pattern": "^(.*)$"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

2 个答案:

答案 0 :(得分:2)

BigQuery不在表架构中使用json-schema标准。我找到了两个项目,这些项目具有可用于从json模式到BigQuery模式的代码:

您可以尝试使用这些项目作为参考来创建相反的转换。另外,您可以为BigQuery团队创建一个feature request,要求将json-schema标准作为输出格式选项包含。

答案 1 :(得分:0)

没有编写程序来为您做到这一点是不可能的。

我提出了一项功能请求,要求该功能。 https://issuetracker.google.com/issues/145308573