ENDSWITH (Azure Cosmos DB)ENDSWITH (Azure Cosmos DB)

返回一个布尔值,指示第一个字符串表达式是否以第二个字符串表达式结尾。Returns a Boolean indicating whether the first string expression ends with the second.

语法Syntax

ENDSWITH(<str_expr1>, <str_expr2> [, <bool_expr>])

参数Arguments

str_expr1str_expr1

是一个字符串表达式。Is a string expression.

str_expr2str_expr2

是要与 str_expr1 的结尾进行比较的字符串表达式。Is a string expression to be compared to the end of str_expr1.

bool_exprbool_expr

用于忽略大小写的可选值。Optional value for ignoring case. 如果设置为 true,则 ENDSWITH 将执行不区分大小写的搜索。When set to true, ENDSWITH will do a case-insensitive search. 如果未指定,则此值为 false。When unspecified, this value is false.

返回类型Return types

返回一个布尔表达式。Returns a Boolean expression.

示例Examples

以下示例检查字符串“abc”是否以“b”和“bC”结尾。The following example checks if the string "abc" ends with "b" and "bC".

SELECT ENDSWITH("abc", "b", false) AS e1, ENDSWITH("abc", "bC", false) AS e2, ENDSWITH("abc", "bC", true) AS e3

下面是结果集。Here is the result set.

[
    {
        "e1": false,
        "e2": false,
        "e3": true
    }
]

备注Remarks

此系统函数将从范围索引中获益。This system function will benefit from a range index.

EndsWith 的 RU 消耗将随着系统函数中属性的基数的增加而增加。The RU consumption of EndsWith will increase as the cardinality of the property in the system function increases. 换言之,如果要检查某个属性值是否以特定字符串结尾,则查询 RU 费用将取决于该属性的可能值数量。In other words, if you are checking whether a property value ends with a certain string, the query RU charge will depend on the number of possible values for that property.

例如,考虑两个属性:town 和 country。For example, consider two properties: town and country. town 的基数是 5,000,country 的基数是 200。The cardinality of town is 5,000 and the cardinality of country is 200. 下面展示了两个示例查询:Here are two example queries:

SELECT * FROM c WHERE ENDSWITH(c.town, "York", false)
SELECT * FROM c WHERE ENDSWITH(c.country, "States", false)

第一个查询可能比第二个查询使用更多的 RU,因为 town 的基数高于 country 的基数。The first query will likely use more RUs than the second query because the cardinality of town is higher than country.

如果某些文档的 EndsWith 中的属性大小大于 1 KB,则查询引擎需要加载这些文档。If the property size in EndsWith is greater than 1 KB for some documents, the query engine will need to load those documents. 在这种情况下,查询引擎将无法使用索引对 EndsWith 进行完全评估。In this case, the query engine won't be able to fully evaluate EndsWith with an index. 如果你有大量属性大小超过 1 KB 的文档,则 EndsWith 的 RU 费用将很高。The RU charge for EndsWith will be high if you have a large number of documents with property sizes greater than 1 KB.

后续步骤Next steps