简体   繁体   English

在 bigQuery 中仅返回非空键/值

[英]Returning only non-null key/value in bigQuery

I have an object in bigQuery that stores all possible parameters in the system.我在 bigQuery 中有一个 object,它存储了系统中所有可能的参数。 Therefore somewhere under the hood the 'parameter' object, has a lot of keys, and when I build a query to SELECT param it returns a lot of columns with null, and maybe only 1 with a value, which makes it impossible to analyze as the output table is incredibly wide.因此,在引擎盖下的某个地方,“参数”object 有很多键,当我构建对SELECT param的查询时,它会返回很多带有 null 的列,并且可能只有 1 个具有值,这使得无法分析为output 表非常宽。

How can I write the query so that it returns 1 column, with only the non null key/value pair?我如何编写查询以使其返回 1 列,只有非 null 键/值对?

ie IE

instead of returning:而不是返回:

param.phone , param.lob , param.destination , param.id , param.1 , param.2 etc with null values param.phoneparam.lobparam.destinationparam.idparam.1param.2等具有null

在此处输入图像描述

i want to see one column with value {"e_line_of_business":"inte.net"} or any other non-null key/values.我想看到一个值为{"e_line_of_business":"inte.net"}或任何其他非空键/值的列。 It's ok to be stringified.可以被字符串化。

You might consider below approach.您可能会考虑以下方法。

WITH sample_data AS (
  SELECT STRUCT(STRING(null) AS phone, STRING(null) AS lob, STRING(null) AS destination, 'internet' AS e_line_of_business, STRING(null) AS param1) params
   UNION ALL
  SELECT STRUCT(STRING(null) AS phone, STRING(null) AS lob, STRING(null) AS destination, 'internet' AS e_line_of_business, 'value_1' AS param1)
   UNION ALL
  SELECT STRUCT('01012345678' AS phone, 'web' AS lob, STRING(null) AS destination, null AS e_line_of_business, null AS param1)
)
SELECT params, REPLACE(REGEXP_REPLACE(TO_JSON_STRING(params), r'"[^,{]+"\:null,?', ''), ',}', '}') non_nulls 
  FROM sample_data;

Query results查询结果

在此处输入图像描述

暂无
暂无

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

相关问题 select 最后一个非空值和 append 到另一列 BigQuery/PYTHON - select last non-null value and append it to another column BigQuery/PYTHON 获取多个分区中的下一个(或上一个)非空值 - Get the next (or previous) non-null value in multiple partitioned FirebaseCloudMessaging: PlatformException (PlatformException(null-error, Host platform returned null value for non-null return value., null, null)) - FirebaseCloudMessaging : PlatformException (PlatformException(null-error, Host platform returned null value for non-null return value., null, null)) 未处理的异常:PlatformException(空错误,主机平台为非空返回值返回 null 值。,null,空) - Unhandled Exception: PlatformException(null-error, Host platform returned null value for non-null return value., null, null) 必须返回非空值,因为返回类型“UserCredentialPlatform”不允许空值 - A non-null value must be returned since the return type 'UserCredentialPlatform' doesn't allow null 根据跨多个列的第一个可用非空值连接两个表 - Join two tables based on first available non-null value across multiple columns BigQuery LAG 仅返回空值 - BigQuery LAG returning only nulls 必须向 Text 小部件提供非空字符串。 断言失败:第 378 行 pos 10: 'data != null' - A non-null String must be provided to a Text widget. Failed assertion: line 378 pos 10: 'data != null' BigQuery 将 Float 值 0.0 和 Boolean false 保存为 null - BigQuery saves Float value 0.0 and Boolean false as null select 一个 json 键的值在 bigQuery 中使用 sql - select a json key's value using sql in bigQuery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM