简体   繁体   English

BigQuery 字符串格式为 json

[英]BigQuery string-formatting to json

Is the following a full list of all value types as they're passed to json in BigQuery?以下是在 BigQuery 中传递给 json 的所有值类型的完整列表吗? I've gotten this by trial and error but haven't been able to find this in the documentation:我通过反复试验得到了这个,但未能在文档中找到它:

select
    NULL as NullValue,
    FALSE as BoolValue,
    DATE '2014-01-01' as DateValue,
    INTERVAL 1 year as IntervalValue,
    DATETIME '2014-01-01 01:02:03' as DatetimeValue,
    TIMESTAMP '2014-01-01 01:02:03' as TimestampValue,
    "Hello" as StringValue,
    B"abc" as BytesValue,
    123 as IntegerValue,
    NUMERIC '3.14' as NumericValue,
    3.14 as FloatValue,
    TIME '12:30:00.45' as TimeValue,
    [1,2,3] as ArrayValue,
    STRUCT('Mark' as first, 'Thomas' as last) as StructValue,
    [STRUCT(1 as x, 2 as y), STRUCT(5 as x, 6 as y)] as ArrayStructValue,
    STRUCT(1 as x, [1,2,3] as y, ('a','b','c') as z) as StructNestedValue

{
  "NullValue": null,
  "BoolValue": "false", // why not just false without quotes?
  "DateValue": "2014-01-01",
  "IntervalValue": "1-0 0 0:0:0",
  "DatetimeValue": "2014-01-01T01:02:03",
  "TimestampValue": "2014-01-01T01:02:03Z",
  "StringValue": "Hello",
  "BytesValue": "YWJj",
  "IntegerValue": "123",
  "NumericValue": "3.14",
  "FloatValue": "3.14",
  "TimeValue": "12:30:00.450000",
  "ArrayValue": ["1", "2", "3"],
  "StructValue": {
    "first": "Mark",
    "last": "Thomas"
  },
  "ArrayStructValue": [
    {"x": "1", "y": "2"},
    {"x": "5", "y": "6"}
  ],
  "StructNestedValue": {
    "x": "1",
    "y": ["1", 2", "3"],
    "z": {"a": "a", b": "b", "c": "c"}
  }
}

Honestly, it seems to me that other than the null value and the array [] or struct {} container, everything is string-enclosed, which seems a bit odd.老实说,在我看来,除了null值和数组[]或 struct {}容器之外,所有内容都是字符串封闭的,这似乎有点奇怪。

According to this document , json is built on two structures:根据这份文件,json 建立在两个结构上:

A collection of name/value pairs.名称/值对的集合。 In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.在各种语言中,这被实现为 object、记录、结构、字典、hash 表、键控列表或关联数组。

An ordered list of values.有序的值列表。 In most languages, this is realized as an array, vector, list, or sequence.在大多数语言中,这被实现为数组、向量、列表或序列。

The result of the SELECT query is in json format, wherein [] depicts an array datatype, {} depicts an object datatype and double quotes(" ") depicts a string value as in the query itself. SELECT 查询的结果为 json 格式,其中 [] 表示数组数据类型,{} 表示 object 数据类型,双引号 (" ") 表示查询本身中的字符串值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM