@@ -134,20 +134,27 @@ public void testAppendPartitionForUnPartitionedTable() {
134134 pus .add (createRandomAppend ("" ));
135135 hmsOps .commit (dbName , tbWithoutPartition , pus );
136136 Table table = hmsClient .getTable (dbName , tbWithoutPartition );
137- Assert . assertEquals (3 , Long . parseLong ( table . getParameters (). get ( "numRows" )) );
137+ assertNumRows (3 , table );
138138
139139 List <THivePartitionUpdate > pus2 = new ArrayList <>();
140140 pus2 .add (createRandomAppend ("" ));
141141 pus2 .add (createRandomAppend ("" ));
142142 pus2 .add (createRandomAppend ("" ));
143143 hmsOps .commit (dbName , tbWithoutPartition , pus2 );
144144 table = hmsClient .getTable (dbName , tbWithoutPartition );
145- Assert . assertEquals (6 , Long . parseLong ( table . getParameters (). get ( "numRows" )) );
145+ assertNumRows (6 , table );
146146 }
147147
148148 @ Test
149149 public void testOverwritePartitionForUnPartitionedTable () {
150- // TODO
150+ testAppendPartitionForUnPartitionedTable ();
151+ List <THivePartitionUpdate > pus = new ArrayList <>();
152+ pus .add (createRandomOverwrite ("" ));
153+ pus .add (createRandomOverwrite ("" ));
154+ pus .add (createRandomOverwrite ("" ));
155+ hmsOps .commit (dbName , tbWithoutPartition , pus );
156+ Table table = hmsClient .getTable (dbName , tbWithoutPartition );
157+ assertNumRows (3 , table );
151158 }
152159
153160 @ Test
@@ -162,11 +169,11 @@ public void testNewPartitionForPartitionedTable() {
162169 hmsOps .commit (dbName , tbWithPartition , pus );
163170
164171 Partition pa = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("a" ));
165- Assert . assertEquals (3 , Long . parseLong ( pa . getParameters (). get ( "numRows" )) );
172+ assertNumRows (3 , pa );
166173 Partition pb = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("b" ));
167- Assert . assertEquals (2 , Long . parseLong ( pb . getParameters (). get ( "numRows" )) );
174+ assertNumRows (2 , pb );
168175 Partition pc = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("c" ));
169- Assert . assertEquals (1 , Long . parseLong ( pc . getParameters (). get ( "numRows" )) );
176+ assertNumRows (1 , pc );
170177 }
171178
172179 @ Test
@@ -183,11 +190,28 @@ public void testAppendPartitionForPartitionedTable() {
183190 hmsOps .commit (dbName , tbWithPartition , pus );
184191
185192 Partition pa = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("a" ));
186- Assert .assertEquals (6 , Long .parseLong (pa .getParameters ().get ("numRows" )));
193+ assertNumRows (6 , pa );
194+ Partition pb = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("b" ));
195+ assertNumRows (4 , pb );
196+ Partition pc = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("c" ));
197+ assertNumRows (2 , pc );
198+ }
199+
200+ @ Test
201+ public void testOverwritePartitionForPartitionedTable () {
202+ testAppendPartitionForPartitionedTable ();
203+ List <THivePartitionUpdate > pus = new ArrayList <>();
204+ pus .add (createRandomOverwrite ("a" ));
205+ pus .add (createRandomOverwrite ("b" ));
206+ pus .add (createRandomOverwrite ("c" ));
207+ hmsOps .commit (dbName , tbWithPartition , pus );
208+
209+ Partition pa = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("a" ));
210+ assertNumRows (1 , pa );
187211 Partition pb = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("b" ));
188- Assert . assertEquals ( 4 , Long . parseLong ( pb . getParameters (). get ( "numRows" )) );
212+ assertNumRows ( 1 , pb );
189213 Partition pc = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("c" ));
190- Assert . assertEquals ( 2 , Long . parseLong ( pc . getParameters (). get ( "numRows" )) );
214+ assertNumRows ( 1 , pc );
191215 }
192216
193217 @ Test
@@ -201,7 +225,7 @@ public void testNewManyPartitionForPartitionedTable() {
201225 hmsOps .commit (dbName , tbWithPartition , pus );
202226 for (int i = 0 ; i < nums ; i ++) {
203227 Partition p = hmsClient .getPartition (dbName , tbWithPartition , Lists .newArrayList ("" + i ));
204- Assert . assertEquals (1 , Long . parseLong ( p . getParameters (). get ( "numRows" )) );
228+ assertNumRows (1 , p );
205229 }
206230
207231 try {
@@ -211,6 +235,14 @@ public void testNewManyPartitionForPartitionedTable() {
211235 }
212236 }
213237
238+ public void assertNumRows (long expected , Partition p ) {
239+ Assert .assertEquals (expected , Long .parseLong (p .getParameters ().get ("numRows" )));
240+ }
241+
242+ public void assertNumRows (long expected , Table t ) {
243+ Assert .assertEquals (expected , Long .parseLong (t .getParameters ().get ("numRows" )));
244+ }
245+
214246 public THivePartitionUpdate genOnePartitionUpdate (String partitionValue , TUpdateMode mode ) {
215247
216248 String uuid = UUID .randomUUID ().toString ();
@@ -242,4 +274,8 @@ public THivePartitionUpdate createRandomNew(String partition) {
242274 public THivePartitionUpdate createRandomAppend (String partition ) {
243275 return genOnePartitionUpdate ("c3=" + partition , TUpdateMode .APPEND );
244276 }
277+
278+ public THivePartitionUpdate createRandomOverwrite (String partition ) {
279+ return genOnePartitionUpdate ("c3=" + partition , TUpdateMode .OVERWRITE );
280+ }
245281}
0 commit comments