@@ -133,20 +133,27 @@ public void testAppendPartitionForUnPartitionedTable() {
133133 pus .add (createRandomAppend ("" ));
134134 hmsOps .commit (dbName , tbWithoutPartition , pus );
135135 Table table = hmsClient .getTable (dbName , tbWithoutPartition );
136- Assert . assertEquals (3 , Long . parseLong ( table . getParameters (). get ( "numRows" )) );
136+ assertNumRows (3 , table );
137137
138138 List <THivePartitionUpdate > pus2 = new ArrayList <>();
139139 pus2 .add (createRandomAppend ("" ));
140140 pus2 .add (createRandomAppend ("" ));
141141 pus2 .add (createRandomAppend ("" ));
142142 hmsOps .commit (dbName , tbWithoutPartition , pus2 );
143143 table = hmsClient .getTable (dbName , tbWithoutPartition );
144- Assert . assertEquals (6 , Long . parseLong ( table . getParameters (). get ( "numRows" )) );
144+ assertNumRows (6 , table );
145145 }
146146
147147 @ Test
148148 public void testOverwritePartitionForUnPartitionedTable () {
149- // TODO
149+ testAppendPartitionForUnPartitionedTable ();
150+ List <THivePartitionUpdate > pus = new ArrayList <>();
151+ pus .add (createRandomOverwrite ("" ));
152+ pus .add (createRandomOverwrite ("" ));
153+ pus .add (createRandomOverwrite ("" ));
154+ hmsOps .commit (dbName , tbWithoutPartition , pus );
155+ Table table = hmsClient .getTable (dbName , tbWithoutPartition );
156+ assertNumRows (3 , table );
150157 }
151158
152159 @ Test
@@ -161,11 +168,11 @@ public void testNewPartitionForPartitionedTable() {
161168 hmsOps .commit (dbName , tbWithPartition , pus );
162169
163170 Partition pa = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("a" ));
164- Assert . assertEquals (3 , Long . parseLong ( pa . getParameters (). get ( "numRows" )) );
171+ assertNumRows (3 , pa );
165172 Partition pb = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("b" ));
166- Assert . assertEquals (2 , Long . parseLong ( pb . getParameters (). get ( "numRows" )) );
173+ assertNumRows (2 , pb );
167174 Partition pc = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("c" ));
168- Assert . assertEquals (1 , Long . parseLong ( pc . getParameters (). get ( "numRows" )) );
175+ assertNumRows (1 , pc );
169176 }
170177
171178 @ Test
@@ -182,11 +189,28 @@ public void testAppendPartitionForPartitionedTable() {
182189 hmsOps .commit (dbName , tbWithPartition , pus );
183190
184191 Partition pa = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("a" ));
185- Assert .assertEquals (6 , Long .parseLong (pa .getParameters ().get ("numRows" )));
192+ assertNumRows (6 , pa );
193+ Partition pb = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("b" ));
194+ assertNumRows (4 , pb );
195+ Partition pc = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("c" ));
196+ assertNumRows (2 , pc );
197+ }
198+
199+ @ Test
200+ public void testOverwritePartitionForPartitionedTable () {
201+ testAppendPartitionForPartitionedTable ();
202+ List <THivePartitionUpdate > pus = new ArrayList <>();
203+ pus .add (createRandomOverwrite ("a" ));
204+ pus .add (createRandomOverwrite ("b" ));
205+ pus .add (createRandomOverwrite ("c" ));
206+ hmsOps .commit (dbName , tbWithPartition , pus );
207+
208+ Partition pa = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("a" ));
209+ assertNumRows (1 , pa );
186210 Partition pb = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("b" ));
187- Assert . assertEquals ( 4 , Long . parseLong ( pb . getParameters (). get ( "numRows" )) );
211+ assertNumRows ( 1 , pb );
188212 Partition pc = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("c" ));
189- Assert . assertEquals ( 2 , Long . parseLong ( pc . getParameters (). get ( "numRows" )) );
213+ assertNumRows ( 1 , pc );
190214 }
191215
192216 @ Test
@@ -200,7 +224,7 @@ public void testNewManyPartitionForPartitionedTable() {
200224 hmsOps .commit (dbName , tbWithPartition , pus );
201225 for (int i = 0 ; i < nums ; i ++) {
202226 Partition p = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("" + i ));
203- Assert . assertEquals (1 , Long . parseLong ( p . getParameters (). get ( "numRows" )) );
227+ assertNumRows (1 , p );
204228 }
205229
206230 try {
@@ -210,6 +234,14 @@ public void testNewManyPartitionForPartitionedTable() {
210234 }
211235 }
212236
237+ public void assertNumRows (long expected , Partition p ) {
238+ Assert .assertEquals (expected , Long .parseLong (p .getParameters ().get ("numRows" )));
239+ }
240+
241+ public void assertNumRows (long expected , Table t ) {
242+ Assert .assertEquals (expected , Long .parseLong (t .getParameters ().get ("numRows" )));
243+ }
244+
213245 public THivePartitionUpdate genOnePartitionUpdate (String partitionValue , TUpdateMode mode ) {
214246
215247 String uuid = UUID .randomUUID ().toString ();
@@ -241,4 +273,8 @@ public THivePartitionUpdate createRandomNew(String partition) {
241273 public THivePartitionUpdate createRandomAppend (String partition ) {
242274 return genOnePartitionUpdate ("c3=" + partition , TUpdateMode .APPEND );
243275 }
276+
277+ public THivePartitionUpdate createRandomOverwrite (String partition ) {
278+ return genOnePartitionUpdate ("c3=" + partition , TUpdateMode .OVERWRITE );
279+ }
244280}
0 commit comments