Cosmos 中的 Cassandra 表不支持静态属性 - 使用 ARM 模板或 terraform

问题描述 投票:0回答:1

在 Cosmos Cassandra 中创建具有静态属性和数据类型的表失败!部署键空间后使用 CQL 创建表可以很好地处理静态字段。还有其他人面临相同或类似的问题吗? 这是一个 github 问题:https://github.com/Azure/azure-rest-api-specs/issues/26506

我尝试使用以下脚本运行

terraform apply

resource "azurerm_resource_group" "example" {
  name     = "tflex-cosmosdb-account-rg"
  location = "West Europe"
}

resource "azurerm_cosmosdb_account" "example" {
  name                = "tfex-cosmosdb-account"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  offer_type          = "Standard"

  capabilities {
    name = "EnableCassandra"
  }

  consistency_policy {
    consistency_level = "Strong"
  }

  geo_location {
    location          = azurerm_resource_group.example.location
    failover_priority = 0
  }
}

resource "azurerm_cosmosdb_cassandra_keyspace" "example" {
  name                = "tfex-cosmos-cassandra-keyspace"
  resource_group_name = azurerm_cosmosdb_account.example.resource_group_name
  account_name        = azurerm_cosmosdb_account.example.name
  throughput          = 400
}

resource "azurerm_cosmosdb_cassandra_table" "example" {
  name                  = "testtable"
  cassandra_keyspace_id = azurerm_cosmosdb_cassandra_keyspace.example.id

  schema {

    column {
      name = "id"
      type = "uuid"
    }
    column {
      name = "type"
      type = "text"
    }
    column {
      name = "source"
      type = "text"
    }
    column {
      name = "time"
      type = "timestamp"
    }
    column {
      name = "entity"
      type = "text"
    }
    column {
      name = "ownerid"
      type = "uuid"
    }
    column {
      name = "ownertype"
      type = "text"
    }
    column {
      name = "data"
      type = "blob"
    }
    column {
      name = "sequence"
      type = "int"
    }
    column {
      name = "cloudeventview"
      type = "blob static"
    }
    
    column {
      name = "lastupdated"
      type = "timestamp static"
    }
    partition_key {
      name = "ownertype"
    }
    partition_key {
      name = "ownerid"
    }
    cluster_key {
      name     = "sequence"
      order_by = "Desc"
    }
  }
}

表已创建,但没有静态字段。根据 Azure 的文档 数据类型声明支持静态。

cassandra terraform azure-cosmosdb azure-cosmosdb-cassandra-api
1个回答
0
投票
我尝试使用 Terraform 在 Cosmos 的 Cassandra 表中配置静态属性类型,并且我能够成功地配置需求。

在 Cassandra 中,静态列由同一分区的所有行共享。

查看您的 Terraform 脚本,您已将

cloudeventview

lastupdated
 列定义为静态。但是,问题可能出在用于定义静态列的语法中。在 CQL 中定义静态列的标准语法是 
column_name type static
,但此语法可能无法直接在 Terraform 中转换。

确保您使用的 Terraform 提供程序支持定义静态列的语法。语法可能不同或者提供程序的当前版本有限制

我的地形配置:

main.tf:

provider "azurerm" { features {} # Here I provided the latest version to eliminate all the compatibility issues } # Resource Group resource "azurerm_resource_group" "example" { name = "tflex-cosmosdb-vkaccount-rg" location = "east us" } # Cosmos DB Account resource "azurerm_cosmosdb_account" "example" { name = "tfex-cosmosdb-account" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location offer_type = "Standard" capabilities { name = "EnableCassandra" } consistency_policy { consistency_level = "Strong" } geo_location { location = azurerm_resource_group.example.location failover_priority = 0 } } # Cassandra Keyspace resource "azurerm_cosmosdb_cassandra_keyspace" "example" { name = "tfex-cosmos-cassandra-keyspace" resource_group_name = azurerm_cosmosdb_account.example.resource_group_name account_name = azurerm_cosmosdb_account.example.name throughput = 400 } # Cosmos DB Cassandra Table without static fields resource "azurerm_cosmosdb_cassandra_table" "example" { name = "testtable" cassandra_keyspace_id = azurerm_cosmosdb_cassandra_keyspace.example.id # Define schema without static fields schema { column { name = "id" type = "uuid" } column { name = "type" type = "text" } column { name = "source" type = "text" } column { name = "time" type = "timestamp" } column { name = "entity" type = "text" } column { name = "ownerid" type = "uuid" } column { name = "ownertype" type = "text" } column { name = "data" type = "blob" } column { name = "sequence" type = "int" } column { name = "cloudeventview" type = "blob static" } column { name = "lastupdated" type = "timestamp static" } partition_key { name = "ownertype" } partition_key { name = "ownerid" } cluster_key { name = "sequence" order_by = "Desc" } } }

输出:

enter image description here

enter image description here

参考:

Azure Cosmos DB for Apache Cassandra 支持的 Apache Cassandra 功能 |微软学习

© www.soinside.com 2019 - 2024. All rights reserved.