JSON号码周围可以有引号吗?在大多数搜索链接中,似乎数字不需要"引号".但是,如果解析器同时接受"attr" : 6和"attr" : "6"?
如果MyParser有一个方法getInt来获取给定密钥的数字,应该在两种情况下都MyParser.getInt("attr")返回6,或者在后一种情况下抛出异常?
将bigquery.extract_data()BigQuery 中的数据提取到 GCS 的函数不维护整数或浮点类型。请参阅下面的 python bigquery 客户端库示例:
client = bigquery.Client()
dataset_ref = bigquery.DatasetReference('our-gcp-project','our-bq-dataset')
configuration = bigquery.job.ExtractJobConfig()
configuration.destination_format = 'NEWLINE_DELIMITED_JSON'
extract_job = client.extract_table(
table_ref=dataset_ref.table('table_name'),
destination_uri=f'gs://our-gcs-bucket/our-output-file.json',
job_config=configuration,
location="us-west2",
)
extract_job.result()
Run Code Online (Sandbox Code Playgroud)
另一种方法是,我们循环 bigquery.rowIterator 对象并将结果简单地写入 JSON:
full_query = 'select * from ...' # query to get BQ table
# results_row_iter = bq.query(full_query).result() # google.bq.rowIterator
results_row_iter = bq.query(full_query) # removed .result() to avoid bringing entire query result into memory
with open(f'ourfile.json', 'w') as f:
for row in results_row_iter: …Run Code Online (Sandbox Code Playgroud) python types google-cloud-storage google-bigquery google-cloud-platform
似乎 BigQuery 在选择 --format json 时总是在值周围加上双引号,即使该字段是整数字段
如果你运行这个:
node --eval 'console.log(JSON.stringify({a:1}));'
Run Code Online (Sandbox Code Playgroud)
你会看到字符串:
{"a":1}
Run Code Online (Sandbox Code Playgroud)
(1 是 an integer,它在 javascript 对象中显示为整数。)
我们希望 BigQuery 中的查询输出也是
{"a":1}
Run Code Online (Sandbox Code Playgroud)
当字段是integer字段时
例如,“bqtest”文件包含:
a
1
Run Code Online (Sandbox Code Playgroud)
请执行下列操作:
bq load --skip_leading_rows 1 --replace --project_id YOUR-PROJECT-ID nfl.jsontestinteger bqtest a:integer
Run Code Online (Sandbox Code Playgroud)
然后
bq query --format json --project_id YOUR-PROJECT-ID "SELECT * FROM nfl.jsontestinteger"
Run Code Online (Sandbox Code Playgroud)
你会看见:
[{"a":"1"}]
Run Code Online (Sandbox Code Playgroud)
如果您不想创建一个公共表,可以使用以下公共表:
bq query --format json --project_id YOUR-PROJECT-ID "SELECT * FROM [personal-real-estate:nfl.jsontestinteger]"
Run Code Online (Sandbox Code Playgroud)
问题:有没有办法让 BigQueryintegers在 json 格式输出中没有双引号的情况下格式化?
只是为了确认这里的流程相同,但我们将字段创建为string字段
bq load --skip_leading_rows 1 --replace --project_id YOUR-PROJECT-ID …Run Code Online (Sandbox Code Playgroud)