25
25
#include < utility>
26
26
#include < vector>
27
27
28
+ #include " base/texttable.h"
28
29
#include " cmd/sdk_iterator.h"
29
30
#include " codec/flat_array.h"
30
31
#include " codec/row_codec.h"
@@ -52,88 +53,61 @@ static void TransferString(std::vector<std::string>* vec) {
52
53
});
53
54
}
54
55
55
- __attribute__ ((unused)) static void PrintSchema (
56
- const google::protobuf::RepeatedPtrField<::openmldb::common::ColumnDesc>& column_desc_field) {
57
- std::vector<std::string> row;
58
- row.push_back (" #" );
59
- row.push_back (" name" );
60
- row.push_back (" type" );
61
- ::baidu::common::TPrinter tp (row.size (), FLAGS_max_col_display_length);
62
- tp.AddRow (row);
63
- uint32_t idx = 0 ;
64
- for (const auto & column_desc : column_desc_field) {
65
- row.clear ();
66
- row.push_back (std::to_string (idx));
67
- row.push_back (column_desc.name ());
68
- auto iter = ::openmldb::codec::DATA_TYPE_STR_MAP.find (column_desc.data_type ());
69
- if (iter != ::openmldb::codec::DATA_TYPE_STR_MAP.end ()) {
70
- row.push_back (iter->second );
71
- } else {
72
- row.push_back (" -" );
73
- }
74
- tp.AddRow (row);
75
- idx++;
76
- }
77
- tp.Print (true );
78
- }
79
-
80
56
__attribute__ ((unused)) static void PrintSchema (
81
57
const google::protobuf::RepeatedPtrField<::openmldb::common::ColumnDesc>& column_desc,
82
58
const google::protobuf::RepeatedPtrField<::openmldb::common::ColumnDesc>& added_column_desc) {
83
- std::vector<std::string> row;
84
- row.push_back (" #" );
85
- row.push_back (" name" );
86
- row.push_back (" type" );
87
- ::baidu::common::TPrinter tp (row.size (), FLAGS_max_col_display_length);
88
- tp.AddRow (row);
89
- uint32_t idx = 0 ;
90
- for (const auto & column_desc : column_desc) {
91
- row.clear ();
92
- row.push_back (std::to_string (idx));
93
- row.push_back (column_desc.name ());
94
- auto iter = ::openmldb::codec::DATA_TYPE_STR_MAP.find (column_desc.data_type ());
95
- if (iter != ::openmldb::codec::DATA_TYPE_STR_MAP.end ()) {
96
- row.push_back (iter->second );
97
- } else {
98
- row.push_back (" -" );
99
- }
100
- tp.AddRow (row);
101
- idx++;
59
+ ::hybridse::base::TextTable t (' -' , ' ' , ' ' );
60
+ t.add (" #" );
61
+ t.add (" Field" );
62
+ t.add (" Type" );
63
+ t.add (" Null" );
64
+ t.end_of_row ();
65
+
66
+ for (int i = 0 ; i < column_desc.size (); i++) {
67
+ const auto & column = column_desc.Get (i);
68
+ t.add (std::to_string (i + 1 ));
69
+ t.add (column.name ());
70
+ // kXXX discard k
71
+ t.add (DataType_Name (column.data_type ()).substr (1 ));
72
+ t.add (column.not_null () ? " NO" : " YES" );
73
+ t.end_of_row ();
102
74
}
103
- for (const auto & column_desc : added_column_desc) {
104
- row.clear ();
105
- row.push_back (std::to_string (idx));
106
- row.push_back (column_desc.name ());
107
- auto iter = ::openmldb::codec::DATA_TYPE_STR_MAP.find (column_desc.data_type ());
108
- if (iter != ::openmldb::codec::DATA_TYPE_STR_MAP.end ()) {
109
- row.push_back (iter->second );
110
- } else {
111
- row.push_back (" -" );
112
- }
113
- tp.AddRow (row);
114
- idx++;
75
+
76
+ for (int i = 0 ; i < added_column_desc.size (); i++) {
77
+ const auto & column = added_column_desc.Get (i);
78
+ t.add (std::to_string (i + 1 ));
79
+ t.add (column.name ());
80
+ // kXXX discard k
81
+ t.add (DataType_Name (column.data_type ()).substr (1 ));
82
+ t.add (column.not_null () ? " NO" : " YES" );
83
+ t.end_of_row ();
115
84
}
116
- tp.Print (true );
85
+ std::cout << t;
86
+ }
87
+
88
+ __attribute__ ((unused)) static void PrintSchema (
89
+ const google::protobuf::RepeatedPtrField<::openmldb::common::ColumnDesc>& column_desc_field) {
90
+ PrintSchema (column_desc_field, {});
117
91
}
118
92
119
93
__attribute__ ((unused)) static void PrintColumnKey (
120
94
const google::protobuf::RepeatedPtrField<::openmldb::common::ColumnKey>& column_key_field) {
121
- std::vector<std::string> row;
122
- row.push_back (" #" );
123
- row.push_back (" index_name" );
124
- row.push_back (" col_name" );
125
- row.push_back (" ts_col" );
126
- row.push_back (" ttl" );
127
- ::baidu::common::TPrinter tp (row.size (), FLAGS_max_col_display_length);
128
- tp.AddRow (row);
129
- uint32_t idx = 0 ;
130
- for (const auto & column_key : column_key_field) {
95
+ ::hybridse::base::TextTable t (' -' , ' ' , ' ' );
96
+ t.add (" #" );
97
+ t.add (" name" );
98
+ t.add (" keys" );
99
+ t.add (" ts" );
100
+ t.add (" ttl" );
101
+ t.add (" ttl_type" );
102
+ t.end_of_row ();
103
+
104
+ for (int i = 0 ; i < column_key_field.size (); i++) {
105
+ const auto & column_key = column_key_field.Get (i);
131
106
if (column_key.flag () == 1 ) {
132
107
continue ;
133
108
}
134
- row.clear ();
135
- row.push_back (std::to_string (idx));
136
- row.push_back (column_key.index_name ());
109
+ t.add (std::to_string (i + 1 ));
110
+ t.add (column_key.index_name ());
137
111
std::string key;
138
112
for (const auto & name : column_key.col_name ()) {
139
113
if (key.empty ()) {
@@ -142,26 +116,29 @@ __attribute__((unused)) static void PrintColumnKey(
142
116
key += " |" + name;
143
117
}
144
118
}
145
- if (key.empty ()) {
146
- key = column_key.index_name ();
147
- }
148
- row.push_back (key);
119
+ t.add ((key.empty () ? column_key.index_name () : key));
120
+
149
121
if (!column_key.ts_name ().empty ()) {
150
- row. push_back (column_key.ts_name ());
122
+ t. add (column_key.ts_name ());
151
123
} else {
152
- row. push_back (" -" );
124
+ t. add (" -" );
153
125
}
126
+
154
127
if (column_key.has_ttl ()) {
155
- ::openmldb::storage::TTLSt cur_ttl_st (column_key.ttl ());
156
- cur_ttl_st.abs_ttl = cur_ttl_st.abs_ttl / (60 * 1000 );
157
- row.push_back (cur_ttl_st.ToString ());
128
+ std::ostringstream oss;
129
+ auto & ttl = column_key.ttl ();
130
+ // TODO(hw): it's better to construct from common::TTLSt, but the abs will be measured in minutes. Needs fix
131
+ storage::TTLSt ttl_st (ttl.abs_ttl (), ttl.lat_ttl (), storage::TTLSt::ConvertTTLType (ttl.ttl_type ()));
132
+ t.add (ttl_st.ToString ());
133
+ t.add (TTLType_Name (ttl_st.GetProtoTTLType ()));
158
134
} else {
159
- row.push_back (" -" );
135
+ t.add (" -" ); // ttl
136
+ t.add (" -" ); // ttl_type
160
137
}
161
- tp. AddRow (row);
162
- idx++ ;
138
+
139
+ t. end_of_row () ;
163
140
}
164
- tp. Print ( true ) ;
141
+ std::cout << t ;
165
142
}
166
143
167
144
__attribute__ ((unused)) static void ShowTableRows (bool is_compress, ::openmldb::codec::SDKCodec* codec,
0 commit comments