tableau icon indicating copy to clipboard operation
tableau copied to clipboard

confgen: support multi-key map

Open Kybxd opened this issue 6 months ago • 1 comments

Sometimes we want to map multiple different keys to the same value, but we don't want to occupy to many cells. So we expect keys with the same value can be defined in the same cell. For example:

Group1ItemID Group1ItemWeight Group2ItemID Group2ItemWeight Group3ItemID Group3ItemWeight
map<uint32, Group>|{multikey:true} int32 uint32 int32 uint32 int32
Group1’s ItemID Group1’s ItemWeight Group2’s ItemID Group2’s ItemWeight Group3’s ItemID Group3’s ItemWeight
101,102,103 100 201,202 200 301 300

This worksheet generates proto:

message ItemConf {
  option (tableau.worksheet) = {name:"ItemConf"};

  map<uint32, Group> group_map = 1 [(tableau.field) = {name:"Group" key:"ItemID" layout:LAYOUT_HORIZONTAL prop:{multikey:true}}];
  message Group {
    uint32 item_id = 1 [(tableau.field) = {name:"ItemID"}];
    int32 item_weight = 2 [(tableau.field) = {name:"ItemWeight"}];
  }
}

And json:

{
    "groupMap": {
        "101": {
            "itemId": 101,
            "itemWeight": 100
        },
        "102": {
            "itemId": 102,
            "itemWeight": 100
        },
        "103": {
            "itemId": 103,
            "itemWeight": 100
        },
        "201": {
            "itemId": 201,
            "itemWeight": 200
        },
        "202": {
            "itemId": 202,
            "itemWeight": 200
        },
        "301": {
            "itemId": 301,
            "itemWeight": 300
        }
    }
}

Kybxd avatar Jul 14 '25 06:07 Kybxd

The multikey-map concept is confused. By default, keys are guaranteed to be unique.

1. Multi same keys to different values

2. A unique composite key (which contains multiple keys) to a value

A data structure to store values with multiple keys in a map.

So, we should define a accurate and clear naming but not multikey.

wenchy avatar Jul 16 '25 03:07 wenchy