@@ -37,17 +37,31 @@ public void testAddDimensions() {
3737
3838 // if these change, we'll need a new index version
3939 // because it means existing time series will get a new _tsid and will be routed to a different shard
40- assertThat (builder .hash ().toString (), equalTo ("0xd4de1356065d297a2be489781e15d256" )); // used to make shard routing decisions
40+ assertThat (builder .hash ().toString (), equalTo ("0xd4de1356065d297a2be489781e15d256" ));
4141 BytesRef bytesRef = builder .buildTsid ();
4242 assertThat (bytesRef , notNullValue ());
43- // 4 bytes for path hash + 1 byte per value (up to 16 , only first value for arrays) + 16 bytes for hash
44- assertThat (bytesRef .length , equalTo (26 ));
43+ // 1 byte for path hash + 1 byte per value (up to 4 , only first value for arrays) + 16 bytes for hash
44+ assertThat (bytesRef .length , equalTo (21 ));
4545 assertThat (
4646 HexFormat .of ().formatHex (bytesRef .bytes , bytesRef .offset , bytesRef .length ),
47- equalTo ("bf438ddaa0a8d663fdbb56d2151e7889e42b7a295d065613ded4 " ) // _tsid in hex format
47+ equalTo ("bfa0a8d66356d2151e7889e42b7a295d065613ded4 " ) // _tsid in hex format
4848 );
4949 }
5050
51+ public void testArray () {
52+ TsidBuilder builder = TsidBuilder .newBuilder ().addStringDimension ("test_non_array" , "value" );
53+
54+ int arrayValues = randomIntBetween (32 , 64 );
55+ for (int i = 0 ; i < arrayValues ; i ++) {
56+ builder .addStringDimension ("_test_large_array" , "value_" + i );
57+ }
58+
59+ BytesRef bytesRef = builder .buildTsid ();
60+ assertThat (bytesRef , notNullValue ());
61+ // 1 byte for path hash + 2 bytes for value hash (1 for the first array value and 1 for the the non-array value) + 16 bytes for hash
62+ assertThat (bytesRef .length , equalTo (19 ));
63+ }
64+
5165 public void testOrderingOfDifferentFieldsDoesNotMatter () {
5266 assertEqualBuilders (
5367 TsidBuilder .newBuilder ().addStringDimension ("foo" , "bar" ).addStringDimension ("baz" , "qux" ),
@@ -114,19 +128,20 @@ public void testExceptionWhenNoDimensions() {
114128 public void testTsidMinSize () {
115129 BytesRef tsid = TsidBuilder .newBuilder ().addIntDimension ("test_int" , 42 ).buildTsid ();
116130
117- // The TSID format should be: 4 bytes for path hash + 1 byte per value (up to 16 ) + 16 bytes for hash
118- // Since we only added one dimension, we expect: 4 + 1 + 16 = 21 bytes
119- assertEquals (21 , tsid .length );
131+ // The TSID format should be: 1 bytes for path hash + 1 byte per value (up to 4 ) + 16 bytes for hash
132+ // Since we only added one dimension, we expect: 1 + 1 + 16 = 21 bytes
133+ assertEquals (18 , tsid .length );
120134 }
121135
122136 public void testTsidMaxSize () {
123137 TsidBuilder tsidBuilder = TsidBuilder .newBuilder ();
124- for (int i = 0 ; i < 32 ; i ++) {
138+ int dimensions = randomIntBetween (4 , 64 );
139+ for (int i = 0 ; i < dimensions ; i ++) {
125140 tsidBuilder .addStringDimension ("dimension_" + i , "value_" + i );
126141 }
127142
128- // The TSID format should be: 4 bytes for path hash + 1 byte per value (up to 16 ) + 16 bytes for hash
129- // Since we added 32 dimensions, we expect: 4 + 16 + 16 = 36 bytes
130- assertEquals (36 , tsidBuilder .buildTsid ().length );
143+ // The TSID format should be: 1 bytes for path hash + 1 byte per value (up to 4 ) + 16 bytes for hash
144+ // Since we added at least 32 dimensions, we expect: 1 + 4 + 16 = 21 bytes
145+ assertEquals (21 , tsidBuilder .buildTsid ().length );
131146 }
132147}
0 commit comments