Null 值Null Values

Kusto 中的所有标量数据类型都有表示缺失值的特殊值。All scalar data types in Kusto have a special value that represents a missing value. 此值称为“null 值”,简称“null” 。This value is called the null value, or simply null.

null 文本Null literals

标量类型 T 的 null 值由 null 文本 T(null) 以查询语言表示。The null value of a scalar type T is represented in the query language by the null literal T(null). 因此,以下语句返回一个单行,其中包含的值全是 null 值:Thus, the following returns a single row full of nulls:

print bool(null), datetime(null), dynamic(null), guid(null), int(null), long(null), real(null), double(null), time(null)


请注意,当前 string 类型不支持 null 值。Please note that currently the string type doesn't support null values.

将 null 与某个值进行比较Comparing null to something

null 值不等于该数据类型的任何其他值,包括它本身。The null value does not compare equal to any other value of the data type, including itself. (也就是说,null == null 为 false。)若要确定某个值是否为 null 值,请使用 isnull() 函数和 isnotnull() 函数。(That is, null == null is false.) To determine if some value is the null value, use the isnull() function and the isnotnull() function.

针对 null 的二进制运算Binary operations on null

通常,null 以“粘性”方式围绕二进制运算符运行;null 值和任何其他值(包括另一个 null 值)之间的二进制运算生成 null 值。In general, null behaves in a "sticky" way around binary operators; a binary operation between a null value and any other value (including another null value) produces a null value.

数据引入和 null 值Data ingestion and null values

对于大多数数据类型,数据源中的缺失值在相应的表单元格中生成 null 值。For most data types, a missing value in the data source produces a null value in the corresponding table cell. 对此,例外情况是类型为 string 的列和类似 CSV 的引入,此情况下缺失的值生成空字符串。An exception to that are columns of type string and CSV-like ingestion, where a missing value produces an empty string. 例如,如果有以下情况:So, for example, if we have:

.create table T [a:string, b:int]

.ingest inline into table T
[ , ]


aa bb isnull(a)isnull(a) isempty(a)isempty(a) strlen(a)strlen(a) isnull(b)isnull(b)
    falsefalse truetrue 00 truetrue
    falsefalse falsefalse 11 true
aa 11 falsefalse falsefalse 11 falsefalse
  • 如果在 Kusto.Explorer 中运行上述查询,则所有 true 值将显示为 1,所有 false 值将显示为 0If you run the query above in Kusto.Explorer, all true values will be displayed as 1, and all false values will be displayed as 0.
  • Kusto 未提供用于限制表列,使其不具有 null 值的方法(换句话说,SQL 的 NOT NULL 约束没有对等项)。Kusto does not offer a way to constrain a table's column from having null values (in other words, there's no equivalent to SQL's NOT NULL constraint).