如何过滤NULL? [英] How to filter on NULL?

查看:116
本文介绍了如何过滤NULL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"order (S)","method (NULL)","time (L)"
"/1553695740/Bar","true","[  { ""N"" : ""1556593200"" },  { ""N"" : ""1556859600"" }]"
"/1556439461/adasd","true","[  { ""N"" : ""1556593200"" },  { ""N"" : ""1556679600"" }]"
"/1556516482/Foobar","cheque","[  { ""N"" : ""1556766000"" }]"

如何在空的方法属性上扫描或查询该问题价值观? https://s.natalian.org/2019-04-29/null。 mp4

How do I scan or query for that matter on empty "method" attribute values? https://s.natalian.org/2019-04-29/null.mp4

推荐答案

不幸的是,DynamoDB控制台提供了一个简单的GUI,并假定您要执行的所有操作都具有相同的功能类型。当您在类型为 NULL的列上选择过滤器时,它仅允许您做存在或不存在。这是有道理的,因为仅包含NULL数据类型的列可以存在或不存在。

Unfortunately the DynamoDB console offers a simple GUI and assumes the operations you want to perform all have the same type. When you select filters on columns of type "NULL", it only allows you to do exists or not exists. This makes sense since a column containing only NULL datatypes can either exist or not exist.

您在这里拥有的列是包含多个数据类型的(因为NULL是不同的数据类型比字符串)。有很多方法可以过滤您想要的内容,但我认为控制台上不提供这些方法。这是一个有关如何通过AWS CLI过滤数据集的示例(注意:由于您的列是一个名为保留字方法的名称,因此您需要使用表达式属性名称):

What you have here is a column that contains multiple datatypes (since NULL is a different datatype than String). There are many ways to filter what you want here but I don't believe they are available to you on the console. Here is an example on how you could filter the dataset via the AWS CLI (note: since your column is a named a reserved word method, you will need to alias it with an expression attribute name):

$ aws dynamodb scan --table-name plocal --filter-expression '#M = :null' --expression-attribute-values '{":null":{"NULL":true}}' --expression-attribute-names '{"#M":"method"}'

考虑避免这种情况,这将是更新逻辑,以便在将数据写入数据库时​​(例如无或不适用)写入某种排序填充字符串值,而不是空字符串或空字符串。然后,您可以只对字符串进行操作,然后搜索该值。

An option to consider to avoid this would be to update your logic to write some of sort filler string value instead of a null or empty string when writing your data to the database (i.e. "None" or "N/A"). Then you could solely operate on Strings and search on that value instead.

DynamoDB当前不允许空字符串的String值,如果尝试直接放置这些项目,则会给您错误。为了使此操作更轻松,许多SDK已为DyanmoDB项目提供了对象的映射器/转换器,这通常涉及将空字符串转换为Null类型,以解决没有空字符串的规则。

DynamoDB currently does not allow String values of an empty string and will give you errors if you try and put those items directly. To make this "easier", many of the SDKs have provided mappers/converters for objects to DyanmoDB items and this usually involves converting empty strings to Null types as a way of working around the rule of no empty strings.

如果需要区分 null ,当它们存储在DyanmoDB中时,您需要编写一些自定义逻辑以将空字符串编组/解组为唯一的字符串值(即 __ EMPTY_STRING )。

If you need to differentiate between null and "", you will need to write some custom logic to marshall/unmarshall empty strings to a unique string value (i.e. "__EMPTY_STRING") when they are stored in DyanmoDB.

这篇关于如何过滤NULL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆