$filter 数字文字的后缀(“number eq '5m”、“eq “5d”、...)仅在 OData 4.0 之前有效?
我发现有时可以发布一个 $filter
OData 2.0 请求,其中数字文字值以一个字母为后缀,就像可以测试 这里 "round(运费) eq 32l”。通过删除后缀或使用后缀 m
、M
、L
,其工作原理也相同。如果使用 d
或 f
,则会出现类型不匹配错误(与 Edm.Decimal
属性一起使用的浮点文字)。如果使用 a
、b
(等等),则表示语法错误。
d
:Edm.Double
f
:Edm.Single
L
:Edm.Int64
m
或M
:Edm.Decimal
- 其他字母无效
有时,似乎这个后缀是强制的,并且有时不是。
我在 OData 标准中进行了一些搜索(我的发现如下所述)。我得出的结论是,在 OData 2.0 和 3.0 中这些后缀是强制性的,但从 OData 4.0 开始这些后缀无效。 (编辑后的文本,请参阅编辑 1)
您能否确认这一点,并且您能否分享一些官方 OData 解释来解释 OData 4.0 中的这一重大变化?
我的发现:
(1) OData 2.0 > URI 约定,然后滚动到 4.5。过滤系统查询选项($filter)(虽然文本“32d”指的是带有“32”的链接,但在 URL 中手动设置“32d”也可以):
(2) OData 2.0 >概述,然后滚动到 6. 原始数据类型:
(3) OData 3.0 > URL 约定,然后滚动到 5.1.2。过滤系统查询选项 ($filter) 和 5.1.2.2.6。算术运算符示例,其中提到了“M”数字文字 (Edm.Decimal):
(4) OData 4.01 >第 1 部分:协议 > 11.2.6.1.2。内置查询函数,然后滚动到算术函数,不再提及“32d”:
(5) OData 4.01>第 2 部分:URL 约定 > 5.1.1.9。算术函数 > 5.1.1.9.3 轮:
(6) OData ABNF 构造规则版本 4.01,然后滚动到“decimalValue ="
编辑 1(7 月2024年9月9日):再次查看OData 3.0,我没有看到与2022年相同的情况,因此变化发生在OData 4.0中。
I see that sometimes it's possible to post a $filter
OData 2.0 request with numeric literal values suffixed with one letter, like can be tested here "round(Freight) eq 32l". It also works identically by removing the suffix or using suffixes m
, M
, L
. If using d
or f
there's a type mismatch error (floating point literal used with an Edm.Decimal
property). If using a
, b
(among others) it indicates a syntax error.
d
:Edm.Double
f
:Edm.Single
L
:Edm.Int64
m
orM
:Edm.Decimal
- Other letters are invalid
Sometimes, it seems that this suffix is mandatory, and sometimes not.
I have searched in the OData standards a little bit (my findings are described below). I came to the conclusion that in OData 2.0 and 3.0 these suffixes were mandatory, but since OData 4.0 these suffixes are invalid. (edited text, see EDIT 1)
Could you confirm that, and could you share some official OData explanations to explain this big change in OData 4.0?
My findings:
(1) OData 2.0 > URI Conventions, then scroll to 4.5. Filter System Query Option ($filter) (althouth the text "32d" refers to link with "32", but setting manually "32d" in the URL also works):
(2) OData 2.0 > Overview, then scroll to 6. Primitive Data Types:
(3) OData 3.0 > URL Conventions, then scroll to 5.1.2. Filter System Query Option ($filter) and 5.1.2.2.6. Arithmetic Operator Examples, there are mentions to "M" numeric literals (Edm.Decimal):
(4) OData 4.01 > Part 1: Protocol > 11.2.6.1.2. Built-in Query Functions, then scroll to Arithmetic Functions, there's no more mention of "32d":
(5) OData 4.01 > Part 2: URL Conventions > 5.1.1.9. Arithmetic Functions > 5.1.1.9.3 round:
(6) OData ABNF Construction Rules Version 4.01, then scroll to "decimalValue ="
EDIT 1 (July 9th, 2024): looking at OData 3.0 again, I don't see the same as in 2022, so the change happened in OData 4.0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
后缀
d
、f
和m
仅在 OData V2 中允许(并且某些实现需要)。OData V4 中的数字文字不需要或允许使用这些后缀。
The suffixes
d
,f
, andm
are only allowed (and required by some implementations) in OData V2.Numeric literals in OData V4 don't need or allow these suffixes.
这是参考文档,表明 OData 4.0 中发生了更改。 新增内容在 OData 版本 4.0 中,然后滚动到 3.2 查询选项 > 3.2.10 修剪:数字类型的 URI 文字后缀:
这里是 OData 4.0 委员会规范 02 的 ABNF 文档,滚动到“decimalValue ="(注意:4.01 中相同):
5.1.1.15 数字促销(OData 版本 4.0。第 2 部分:URL 约定以及勘误表 03):
以下信息与问题无关(
$filter
或其他 URI 数字表示形式),但适用于请求正文中的数字,此处为 JSON 格式。 3.2 控制数字的表示:Here is the reference document which indicates that the change happened in OData 4.0. What’s New in OData Version 4.0, then scroll to 3.2 Query Options > 3.2.10 Pruned: URI Literal suffixes for numeric types:
Here is the ABNF documentation of OData 4.0 Committee Specification 02, scroll to "decimalValue =" (NB: it's the same in 4.01):
5.1.1.15 Numeric Promotion (OData Version 4.0. Part 2: URL Conventions Plus Errata 03):
The below information is not related to the question (
$filter
or other URI numeric representations), but applies to numbers in the body of requests, here in JSON format. 3.2 Controlling the Representation of Numbers: