Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions be/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ set_target_properties(protoc PROPERTIES IMPORTED_LOCATION ${THIRDPARTY_DIR}/lib/
add_library(gtest STATIC IMPORTED)
set_target_properties(gtest PROPERTIES IMPORTED_LOCATION ${THIRDPARTY_DIR}/lib/libgtest.a)

add_library(benchmark STATIC IMPORTED)
set_target_properties(benchmark PROPERTIES IMPORTED_LOCATION ${THIRDPARTY_DIR}/lib/libbenchmark.a)

add_library(gmock STATIC IMPORTED)
set_target_properties(gmock PROPERTIES IMPORTED_LOCATION ${THIRDPARTY_DIR}/lib/libgmock.a)

Expand Down Expand Up @@ -500,6 +503,7 @@ set(COMMON_THIRDPARTY
gflags
brpc
protobuf
benchmark
openssl
crypto
leveldb
Expand Down Expand Up @@ -694,6 +698,7 @@ if (${MAKE_TEST} STREQUAL "ON")
add_subdirectory(${TEST_DIR}/util)
add_subdirectory(${TEST_DIR}/plugin)
add_subdirectory(${TEST_DIR}/plugin/example)
add_subdirectory(${TEST_DIR}/tools)
endif ()

# Install be
Expand Down
61 changes: 57 additions & 4 deletions be/test/olap/tablet_schema_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,19 @@ TabletColumn create_varchar_key(int32_t id, bool is_nullable = true) {
column._type = OLAP_FIELD_TYPE_VARCHAR;
column._is_key = true;
column._is_nullable = is_nullable;
column._length = 8;
column._length = 65533;
column._index_length = 4;
return column;
}

TabletColumn create_string_key(int32_t id, bool is_nullable = true) {
TabletColumn column;
column._unique_id = id;
column._col_name = std::to_string(id);
column._type = OLAP_FIELD_TYPE_STRING;
column._is_key = true;
column._is_nullable = is_nullable;
column._length = 2147483643;
column._index_length = 4;
return column;
}
Expand All @@ -98,10 +110,10 @@ TabletColumn create_with_default_value(std::string default_value) {
}

void set_column_value_by_type(FieldType fieldType, int src, char* target, MemPool* pool,
size_t _length = 0) {
size_t _length = 8) {
if (fieldType == OLAP_FIELD_TYPE_CHAR) {
std::string s = std::to_string(src);
char* src_value = &s[0];
const char* src_value = s.c_str();
int src_len = s.size();

auto* dest_slice = (Slice*)target;
Expand All @@ -111,7 +123,16 @@ void set_column_value_by_type(FieldType fieldType, int src, char* target, MemPoo
memset(dest_slice->data + src_len, 0, dest_slice->size - src_len);
} else if (fieldType == OLAP_FIELD_TYPE_VARCHAR) {
std::string s = std::to_string(src);
char* src_value = &s[0];
const char* src_value = s.c_str();
int src_len = s.size();

auto* dest_slice = (Slice*)target;
dest_slice->size = src_len;
dest_slice->data = (char*)pool->allocate(src_len);
memcpy(dest_slice->data, src_value, src_len);
} else if (fieldType == OLAP_FIELD_TYPE_STRING) {
std::string s = std::to_string(src);
const char* src_value = s.c_str();
int src_len = s.size();

auto* dest_slice = (Slice*)target;
Expand All @@ -123,4 +144,36 @@ void set_column_value_by_type(FieldType fieldType, int src, char* target, MemPoo
}
}

void set_column_value_by_type(FieldType fieldType, const std::string& src, char* target,
MemPool* pool, size_t _length = 8) {
if (fieldType == OLAP_FIELD_TYPE_CHAR) {
const char* src_value = src.c_str();
int src_len = src.size();

auto* dest_slice = (Slice*)target;
dest_slice->size = _length;
dest_slice->data = (char*)pool->allocate(dest_slice->size);
memcpy(dest_slice->data, src_value, src_len);
memset(dest_slice->data + src_len, 0, dest_slice->size - src_len);
} else if (fieldType == OLAP_FIELD_TYPE_VARCHAR) {
const char* src_value = src.c_str();
int src_len = src.size();

auto* dest_slice = (Slice*)target;
dest_slice->size = src_len;
dest_slice->data = (char*)pool->allocate(src_len);
memcpy(dest_slice->data, src_value, src_len);
} else if (fieldType == OLAP_FIELD_TYPE_STRING) {
const char* src_value = src.c_str();
int src_len = src.size();

auto* dest_slice = (Slice*)target;
dest_slice->size = src_len;
dest_slice->data = (char*)pool->allocate(src_len);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add String type

memcpy(dest_slice->data, src_value, src_len);
} else {
*(int*)target = std::stoi(src);
}
}

} // namespace doris
35 changes: 34 additions & 1 deletion be/test/test_util/test_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <common/configbase.h>
#include <libgen.h>
#include <linux/limits.h>
#include <cstdlib>
#include <strings.h>
#include <sys/types.h>
#include <unistd.h>
Expand Down Expand Up @@ -74,4 +73,38 @@ void InitConfig() {
}
}

bool equal_ignore_case(std::string lhs, std::string rhs) {
std::transform(lhs.begin(), lhs.end(), lhs.begin(), ::tolower);
std::transform(rhs.begin(), rhs.end(), rhs.begin(), ::tolower);
return lhs == rhs;
}

std::mt19937_64 rng_64(std::chrono::steady_clock::now().time_since_epoch().count());

int rand_rng_int(int l, int r) {
std::uniform_int_distribution<int> u(l, r);
return u(rng_64);
}
char rand_rng_char() {
return (rand_rng_int(0, 1) ? 'a' : 'A') + rand_rng_int(0, 25);
}
std::string rand_rng_string(size_t length) {
string s;
while (length--) {
s += rand_rng_char();
}
return s;
}
std::string rand_rng_by_type(FieldType fieldType) {
if (fieldType == OLAP_FIELD_TYPE_CHAR) {
return rand_rng_string(rand_rng_int(1, 8));
} else if (fieldType == OLAP_FIELD_TYPE_VARCHAR) {
return rand_rng_string(rand_rng_int(1, 128));
} else if (fieldType == OLAP_FIELD_TYPE_STRING) {
return rand_rng_string(rand_rng_int(1, 100000));
} else {
return std::to_string(rand_rng_int(1, 1000000));
}
}

} // namespace doris
12 changes: 12 additions & 0 deletions be/test/test_util/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@

#pragma once

#include <chrono>
#include <cstdlib>
#include <random>
#include <string>

#include "olap/tablet_schema.h"

namespace doris {

#define LOOP_LESS_OR_MORE(less, more) (AllowSlowTests() ? more : less)
Expand All @@ -36,4 +41,11 @@ std::string GetCurrentRunningDir();
// Initialize config file.
void InitConfig();

bool equal_ignore_case(std::string lhs, std::string rhs);

int rand_rng_int(int l, int r);
char rand_rng_char();
std::string rand_rng_string(size_t length = 8);
std::string rand_rng_by_type(FieldType fieldType);

} // namespace doris
23 changes: 23 additions & 0 deletions be/test/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# where to put generated libraries
set(EXECUTABLE_OUTPUT_PATH "${BUILD_DIR}/test/env")
# where to put generated binaries
set(EXECUTABLE_OUTPUT_PATH "${BUILD_DIR}/test/tools")

ADD_BE_TEST(benchmark_tool)
Loading