Skip to content

Commit

Permalink
start debug
Browse files Browse the repository at this point in the history
  • Loading branch information
lzyy2024 committed Jan 21, 2025
1 parent 7343f2a commit 8b37740
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions be/src/vec/functions/function_compress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include <glog/logging.h>

#include <cctype>
#include <cstddef>
#include <cstring>
Expand Down Expand Up @@ -42,6 +44,7 @@
#include "vec/functions/function.h"
#include "vec/functions/simple_function_factory.h"


namespace doris {
class FunctionContext;
} // namespace doris
Expand All @@ -58,7 +61,7 @@ class FunctionCompress : public IFunction {
size_t get_number_of_arguments() const override { return 1; }

DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
return std::make_shared<DataTypeString>();
return make_nullable(std::make_shared<DataTypeString>());
}

Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
Expand All @@ -80,20 +83,21 @@ class FunctionCompress : public IFunction {
auto null_column = ColumnUInt8::create(input_rows_count);
auto& null_map = null_column->get_data();

faststring compressed_str;
Slice data;
for (int row = 0; row < input_rows_count; row++) {
null_map[row] = false;
auto str = arg_column.get_data_at(row);
const Slice data(str.data, str.size);
faststring compressed_str;
const auto& str = arg_column.get_data_at(row);
data = Slice(str.data, str.size);

auto st = compression_codec->compress(data, &compressed_str);
if (!st.ok()) {
col_offset[row] = col_offset[row - 1];
null_map[row] = true;
continue;
}
auto* c_data = reinterpret_cast<const char*>(compressed_str.data());
col_data.push_back_raw(c_data, compressed_str.size());
col_data.resize(col_data.size() + compressed_str.size() + 1);
memcpy(col_data.data() + col_data.size(), compressed_str.data(), compressed_str.size());
col_offset[row] = col_offset[row - 1] + compressed_str.size();
}
block.replace_by_position(
Expand All @@ -112,7 +116,7 @@ class FunctionUncompress : public IFunction {
size_t get_number_of_arguments() const override { return 1; }

DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
return std::make_shared<DataTypeString>();
return make_nullable(std::make_shared<DataTypeString>());
}

Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
Expand All @@ -133,22 +137,26 @@ class FunctionUncompress : public IFunction {
auto null_column = ColumnUInt8::create(input_rows_count);
auto& null_map = null_column->get_data();

std::string uncompressed;
uncompressed.resize(32);
Slice data;
Slice uncompressed_slice;
for (int row = 0; row < input_rows_count; row++) {
null_map[row] = false;
auto str = arg_column.get_data_at(row);
const Slice data(str.data, str.size);

std::string uncompressed;
uncompressed.resize(32);
Slice uncompressed_slice(uncompressed);
const auto& str = arg_column.get_data_at(row);
data = Slice(str.data, str.size);
uncompressed_slice = Slice(uncompressed);
auto st = compression_codec->decompress(data, &uncompressed_slice);
if (!st.ok()) {
col_offset[row] = col_offset[row - 1];
null_map[row] = true;
continue;
}
auto* unc_data = reinterpret_cast<const char*>(uncompressed_slice.data);
col_data.push_back_raw(unc_data, uncompressed_slice.size);
// auto* unc_data = reinterpret_cast<const char*>(uncompressed_slice.data);
// col_data.push_back_raw(unc_data, uncompressed_slice.size);
col_data.resize(col_data.size() + uncompressed_slice.size + 1);
memcpy(col_data.data() + col_data.size(), uncompressed_slice.data,
uncompressed_slice.size);
col_offset[row] = col_offset[row - 1] + uncompressed_slice.size;
}
block.replace_by_position(
Expand Down

0 comments on commit 8b37740

Please sign in to comment.