|
17 | 17 | */ |
18 | 18 | package org.apache.hadoop.hive.ql.txn.compactor; |
19 | 19 |
|
| 20 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 21 | +import com.fasterxml.jackson.databind.JsonNode; |
| 22 | +import com.fasterxml.jackson.databind.ObjectMapper; |
20 | 23 | import org.apache.hadoop.fs.FileUtil; |
21 | 24 | import org.apache.hadoop.hive.cli.CliSessionState; |
22 | 25 | import org.apache.hadoop.hive.conf.Constants; |
|
48 | 51 |
|
49 | 52 | import java.io.File; |
50 | 53 | import java.io.IOException; |
| 54 | +import java.util.ArrayList; |
| 55 | +import java.util.Arrays; |
51 | 56 | import java.util.Collections; |
52 | 57 | import java.util.List; |
53 | 58 | import java.util.Map; |
|
58 | 63 |
|
59 | 64 | import static org.apache.hadoop.hive.conf.HiveConf.ConfVars.HIVE_COMPACTOR_CLEANER_RETENTION_TIME; |
60 | 65 | import static org.apache.hadoop.hive.ql.txn.compactor.CompactorTestUtil.executeStatementOnDriverAndReturnResults; |
61 | | -import static org.apache.hadoop.hive.ql.txn.compactor.TestCompactor.executeStatementOnDriver; |
62 | 66 | import static org.apache.hadoop.hive.ql.txn.compactor.TestCompactor.dropTables; |
| 67 | +import static org.apache.hadoop.hive.ql.txn.compactor.TestCompactor.executeStatementOnDriver; |
63 | 68 |
|
64 | 69 | /** |
65 | 70 | * Superclass for Test[Crud|Mm]CompactorOnTez, for setup and helper classes. |
@@ -184,7 +189,8 @@ protected void verifySuccessfulCompaction(int expectedSuccessfulCompactions) thr |
184 | 189 | protected HiveHookEvents.HiveHookEventProto getRelatedTezEvent(String dbTableName) throws Exception { |
185 | 190 | int retryCount = 3; |
186 | 191 | while (retryCount-- > 0) { |
187 | | - List<ProtoMessageReader<HiveHookEvents.HiveHookEventProto>> readers = TestHiveProtoLoggingHook.getTestReader(conf, tmpFolder); |
| 192 | + List<ProtoMessageReader<HiveHookEvents.HiveHookEventProto>> |
| 193 | + readers = TestHiveProtoLoggingHook.getTestReader(conf, tmpFolder); |
188 | 194 | for (ProtoMessageReader<HiveHookEvents.HiveHookEventProto> reader : readers) { |
189 | 195 | do { |
190 | 196 | HiveHookEvents.HiveHookEventProto event; |
@@ -541,9 +547,40 @@ protected List<String> getBucketData(String tblName, String bucketId) throws Exc |
541 | 547 | "select ROW__ID, * from " + tblName + " where ROW__ID.bucketid = " + bucketId + " order by ROW__ID, a, b", driver); |
542 | 548 | } |
543 | 549 |
|
| 550 | + protected List<RowInfo> getStructuredBucketData(String tblName, String bucketId) throws Exception { |
| 551 | + List<String> getBucketData = getBucketData(tblName, bucketId); |
| 552 | + |
| 553 | + List<RowInfo> result = new ArrayList<>(getBucketData.size()); |
| 554 | + for (String row : getBucketData) { |
| 555 | + result.add(RowInfo.fromRawString(row)); |
| 556 | + } |
| 557 | + |
| 558 | + return result; |
| 559 | + } |
| 560 | + |
544 | 561 | protected void dropTable(String tblName) throws Exception { |
545 | 562 | executeStatementOnDriver("drop table " + tblName, driver); |
546 | 563 | } |
| 564 | + |
| 565 | + protected record RowInfo(long writeId, long bucketId, long rowId, TestRebalanceCompactor.RowData rowData) { |
| 566 | + private static final ObjectMapper MAPPER = new ObjectMapper(); |
| 567 | + |
| 568 | + static RowInfo fromRawString(String row) throws JsonProcessingException { |
| 569 | + // Example row data to parse: "{\"writeid\":7,\"bucketid\":537001984,\"rowid\":10}\t5\t4", |
| 570 | + |
| 571 | + String[] parts = row.split("\t"); |
| 572 | + |
| 573 | + JsonNode json = MAPPER.readTree(parts[0]); |
| 574 | + |
| 575 | + return new RowInfo( |
| 576 | + json.get("writeid").asLong(), |
| 577 | + json.get("bucketid").asLong(), |
| 578 | + json.get("rowid").asLong(), |
| 579 | + |
| 580 | + new TestRebalanceCompactor.RowData(Arrays.copyOfRange(parts, 1, parts.length)) |
| 581 | + ); |
| 582 | + } |
| 583 | + } |
547 | 584 | } |
548 | 585 |
|
549 | 586 | protected Initiator createInitiator() throws Exception { |
|
0 commit comments