@@ -37,17 +37,31 @@ public void testAddDimensions() {
37
37
38
38
// if these change, we'll need a new index version
39
39
// 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" ));
41
41
BytesRef bytesRef = builder .buildTsid ();
42
42
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 ));
45
45
assertThat (
46
46
HexFormat .of ().formatHex (bytesRef .bytes , bytesRef .offset , bytesRef .length ),
47
- equalTo ("bf438ddaa0a8d663fdbb56d2151e7889e42b7a295d065613ded4 " ) // _tsid in hex format
47
+ equalTo ("bfa0a8d66356d2151e7889e42b7a295d065613ded4 " ) // _tsid in hex format
48
48
);
49
49
}
50
50
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
+
51
65
public void testOrderingOfDifferentFieldsDoesNotMatter () {
52
66
assertEqualBuilders (
53
67
TsidBuilder .newBuilder ().addStringDimension ("foo" , "bar" ).addStringDimension ("baz" , "qux" ),
@@ -114,19 +128,20 @@ public void testExceptionWhenNoDimensions() {
114
128
public void testTsidMinSize () {
115
129
BytesRef tsid = TsidBuilder .newBuilder ().addIntDimension ("test_int" , 42 ).buildTsid ();
116
130
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 );
120
134
}
121
135
122
136
public void testTsidMaxSize () {
123
137
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 ++) {
125
140
tsidBuilder .addStringDimension ("dimension_" + i , "value_" + i );
126
141
}
127
142
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 );
131
146
}
132
147
}
0 commit comments