简体   繁体   English

Azure Cosmos DB 列数限制

[英]Azure Cosmos DB Number of Columns Limit

The Azure Table Service documentation states that entities (rows) must have at most 255 properties, which I understand to mean these tables can have at most 255 columns, which seems highly restrictive. Azure 表服务文档指出实体(行)最多必须有 255 个属性,我理解这意味着这些表最多可以有 255 个列,这似乎具有高度限制性。

Two questions: first, do the same limits apply to Cosmos DB Table Storage?两个问题:第一,Cosmos DB 表存储是否适用相同的限制? I can't seem to find any documentation that says one way or another, though the language of "entities" is still used.尽管仍在使用“实体”的语言,但我似乎找不到任何以一种或另一种方式说明的文档。 And second--if the same limit applies in Cosmos DB--is there any useful way around this limit for storage and querying, along the lines of JSON in SQL Server ?其次——如果同样的限制适用于 Cosmos DB——是否有任何有用的方法来解决存储和查询的这个限制,沿着SQL Server 中JSON行?

EDIT: here is some example code that attempts to write entities with 260 properties to Cosmos DB Table Storage and the error that is thrown.编辑:这里是一些示例代码,尝试将具有 260 个属性的实体写入 Cosmos DB 表存储以及引发的错误。 Account names and keys and such are redacted帐户名称和密钥等已被编辑

# Libraries
from azure.cosmosdb.table.tableservice import TableService
from azure.cosmosdb.table.models import Entity
import csv
import os


# Connect
## Table Storage
"""
access_key = 'access_key'
table_service = TableService(account_name='account_name', account_key= access_key)
"""
## Cosmos DB Table Storage
connection_string = "connection_string"
table_service = TableService(connection_string=connection_string)

# Create Table
if not table_service.exists('testTable'):
    table_service.create_table('testTable')

length = 260
letters = [chr(i) for i in range(ord('a'), ord('z') + 1)]
keys = [a + b + c for a in letters for b in letters for c in letters][:length] 
values = ['0' * (8 - len(str(i))) + str(i) for i in range(length)]
entity = dict(zip(keys, values))
entity['PartitionKey'] = 'TestKey'
entity['RowKey'] = '1'
table_service.insert_entity('testTable', entity)

This raises "ValueError: The entity contains more properties than allowed."这会引发“ValueError:实体包含的属性多于允许的属性”。

first, do the same limits apply to Cosmos DB Table Storage?首先,同样的限制是否适用于 Cosmos DB 表存储?

Based on the Azure Table storage limits , as you said ,max number of properties in a table entity is 255 .根据Azure 表存储限制,如您所说,表实体中的最大属性数为255 However,I just found below statement in Azure Cosmos DB limits .但是,我刚刚在Azure Cosmos DB 限制中发现了以下语句。

Azure Cosmos DB is a global scale database in which throughput and storage can be scaled to handle whatever your application requires. Azure Cosmos DB 是一个全球规模的数据库,可以在其中扩展吞吐量和存储以处理应用程序需要的任何内容。 If you have any questions about the scale Azure Cosmos DB provides, please send email to askcosmosdb@microsoft.com.如果您对 Azure Cosmos DB 提供的规模有任何疑问,请发送电子邮件至 askcosmosdb@microsoft.com。

According to my test(I tired to add 260 properties into an entity), Azure Cosmos DB Table API accept that properties exceed 255.根据我的测试(我累了将 260 个属性添加到实体中),Azure Cosmos DB 表 API 接受属性超过 255。

在此处输入图片说明

If you want to get official reply, you could send email to above address.如果您想得到官方回复,您可以发送电子邮件到上述地址。

is there any useful way around this limit for storage and querying, along the lines of JSON in SQL Server?沿着 SQL Server 中的 JSON 行,是否有任何有用的方法可以绕过此存储和查询限制?

If you want to store and query data of json format, I suggest you using cosmos db SQL API.It is versatile and flexible.You could refer to the doc .如果你想存储和查询json格式的数据,我建议你使用cosmos db SQL API,它通用灵活,可以参考文档

Besides, if your data are stored in sql server database now.此外,如果您的数据现在存储在 sql server 数据库中。 You could use Migration Tool to import data into cosmos db.您可以使用迁移工具将数据导入 cosmos db。 Or you could Azure Data Factory to do more custom transmission.或者您可以使用Azure 数据工厂进行更多自定义传输。

Hope it helps you.希望对你有帮助。

Since this pops pretty high on Google searches: As of now, it's 255 (-2 if you encrypt)由于这在 Google 搜索中的流行度很高:截至目前,它是 255(如果加密则为 -2)

I just did a quick test using pytest:我刚刚使用 pytest 做了一个快速测试:

from azure.cosmosdb.table import TableService
field_number = 250
entity = get_dummy_dict_entry_with_many_col(field_number)
for x in range(field_number, 1000):
    print("Adding entity with {} elements.".format(len(entity)))
    table_service.insert_entity(my_test_table_name, entity)
    field_number += 1
    entity["Field_nb_{}".format(field_number)] = field_number
    entity["RowKey"] += str(field_number)

and got an exception in "def _validate_entity(entity, encrypt=None):"并在“def _validate_entity(entity, encrypt=None):”中出现异常

# Two properties are added during encryption. Validate sufficient space
max_properties = 255
if encrypt:
    max_properties = max_properties - 2  
# Validate there are not more than 255 properties including Timestamp
    if (len(entity) > max_properties) or (len(entity) == max_properties and 'Timestamp' not in entity):
>           raise ValueError(_ERROR_TOO_MANY_PROPERTIES)
E           ValueError: The entity contains more properties than allowed.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM