简体   繁体   English

在 BigQuery 中读取时,未定义行 XXXX、列 xx-xx 处的 JSON 输入意外结束

[英]Unexpected end of JSON input at undefined line XXXX, columns xx-xx while reading in BigQuery

I have a table in Bigquery which has 2 columns - job_id and json_column (string which is in JSON format).我在 Bigquery 中有一个表,它有 2 列 - job_idjson_column (JSON 格式的字符串)。 When I tried to read the data and identify some objects it gives me error as below:当我试图读取数据并识别一些对象时,它给我错误如下:

SyntaxError:Unexpected end of JSON input at undefined line XXXX, columns xx-xx

It Always gives me line 5931 and second time I execute again it gives line 6215.它总是给我第 5931 行,第二次我再次执行它给了第 6215 行。

If it's related to JSON structure issue, how can I know which row/ job_id that number 5931 corresponds to?如果它与JSON结构问题有关,我如何知道数字5931对应于哪个行/ job_id If I subset for a specific job_id , it returns the values but when I tried to execute on the complete table, I got this error.如果我为特定的job_id设置子集,它会返回值,但是当我尝试在整个表上执行时,出现此错误。 I tried looking at the job_id at the row_numbers mentioned and code works fine for those job_id s.我试着查看提到的 row_numbers 处的job_id ,代码对那些job_id工作正常。

Do you think its JSON structure issue and how to identify which row/ job_id has this Issue?你认为它的 JSON 结构问题以及如何识别哪个行/ job_id有这个问题?

Table Structure:表结构: 在此处输入图像描述

Code:代码:

CREATE TEMPORARY FUNCTION CUSTOM_JSON_EXTRACT(json STRING, json_path STRING)
    RETURNS ARRAY<STRING>
    LANGUAGE js AS """
      var result = jsonPath(JSON.parse(json), json_path);
      if(result){return result;} 
      else {return [];}
    """
    OPTIONS (
        library="gs://json_temp/jsonpath-0.8.0.js"
    );

SELECT job_id,dist,gm,sub_gm
FROM lz_fdp_op.fdp_json_file,
UNNEST(CUSTOM_JSON_EXTRACT(trim(conv_column), '$.Project.OpsLocationInfo.iDistrictId')) dist ,
UNNEST(CUSTOM_JSON_EXTRACT(trim(conv_column), '$.Project.GeoMarketInfo.Geo')) gm,
UNNEST(CUSTOM_JSON_EXTRACT(trim(conv_column), '$.Project.GeoMarketInfo.SubGeo')) sub_gm 

Would this work for you?这对你有用吗?

WITH 

T AS (
  SELECT
    '1000149.04.14' AS job_id,
    '{"Project":{"OpsLocationInfo":{"iDistrictId":"A"},"GeoMarketInfo":{"Geo":"B","SubGeo":"C"}}}' AS conv_column
)

SELECT
  JSON_EXTRACT_SCALAR(conv_column, '$.Project.OpsLocationInfo.iDistrictId') AS dist,
  JSON_EXTRACT_SCALAR(conv_column, '$.Project.GeoMarketInfo.Geo') AS gm,
  JSON_EXTRACT_SCALAR(conv_column, '$.Project.GeoMarketInfo.SubGeo') AS sub_gm
FROM
  T

BigQuery JSON Functions docs: https://cloud.google.com/bigquery/docs/reference/standard-sql/json_functions BigQuery JSON 函数文档: https ://cloud.google.com/bigquery/docs/reference/standard-sql/json_functions

how can I read multiple arrays in an object in JSON without using unnest?如何在不使用 unnest 的情况下读取 JSON 对象中的多个数组?

Can you explain better with an input sample your comment?你能用输入样本更好地解释你的评论吗?

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

相关问题 Golang json 解组“JSON 输入的意外结束” - Golang json Unmarshal "unexpected end of JSON input" 将 JSON 转换为 BigQuery 中的列 - Converting JSON to Columns in BigQuery 地址为 IP 'yyy.yy.yy.yy' 的客户端不允许访问服务器。 我的客户ip是xxx.xx.xx.xx - Client with IP address 'yyy.yy.yy.yy' is not allowed to access the server. My client ip is xxx.xx.xx.xx JVM -XX:MaxRAMPercentage 未在容器中应用 - JVM -XX:MaxRAMPercentage not being applied in container 使用 expo 和 React Native 将图像上传到 Firebase 存储 (v 9.xx)。 (参考未定义?) - Uploading images to Firebase Storage (v 9.xx) using expo and React Native. (Ref undefined?) AWS ELB 不健康 4xx - AWS ELB unhealthy 4xx 将 JSON 数据插入 BigQuery 错误:读取数据时出错,错误消息:JSON 从 position 0 开始的行中解析错误 - Insert JSON Data into BigQuery ERROR: Error while reading data, error message: JSON parsing error in row starting at position 0: Expected key 在BigQuery中使用JSON函数查询订单行项目 - Querying Line Items of Order with JSON Functions in BigQuery 语法错误:预期输入结束但在 BigQuery 中获得了标识符 - Syntax error: Expected end of input but got identifier in BigQuery 使用 pandas to_gbq 在 Google BigQuery 中创建表时读取数据时出现 400 错误 - 400 Error while reading data using pandas to_gbq to create a table in Google BigQuery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM