.alter materialized-view.alter materialized-view

更改具体化视图可用于更改具体化视图的查询,同时保留视图中的现有数据。Altering the materialized view can be used for changing the query of a materialized view, while preserving the existing data in the view.

需要数据库管理员权限或具体化视图的管理员角色。Requires Database Admin permissions, or an admin of the materialized view.

警告

更改具体化视图时要格外小心。Be extra cautious when altering a materialized view. 使用不当可能会导致数据丢失。Incorrect use may lead to data loss.

语法Syntax

.alter materialized-view.alter materialized-view
[ with (PropertyName = PropertyValue,...)][ with (PropertyName = PropertyValue,...)]
ViewName on table SourceTableNameViewName on table SourceTableName
{
    Query    Query
}

参数Arguments

参数Argument 类型Type 说明Description
视图名ViewName 字符串String 具体化视图名称。Materialized view name.
SourceTableNameSourceTableName 字符串String 定义视图的源表的名称。Name of source table on which the view is defined.
查询Query StringString 具体化视图查询。The materialized view query.

属性Properties

dimensionTables 是 materialized-view alter 命令唯一支持的属性。The dimensionTables is the only supported property in materialized-view alter command. 此属性应在查询引用维度表时使用。This property should be used in case query references dimension tables. 有关详细信息,请参阅 .create materialized-view 命令。For more information, see the .create materialized-view command.

用例Use cases

  • 向视图添加聚合 - 例如,通过将视图查询更改为 T | summarize count(), min(Value), avg(Value) by Id,将 avg 聚合添加到 T | summarize count(), min(Value) by Id 中。Add aggregations to the view - for example, add avg aggregation to T | summarize count(), min(Value) by Id, by altering view query to T | summarize count(), min(Value), avg(Value) by Id.
  • 更改除 summarize 运算符之外的运算符。Change operators other than the summarize operator. 例如,通过将 T | summarize arg_max(Timestamp, *) by User 更改为 T | where User != 'someone' | summarize arg_max(Timestamp, *) by User 来筛选掉某些记录。Tor example, filter out some records by altering T | summarize arg_max(Timestamp, *) by User to T | where User != 'someone' | summarize arg_max(Timestamp, *) by User.
  • 由于源表发生了更改,在不更改查询的情况下更改。Alter with no change to the query because of a change in source table. 例如,假定 T | summarize arg_max(Timestamp, *) by Id 视图,它未设置为 autoUpdateSchema(请参阅 .create materialized-view 命令)。Tor example, assume a view of T | summarize arg_max(Timestamp, *) by Id, which isn't set to autoUpdateSchema (see .create materialized-view command). 如果在视图的源表中添加或删除了某列,则该视图将自动禁用。If a column is added or removed from the source table of the view, the view will be automatically disabled. 使用完全相同的查询执行 alter 命令,以更改具体化视图的架构,使之与新表架构保持一致。Execute the alter command, with the exact same query, to change the materialized view's schema to align with new table schema. 在更改后,仍必须使用 enable materialized view 命令显式启用该视图。The view still must be explicitly enabled following the change, using the enable materialized view command.

更改具体化视图的限制Alter materialized view limitations

  • 不支持的更改:Changes not supported:

    • 不支持更改列类型。Changing column type isn't supported.
    • 不支持重命名列。Renaming columns isn't supported. 例如,将 T | summarize count() by Id 视图更改为 T | summarize Count=count() by Id 将删除 count_ 列并创建新列 Count(该列最初将仅包含 null)。For example, altering a view of T | summarize count() by Id to T | summarize Count=count() by Id will drop column count_ and create a new column Count, which will initially contain nulls only.
    • 不支持通过表达式对具体化视图组进行更改。Changes to the materialized view group by expressions aren't supported.
  • 对现有数据的影响:Impact on existing data:

    • 更改具体化视图不会影响现有数据。Altering the materialized view has no impact on existing data.
    • 新列将接收所有现有记录的空值,直到引入的记录发布 alter 命令来修改 null 值。New columns will receive nulls for all existing records until records ingested post the alter command modify the null values.
      • 例如:如果 T | summarize count() by bin(Timestamp, 1d) 视图更改为 T | summarize count(), sum(Value) by bin(Timestamp, 1d),则对于那些已在更改视图之前处理的记录的特定 Timestamp=Tsum 列将包含部分数据。For example: if a view of T | summarize count() by bin(Timestamp, 1d) is altered to T | summarize count(), sum(Value) by bin(Timestamp, 1d), then for a particular Timestamp=T for which records have already been processed before altering the view, the sum column will contain partial data. 此视图仅包含在 alter 执行后处理的记录。This view only includes records processed after the alter execution.
    • 向查询添加筛选器不会更改已具体化的记录。Adding filters to the query doesn't change records that have already been materialized. 筛选器将仅适用于新引入的记录。The filter will only apply to newly ingested records.