17
17
18
18
package com .alipay .oceanbase .hbase .util ;
19
19
20
- import com .fasterxml .jackson .core .type .TypeReference ;
21
20
import com .fasterxml .jackson .databind .JsonNode ;
22
21
import com .fasterxml .jackson .databind .ObjectMapper ;
23
22
import com .alipay .oceanbase .hbase .execute .AbstractObTableMetaExecutor ;
32
31
33
32
import java .io .IOException ;
34
33
import java .util .HashMap ;
34
+ import java .util .Iterator ;
35
35
import java .util .Map ;
36
36
import java .util .Optional ;
37
+ import java .util .stream .Stream ;
37
38
38
39
public class OHTableDescriptorExecutor extends AbstractObTableMetaExecutor <HTableDescriptor > {
39
40
private final String tableName ;
@@ -56,9 +57,11 @@ public HTableDescriptor parse(ObTableMetaResponse response) throws IOException {
56
57
"cfDescs": {
57
58
"cf1": {
58
59
"TTL":604800
60
+ "maxVersions": 3
59
61
},
60
62
"cf2": {
61
63
"TTL":259200
64
+ "maxVersions": 2
62
65
}
63
66
},
64
67
"tbDesc": {
@@ -70,14 +73,17 @@ public HTableDescriptor parse(ObTableMetaResponse response) throws IOException {
70
73
HTableDescriptor tableDescriptor = new HTableDescriptor (TableName .valueOf (tableName ));
71
74
JsonNode cfDescsNode = Optional .<JsonNode >ofNullable (jsonMap .get ("cfDescs" ))
72
75
.orElseThrow (() -> new IOException ("cfDesc is null" ));
73
- Map <String , Object > cfDescsMap = objectMapper . convertValue ( cfDescsNode , new TypeReference < Map < String , Object >>(){} );
74
- for ( Map . Entry < String , Object > entry : cfDescsMap . entrySet ()) {
76
+ Stream < Map . Entry <String , JsonNode >> stream = cfDescsNode . propertyStream ( );
77
+ stream . forEach ( entry -> {
75
78
String cfName = entry .getKey ();
76
- JsonNode attributes = (JsonNode ) entry .getValue ();
79
+ JsonNode value = entry .getValue ();
80
+ int ttl = value .path ("TTL" ).asInt ();
81
+ int maxVersions = value .path ("maxVersions" ).asInt ();
77
82
HColumnDescriptor cf = new HColumnDescriptor (cfName );
78
- cf .setTimeToLive (attributes .get ("TTL" ).asInt ());
83
+ cf .setTimeToLive (ttl );
84
+ cf .setMaxVersions (maxVersions );
79
85
tableDescriptor .addFamily (cf );
80
- }
86
+ });
81
87
return tableDescriptor ;
82
88
} catch (IllegalArgumentException e ) {
83
89
throw new IOException ("Failed to parse response" , e );
0 commit comments