You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Cassandra Map数据类型支持的类型及timestamp作为键的合理性咨询

Hey there! As someone who’s worked with Cassandra for years, let’s walk through your questions about the Map data type clearly and straightforwardly.

1. Supported Data Types for Cassandra Maps

Cassandra's map is a collection type that stores key-value pairs, with specific rules for valid key and value types:

  • Map Keys: Must be immutable native Cassandra types (since keys are hashed for efficient lookups). Valid options include:

    • Numeric types: int, bigint, smallint, tinyint, float, double, decimal
    • String types: text, varchar
    • Date/time types: timestamp, date, time
    • Identifier types: uuid, timeuuid
    • Network type: inet
    • Boolean type: boolean
      Note: Mutable types like collections, user-defined types (UDTs), or tuples can’t be used as map keys.
  • Map Values: Far more flexible—you can use any native Cassandra type, including all the ones listed above, plus collections (list, set, map), UDTs, tuples, and even frozen collections/UDTs.

2. Validity of the login_user Table with map<timestamp, text>

Great news: Your table creation statement is 100% valid!

timestamp is a perfectly acceptable immutable type for map keys, and text is a standard, valid type for map values. Let’s confirm with your exact code:

CREATE TABLE login_user ( 
    user_name text, 
    password text, 
    location map<timestamp,text>, 
    PRIMARY KEY (user_name) 
);

This will work exactly as you intend. A quick heads-up: Since map keys are unique per row, if you insert a new entry into the location map with a timestamp that already exists for a user, it will overwrite the existing text value for that key. That’s standard Cassandra collection behavior—just something to keep in mind as you work with the table.

内容的提问来源于stack exchange,提问作者Inuri Jayanika Ginige

火山引擎 最新活动