jt2594838 commented on code in PR #745:
URL: https://github.com/apache/tsfile/pull/745#discussion_r2972614493
##########
cpp/src/reader/qds_without_timegenerator.cc:
##########
@@ -111,37 +143,111 @@ void QDSWithoutTimeGenerator::close() {
}
int QDSWithoutTimeGenerator::next(bool& has_next) {
- row_record_->reset();
- if (heap_time_.size() == 0) {
- has_next = false;
- return E_OK;
+ // For single path, apply offset/limit at row level.
+ if (is_single_path_) {
+ while (true) {
+ row_record_->reset();
+ if (heap_time_.size() == 0) {
+ has_next = false;
+ return E_OK;
+ }
+ if (remaining_limit_ == 0) {
+ has_next = false;
+ return E_OK;
+ }
+ int64_t time = heap_time_.begin()->first;
+ row_record_->set_timestamp(time);
+ row_record_->get_field(0)->set_value(INT64, &time, get_len(INT64),
+ pa_);
+
+ uint32_t len = 0;
+ uint32_t idx = heap_time_.begin()->second;
+ auto val_datatype = value_iters_[idx]->get_data_type();
+ void* val_ptr = value_iters_[idx]->read(&len);
+ row_record_->get_field(idx + 1)->set_value(val_datatype, val_ptr,
+ len, pa_);
+ value_iters_[idx]->next();
+
+ heap_time_.erase(heap_time_.begin());
+
+ if (!time_iters_[idx]->end()) {
+ int64_t timev = *(int64_t*)(time_iters_[idx]->read(&len));
+ heap_time_.insert(std::make_pair(timev, idx));
+ time_iters_[idx]->next();
+ } else {
+ get_next_tsblock(idx, false);
+ }
+
+ // Apply offset: skip this row.
+ if (remaining_offset_ > 0) {
+ remaining_offset_--;
+ continue;
+ }
Review Comment:
May skip setting row_record's field if offset > 0.
##########
cpp/src/reader/qds_without_timegenerator.cc:
##########
@@ -199,4 +305,42 @@ int QDSWithoutTimeGenerator::get_next_tsblock(uint32_t
index, bool alloc_mem) {
return ret;
}
+int QDSWithoutTimeGenerator::get_next_tsblock_with_hint(uint32_t index,
+ bool alloc_mem,
+ int64_t min_time_hint)
{
+ if (tsblocks_[index] != nullptr) {
+ delete time_iters_[index];
+ time_iters_[index] = nullptr;
+ delete value_iters_[index];
+ value_iters_[index] = nullptr;
+ tsblocks_[index]->reset();
+ }
+
+ int ret = ssi_vec_[index]->get_next(tsblocks_[index], alloc_mem, nullptr,
+ min_time_hint);
+ if (IS_SUCC(ret)) {
+ time_iters_[index] = new ColIterator(0, tsblocks_[index]);
+ uint32_t len = 0;
+ int64_t time = *(int64_t*)(time_iters_[index]->read(&len));
+ time_iters_[index]->next();
+ heap_time_.insert(std::pair<uint64_t, uint32_t>(time, index));
+ value_iters_[index] = new ColIterator(1, tsblocks_[index]);
+ } else {
+ if (time_iters_[index]) {
+ delete time_iters_[index];
+ time_iters_[index] = nullptr;
+ }
+ if (value_iters_[index]) {
+ delete value_iters_[index];
+ value_iters_[index] = nullptr;
+ }
+ if (tsblocks_[index]) {
+ ssi_vec_[index]->destroy();
+ tsblocks_[index] = nullptr;
+ }
+ ret = E_OK;
+ }
Review Comment:
The failure status cannot be sensed in this branch. Is this safe?
##########
cpp/src/reader/tsfile_reader.cc:
##########
@@ -116,6 +114,41 @@ int TsFileReader::query(const std::string& table_name,
return ret;
}
+int TsFileReader::queryByRow(std::vector<std::string>& path_list, int offset,
+ int limit, ResultSet*& result_set) {
+ int ret = E_OK;
+ std::vector<Path> path_list_vec;
+ for (const auto& path : path_list) {
+ path_list_vec.emplace_back(Path(path, true));
+ }
+ QueryExpression* query_expression =
+ QueryExpression::create(path_list_vec, nullptr);
+ ret =
+ tsfile_executor_->execute(query_expression, result_set, offset, limit);
+ return ret;
+}
+
+int TsFileReader::queryByRow(const std::string& table_name,
+ const std::vector<std::string>& column_names,
+ int offset, int limit, ResultSet*& result_set) {
+ int ret = E_OK;
+ TsFileMeta* tsfile_meta = tsfile_executor_->get_tsfile_meta();
+ if (tsfile_meta == nullptr) {
+ return E_TSFILE_WRITER_META_ERR;
Review Comment:
TSFILE_WRITER ?
##########
cpp/src/reader/tsfile_series_scan_iterator.cc:
##########
@@ -36,52 +36,103 @@ void TsFileSeriesScanIterator::destroy() {
}
}
+bool TsFileSeriesScanIterator::should_skip_chunk_by_time(
+ ChunkMeta* cm, int64_t min_time_hint) {
+ if (min_time_hint < 0 || cm->statistic_ == nullptr) {
Review Comment:
Beware of negative timestamp
##########
cpp/src/reader/table_query_executor.cc:
##########
@@ -88,6 +88,73 @@ int TableQueryExecutor::query(const std::string& table_name,
return ret;
}
+int TableQueryExecutor::query(const std::string& table_name,
+ const std::vector<std::string>& columns,
+ Filter* time_filter, Filter* id_filter,
Review Comment:
id_filter -> tag_filter
##########
cpp/src/reader/chunk_reader.cc:
##########
@@ -490,4 +504,82 @@ int
ChunkReader::decode_tv_buf_into_tsblock_by_datatype(ByteStream& time_in,
return ret;
}
+bool ChunkReader::should_skip_page_by_time(int64_t min_time_hint) {
+ if (min_time_hint < 0) {
+ return false;
+ }
Review Comment:
Though rare, the timestamp can be negative.
May use the minimum of int64 for this case.
##########
cpp/src/reader/table_query_executor.cc:
##########
@@ -88,6 +88,73 @@ int TableQueryExecutor::query(const std::string& table_name,
return ret;
}
+int TableQueryExecutor::query(const std::string& table_name,
+ const std::vector<std::string>& columns,
+ Filter* time_filter, Filter* id_filter,
+ Filter* field_filter, int offset, int limit,
+ ResultSet*& ret_qds) {
+ int ret = common::E_OK;
+ TsFileMeta* file_metadata = nullptr;
+ file_metadata = tsfile_io_reader_->get_tsfile_meta();
+ common::PageArena pa;
+ pa.init(512, common::MOD_TSFILE_READER);
+ MetaIndexNode* table_root = nullptr;
+ std::shared_ptr<TableSchema> table_schema;
+ if (RET_FAIL(
+ file_metadata->get_table_metaindex_node(table_name, table_root))) {
+ } else if (RET_FAIL(
+ file_metadata->get_table_schema(table_name, table_schema)))
{
+ }
+
+ if (IS_FAIL(ret)) {
+ ret_qds = nullptr;
+ return ret;
+ }
+ std::vector<std::string> lower_case_column_names(columns);
+ for (auto& column : lower_case_column_names) {
+ to_lowercase_inplace(column);
+ }
+ std::shared_ptr<ColumnMapping> column_mapping =
+ std::make_shared<ColumnMapping>();
+ for (size_t i = 0; i < lower_case_column_names.size(); ++i) {
+ column_mapping->add(lower_case_column_names[i], static_cast<int>(i),
+ *table_schema);
+ }
+ std::vector<common::TSDataType> data_types;
+ data_types.reserve(lower_case_column_names.size());
+ for (size_t i = 0; i < lower_case_column_names.size(); ++i) {
+ auto ind = table_schema->find_column_index(lower_case_column_names[i]);
+ if (ind < 0) {
+ delete time_filter;
Review Comment:
Why is time_filter deleted here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]