1717 */
1818package org .apache .hadoop .hive .llap .cache ;
1919
20- import java .util .HashMap ;
2120import java .util .LinkedHashMap ;
22- import java .util .Map ;
2321
2422import org .apache .hadoop .hive .common .io .CacheTag ;
23+ import org .apache .hadoop .hive .metastore .Warehouse ;
2524
2625import org .junit .BeforeClass ;
2726import org .junit .Test ;
@@ -53,16 +52,20 @@ public static void setup() {
5352 */
5453 @ Test
5554 public void testParentCacheTagGeneration () {
56- CacheTag db = cacheTagBuilder ("dbname" );
57- CacheTag table = cacheTagBuilder ("dbname.tablename" );
58- CacheTag p = cacheTagBuilder ("dbname.tablename" , "p=v1" );
59- CacheTag pp = cacheTagBuilder ("dbname.tablename" , "p=v1" , "pp=vv1" );
60- CacheTag ppp = cacheTagBuilder ("dbname.tablename" , "p=v1" , "pp=vv1" , "ppp=vvv1" );
55+ // DB-level tag: tableName = "hive.dbname" (catalog prepended, one dot).
56+ CacheTag db = cacheTagBuilder (Warehouse .DEFAULT_CATALOG_NAME + ".dbname" );
57+ // Table-level tag: tableName = "hive.dbname.tablename" (two dots).
58+ CacheTag table = cacheTagBuilder (Warehouse .DEFAULT_CATALOG_NAME + ".dbname.tablename" );
59+ CacheTag p = cacheTagBuilder (Warehouse .DEFAULT_CATALOG_NAME + ".dbname.tablename" , "p=v1" );
60+ CacheTag pp = cacheTagBuilder (Warehouse .DEFAULT_CATALOG_NAME + ".dbname.tablename" , "p=v1" , "pp=vv1" );
61+ CacheTag ppp = cacheTagBuilder (Warehouse .DEFAULT_CATALOG_NAME + ".dbname.tablename" , "p=v1" , "pp=vv1" , "ppp=vvv1" );
6162
6263 assertTrue (pp .compareTo (CacheTag .createParentCacheTag (ppp )) == 0 );
6364 assertTrue (p .compareTo (CacheTag .createParentCacheTag (pp )) == 0 );
6465 assertTrue (table .compareTo (CacheTag .createParentCacheTag (p )) == 0 );
66+ // createParentCacheTag(table) strips the table part → "hive.dbname" which equals db.
6567 assertTrue (db .compareTo (CacheTag .createParentCacheTag (table )) == 0 );
68+ // DB-level tag has exactly one dot; the hierarchy stops here.
6669 assertNull (CacheTag .createParentCacheTag (db ));
6770 }
6871
@@ -127,7 +130,7 @@ public void testCacheTagComparison() {
127130 public void testEncodingDecoding () throws Exception {
128131 LinkedHashMap <String , String > partDescs = new LinkedHashMap <>();
129132 partDescs .put ("pytha=goras" , "a2+b2=c2" );
130- CacheTag tag = CacheTag .build (" math.rules" , partDescs );
133+ CacheTag tag = CacheTag .build (Warehouse . DEFAULT_CATALOG_NAME + ". math.rules" , partDescs );
131134 CacheTag .SinglePartitionCacheTag stag = ((CacheTag .SinglePartitionCacheTag )tag );
132135 assertEquals ("pytha=goras=a2+b2=c2" , stag .partitionDescToString ());
133136 assertEquals (1 , stag .getPartitionDescMap ().size ());
@@ -136,7 +139,7 @@ public void testEncodingDecoding() throws Exception {
136139 partDescs .clear ();
137140 partDescs .put ("mutli=one" , "one=/1" );
138141 partDescs .put ("mutli=two/" , "two=2" );
139- tag = CacheTag .build (" math.rules" , partDescs );
142+ tag = CacheTag .build (Warehouse . DEFAULT_CATALOG_NAME + ". math.rules" , partDescs );
140143 CacheTag .MultiPartitionCacheTag mtag = ((CacheTag .MultiPartitionCacheTag )tag );
141144 assertEquals ("mutli=one=one=/1/mutli=two/=two=2" , mtag .partitionDescToString ());
142145 assertEquals (2 , mtag .getPartitionDescMap ().size ());
@@ -167,81 +170,83 @@ private static LlapCacheableBuffer createMockBuffer(long size, CacheTag cacheTag
167170 return llapCacheableBufferMock ;
168171 }
169172
170- public static CacheTag cacheTagBuilder (String dbAndTable , String ... partitions ) {
173+ public static CacheTag cacheTagBuilder (String fullTableName , String ... partitions ) {
171174 if (partitions != null && partitions .length > 0 ) {
172175 LinkedHashMap <String , String > partDescs = new LinkedHashMap <>();
173176 for (String partition : partitions ) {
174177 String [] partDesc = partition .split ("=" );
175178 partDescs .put (partDesc [0 ], partDesc [1 ]);
176179 }
177- return CacheTag .build (dbAndTable , partDescs );
180+ return CacheTag .build (fullTableName , partDescs );
178181 } else {
179- return CacheTag .build (dbAndTable );
182+ return CacheTag .build (fullTableName );
180183 }
181184 }
182185
186+ private static final String DEF_CAT = Warehouse .DEFAULT_CATALOG_NAME + "." ;
187+
183188 private static void cacheTestBuffers () {
184189 tracker .cache (createMockBuffer (4 * 1024L ,
185- cacheTagBuilder ("default.testtable" )), null );
190+ cacheTagBuilder (DEF_CAT + "default.testtable" )), null );
186191 tracker .cache (createMockBuffer (2 * 1024L ,
187- cacheTagBuilder ("otherdb.testtable" , "p=v1" , "pp=vv1" )), null );
192+ cacheTagBuilder (DEF_CAT + "otherdb.testtable" , "p=v1" , "pp=vv1" )), null );
188193 tracker .cache (createMockBuffer (32 * 1024L ,
189- cacheTagBuilder ("otherdb.testtable" , "p=v1" , "pp=vv1" )), null );
194+ cacheTagBuilder (DEF_CAT + "otherdb.testtable" , "p=v1" , "pp=vv1" )), null );
190195 tracker .cache (createMockBuffer (64 * 1024L ,
191- cacheTagBuilder ("otherdb.testtable" , "p=v1" , "pp=vv2" )), null );
196+ cacheTagBuilder (DEF_CAT + "otherdb.testtable" , "p=v1" , "pp=vv2" )), null );
192197 tracker .cache (createMockBuffer (128 * 1024L ,
193- cacheTagBuilder ("otherdb.testtable" , "p=v2" , "pp=vv1" )), null );
198+ cacheTagBuilder (DEF_CAT + "otherdb.testtable" , "p=v2" , "pp=vv1" )), null );
194199 tracker .cache (createMockBuffer (256 * 1024L ,
195- cacheTagBuilder ("otherdb.testtable2" , "p=v3" )), null );
200+ cacheTagBuilder (DEF_CAT + "otherdb.testtable2" , "p=v3" )), null );
196201 tracker .cache (createMockBuffer (512 * 1024 * 1024L ,
197- cacheTagBuilder ("otherdb.testtable2" , "p=v3" )), null );
202+ cacheTagBuilder (DEF_CAT + "otherdb.testtable2" , "p=v3" )), null );
198203 tracker .cache (createMockBuffer (1024 * 1024 * 1024L ,
199- cacheTagBuilder ("otherdb.testtable3" )), null );
204+ cacheTagBuilder (DEF_CAT + "otherdb.testtable3" )), null );
200205 tracker .cache (createMockBuffer (2 * 1024 * 1024L ,
201- cacheTagBuilder ("default.testtable" )), null );
206+ cacheTagBuilder (DEF_CAT + "default.testtable" )), null );
202207 }
203208
204209 private static void evictSomeTestBuffers () {
205210 tracker .notifyEvicted (createMockBuffer (32 * 1024L ,
206- cacheTagBuilder ("otherdb.testtable" , "p=v1" , "pp=vv1" )));
211+ cacheTagBuilder (DEF_CAT + "otherdb.testtable" , "p=v1" , "pp=vv1" )));
207212 tracker .notifyEvicted (createMockBuffer (512 * 1024 * 1024L ,
208- cacheTagBuilder ("otherdb.testtable2" , "p=v3" )));
213+ cacheTagBuilder (DEF_CAT + "otherdb.testtable2" , "p=v3" )));
209214 tracker .notifyEvicted (createMockBuffer (2 * 1024 * 1024L ,
210- cacheTagBuilder ("default.testtable" )));
215+ cacheTagBuilder (DEF_CAT + "default.testtable" )));
211216 tracker .notifyEvicted (createMockBuffer (4 * 1024L ,
212- cacheTagBuilder ("default.testtable" )));
217+ cacheTagBuilder (DEF_CAT + "default.testtable" )));
213218 }
214219
215220 private static final String EXPECTED_CACHE_STATE_WHEN_FULL =
216221 "\n " +
217222 "Cache state: \n " +
218- "default : 2/2, 2101248/2101248\n " +
219- "default.testtable : 2/2, 2101248/2101248\n " +
220- "otherdb : 7/7, 1611106304/1611106304\n " +
221- "otherdb.testtable : 4/4, 231424/231424\n " +
222- "otherdb.testtable/p=v1 : 3/3, 100352/100352\n " +
223- "otherdb.testtable/p=v1/pp=vv1 : 2/2, 34816/34816\n " +
224- "otherdb.testtable/p=v1/pp=vv2 : 1/1, 65536/65536\n " +
225- "otherdb.testtable/p=v2 : 1/1, 131072/131072\n " +
226- "otherdb.testtable/p=v2/pp=vv1 : 1/1, 131072/131072\n " +
227- "otherdb.testtable2 : 2/2, 537133056/537133056\n " +
228- "otherdb.testtable2/p=v3 : 2/2, 537133056/537133056\n " +
229- "otherdb.testtable3 : 1/1, 1073741824/1073741824" ;
223+ "hive. default : 2/2, 2101248/2101248\n " +
224+ "hive. default.testtable : 2/2, 2101248/2101248\n " +
225+ "hive. otherdb : 7/7, 1611106304/1611106304\n " +
226+ "hive. otherdb.testtable : 4/4, 231424/231424\n " +
227+ "hive. otherdb.testtable/p=v1 : 3/3, 100352/100352\n " +
228+ "hive. otherdb.testtable/p=v1/pp=vv1 : 2/2, 34816/34816\n " +
229+ "hive. otherdb.testtable/p=v1/pp=vv2 : 1/1, 65536/65536\n " +
230+ "hive. otherdb.testtable/p=v2 : 1/1, 131072/131072\n " +
231+ "hive. otherdb.testtable/p=v2/pp=vv1 : 1/1, 131072/131072\n " +
232+ "hive. otherdb.testtable2 : 2/2, 537133056/537133056\n " +
233+ "hive. otherdb.testtable2/p=v3 : 2/2, 537133056/537133056\n " +
234+ "hive. otherdb.testtable3 : 1/1, 1073741824/1073741824" ;
230235
231236 private static final String EXPECTED_CACHE_STATE_AFTER_EVICTION =
232237 "\n " +
233238 "Cache state: \n " +
234- "default : 0/2, 0/2101248\n " +
235- "default.testtable : 0/2, 0/2101248\n " +
236- "otherdb : 5/7, 1074202624/1611106304\n " +
237- "otherdb.testtable : 3/4, 198656/231424\n " +
238- "otherdb.testtable/p=v1 : 2/3, 67584/100352\n " +
239- "otherdb.testtable/p=v1/pp=vv1 : 1/2, 2048/34816\n " +
240- "otherdb.testtable/p=v1/pp=vv2 : 1/1, 65536/65536\n " +
241- "otherdb.testtable/p=v2 : 1/1, 131072/131072\n " +
242- "otherdb.testtable/p=v2/pp=vv1 : 1/1, 131072/131072\n " +
243- "otherdb.testtable2 : 1/2, 262144/537133056\n " +
244- "otherdb.testtable2/p=v3 : 1/2, 262144/537133056\n " +
245- "otherdb.testtable3 : 1/1, 1073741824/1073741824" ;
239+ "hive. default : 0/2, 0/2101248\n " +
240+ "hive. default.testtable : 0/2, 0/2101248\n " +
241+ "hive. otherdb : 5/7, 1074202624/1611106304\n " +
242+ "hive. otherdb.testtable : 3/4, 198656/231424\n " +
243+ "hive. otherdb.testtable/p=v1 : 2/3, 67584/100352\n " +
244+ "hive. otherdb.testtable/p=v1/pp=vv1 : 1/2, 2048/34816\n " +
245+ "hive. otherdb.testtable/p=v1/pp=vv2 : 1/1, 65536/65536\n " +
246+ "hive. otherdb.testtable/p=v2 : 1/1, 131072/131072\n " +
247+ "hive. otherdb.testtable/p=v2/pp=vv1 : 1/1, 131072/131072\n " +
248+ "hive. otherdb.testtable2 : 1/2, 262144/537133056\n " +
249+ "hive. otherdb.testtable2/p=v3 : 1/2, 262144/537133056\n " +
250+ "hive. otherdb.testtable3 : 1/1, 1073741824/1073741824" ;
246251
247252}
0 commit comments