@@ -68,6 +68,8 @@ import chunk_index_entry;
68
68
import background_process;
69
69
import compaction_process;
70
70
import bg_task;
71
+ import buffer_obj;
72
+ import file_worker_type;
71
73
72
74
namespace infinity {
73
75
@@ -377,6 +379,21 @@ void PhysicalShow::Init() {
377
379
output_types_->emplace_back (varchar_type);
378
380
break ;
379
381
}
382
+ case ShowType::kShowBuffer : {
383
+ output_names_->reserve (5 );
384
+ output_types_->reserve (5 );
385
+ output_names_->emplace_back (" path" );
386
+ output_names_->emplace_back (" status" );
387
+ output_names_->emplace_back (" size" );
388
+ output_names_->emplace_back (" buffered_type" );
389
+ output_names_->emplace_back (" type" );
390
+ output_types_->emplace_back (varchar_type);
391
+ output_types_->emplace_back (varchar_type);
392
+ output_types_->emplace_back (bigint_type);
393
+ output_types_->emplace_back (varchar_type);
394
+ output_types_->emplace_back (varchar_type);
395
+ break ;
396
+ }
380
397
default : {
381
398
Status status = Status::NotSupport (" Not implemented show type" );
382
399
LOG_ERROR (status.message ());
@@ -478,6 +495,10 @@ bool PhysicalShow::Execute(QueryContext *query_context, OperatorState *operator_
478
495
ExecuteShowConfig (query_context, show_operator_state);
479
496
break ;
480
497
}
498
+ case ShowType::kShowBuffer : {
499
+ ExecuteShowBuffer (query_context, show_operator_state);
500
+ break ;
501
+ }
481
502
default : {
482
503
String error_message = " Invalid chunk scan type" ;
483
504
LOG_CRITICAL (error_message);
@@ -2789,7 +2810,7 @@ void PhysicalShow::ExecuteShowIndexes(QueryContext *query_context, ShowOperatorS
2789
2810
{
2790
2811
auto map_guard = table_entry->IndexMetaMap ();
2791
2812
for (const auto &[index_name, index_meta] : *map_guard) {
2792
- if (! output_block_ptr) {
2813
+ if (output_block_ptr. get () == nullptr ) {
2793
2814
output_block_ptr = DataBlock::MakeUniquePtr ();
2794
2815
output_block_ptr->Init (column_types);
2795
2816
}
@@ -4080,4 +4101,87 @@ void PhysicalShow::ExecuteShowConfig(QueryContext *query_context, ShowOperatorSt
4080
4101
operator_state->output_ .emplace_back (std::move (output_block_ptr));
4081
4102
}
4082
4103
4104
+ void PhysicalShow::ExecuteShowBuffer (QueryContext *query_context, ShowOperatorState *operator_state) {
4105
+ auto varchar_type = MakeShared<DataType>(LogicalType::kVarchar );
4106
+ auto bigint_type = MakeShared<DataType>(LogicalType::kBigInt );
4107
+
4108
+ Vector<SharedPtr<ColumnDef>> column_defs = {
4109
+ MakeShared<ColumnDef>(0 , varchar_type, " path" , std::set<ConstraintType>()),
4110
+ MakeShared<ColumnDef>(1 , varchar_type, " status" , std::set<ConstraintType>()),
4111
+ MakeShared<ColumnDef>(2 , bigint_type, " size" , std::set<ConstraintType>()),
4112
+ MakeShared<ColumnDef>(3 , varchar_type, " buffered_type" , std::set<ConstraintType>()),
4113
+ MakeShared<ColumnDef>(4 , varchar_type, " type" , std::set<ConstraintType>()),
4114
+ };
4115
+
4116
+ SharedPtr<TableDef> table_def = TableDef::Make (MakeShared<String>(" default_db" ), MakeShared<String>(" show_buffer" ), column_defs);
4117
+
4118
+ // create data block for output state
4119
+ Vector<SharedPtr<DataType>> column_types{
4120
+ varchar_type,
4121
+ varchar_type,
4122
+ bigint_type,
4123
+ varchar_type,
4124
+ varchar_type,
4125
+ };
4126
+
4127
+ UniquePtr<DataBlock> output_block_ptr = DataBlock::MakeUniquePtr ();
4128
+ output_block_ptr->Init (column_types);
4129
+ SizeT row_count = 0 ;
4130
+
4131
+ BufferManager *buffer_manager = query_context->storage ()->buffer_manager ();
4132
+ Vector<BufferObjectInfo> buffer_object_info_array = buffer_manager->GetBufferObjectsInfo ();
4133
+ for (const auto & buffer_object_info: buffer_object_info_array) {
4134
+
4135
+ if (output_block_ptr.get () == nullptr ) {
4136
+ output_block_ptr = DataBlock::MakeUniquePtr ();
4137
+ output_block_ptr->Init (column_types);
4138
+ }
4139
+
4140
+ {
4141
+ // path
4142
+ Value value = Value::MakeVarchar (buffer_object_info.object_path_ );
4143
+ ValueExpression value_expr (value);
4144
+ value_expr.AppendToChunk (output_block_ptr->column_vectors [0 ]);
4145
+ }
4146
+ {
4147
+ // status
4148
+ Value value = Value::MakeVarchar (BufferStatusToString (buffer_object_info.buffered_status_ ));
4149
+ ValueExpression value_expr (value);
4150
+ value_expr.AppendToChunk (output_block_ptr->column_vectors [1 ]);
4151
+ }
4152
+ {
4153
+ // size
4154
+ i64 buffer_object_size = static_cast <i64>(buffer_object_info.object_size_ );
4155
+ Value value = Value::MakeBigInt (buffer_object_size);
4156
+ ValueExpression value_expr (value);
4157
+ value_expr.AppendToChunk (output_block_ptr->column_vectors [2 ]);
4158
+ }
4159
+ {
4160
+ // buffered type
4161
+ Value value = Value::MakeVarchar (BufferTypeToString (buffer_object_info.buffered_type_ ));
4162
+ ValueExpression value_expr (value);
4163
+ value_expr.AppendToChunk (output_block_ptr->column_vectors [3 ]);
4164
+ }
4165
+ {
4166
+ // type
4167
+ Value value = Value::MakeVarchar (FileWorkerType2Str (buffer_object_info.file_type_ ));
4168
+ ValueExpression value_expr (value);
4169
+ value_expr.AppendToChunk (output_block_ptr->column_vectors [4 ]);
4170
+ }
4171
+
4172
+ ++ row_count;
4173
+ if (row_count == output_block_ptr->capacity ()) {
4174
+ output_block_ptr->Finalize ();
4175
+ operator_state->output_ .emplace_back (std::move (output_block_ptr));
4176
+ output_block_ptr = nullptr ;
4177
+ row_count = 0 ;
4178
+ }
4179
+
4180
+ }
4181
+
4182
+ output_block_ptr->Finalize ();
4183
+ operator_state->output_ .emplace_back (std::move (output_block_ptr));
4184
+ return ;
4185
+ }
4186
+
4083
4187
} // namespace infinity
0 commit comments