[bugfix](array-type) ColumnDate lost is_date_type after cloned (#13420)

Problem:
IColumn::is_date property will lost after ColumnDate::clone called.

Fix:
After ColumnDate created, also set IColumn::is_date.

Co-authored-by: cambyzju <zhuxiaoli01@baidu.com>
This commit is contained in:
camby
2022-10-19 21:29:36 +08:00
committed by GitHub
parent c4b5ba2a4f
commit 9ac4cfc9bb
4 changed files with 43 additions and 10 deletions

View File

@ -614,6 +614,15 @@ public:
virtual void set_datetime_type() { is_date_time = true; }
virtual void set_decimalv2_type() { is_decimalv2 = true; }
void copy_date_types(const IColumn& col) {
if (col.is_date_type()) {
set_date_type();
}
if (col.is_datetime_type()) {
set_datetime_type();
}
}
// todo(wb): a temporary implemention, need re-abstract here
bool is_date = false;
bool is_date_time = false;

View File

@ -313,6 +313,9 @@ const char* ColumnVector<T>::get_family_name() const {
template <typename T>
MutableColumnPtr ColumnVector<T>::clone_resized(size_t size) const {
auto res = this->create();
if constexpr (std::is_same_v<T, vectorized::Int64>) {
res->copy_date_types(*this);
}
if (size > 0) {
auto& new_col = assert_cast<Self&>(*res);
@ -386,6 +389,9 @@ ColumnPtr ColumnVector<T>::filter(const IColumn::Filter& filt, ssize_t result_si
}
auto res = this->create();
if constexpr (std::is_same_v<T, vectorized::Int64>) {
res->copy_date_types(*this);
}
Container& res_data = res->get_data();
res_data.reserve(result_size_hint > 0 ? result_size_hint : size);
@ -445,6 +451,9 @@ ColumnPtr ColumnVector<T>::permute(const IColumn::Permutation& perm, size_t limi
}
auto res = this->create(limit);
if constexpr (std::is_same_v<T, vectorized::Int64>) {
res->copy_date_types(*this);
}
typename Self::Container& res_data = res->get_data();
for (size_t i = 0; i < limit; ++i) res_data[i] = data[perm[i]];
@ -458,9 +467,12 @@ ColumnPtr ColumnVector<T>::replicate(const IColumn::Offsets& offsets) const {
LOG(FATAL) << "Size of offsets doesn't match size of column.";
}
if (0 == size) return this->create();
auto res = this->create();
if constexpr (std::is_same_v<T, vectorized::Int64>) {
res->copy_date_types(*this);
}
if (0 == size) return res;
typename Self::Container& res_data = res->get_data();
res_data.reserve(offsets.back());

View File

@ -134,3 +134,12 @@
6 \N
7 \N
-- !select --
1 \N
2 \N
3 \N
4 \N
5 \N
6 \N
7 \N

View File

@ -29,7 +29,9 @@ suite("test_array_functions") {
`k2` ARRAY<int(11)> NOT NULL COMMENT "",
`k3` ARRAY<VARCHAR(20)> NULL COMMENT "",
`k4` ARRAY<int(11)> NULL COMMENT "",
`k5` ARRAY<CHAR(5)> NULL COMMENT ""
`k5` ARRAY<CHAR(5)> NULL COMMENT "",
`k6` ARRAY<date> NULL COMMENT "",
`k7` ARRAY<datetime> NULL COMMENT ""
) ENGINE=OLAP
DUPLICATE KEY(`k1`)
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
@ -38,13 +40,13 @@ suite("test_array_functions") {
"storage_format" = "V2"
)
"""
sql """ INSERT INTO ${tableName} VALUES(1,[1,2,3],["a","b",""],[1,2],["hi"]) """
sql """ INSERT INTO ${tableName} VALUES(2,[4],NULL,[5],["hi2"]) """
sql """ INSERT INTO ${tableName} VALUES(3,[],[],NULL,["hi3"]) """
sql """ INSERT INTO ${tableName} VALUES(4,[1,2,3,4,5,4,3,2,1],[],[],NULL) """
sql """ INSERT INTO ${tableName} VALUES(5,[],["a","b","c","d","c","b","a"],NULL,NULL) """
sql """ INSERT INTO ${tableName} VALUES(6,[1,2,3,4,5,4,3,2,1],["a","b","c","d","c","b","a"],NULL,NULL) """
sql """ INSERT INTO ${tableName} VALUES(7,[8,9,NULL,10,NULL],["f",NULL,"g",NULL,"h"],NULL,NULL) """
sql """ INSERT INTO ${tableName} VALUES(1,[1,2,3],["a","b",""],[1,2],["hi"],["2015-03-13"],["2015-03-13 12:36:38"]) """
sql """ INSERT INTO ${tableName} VALUES(2,[4],NULL,[5],["hi2"],NULL,NULL) """
sql """ INSERT INTO ${tableName} VALUES(3,[],[],NULL,["hi3"],NULL,NULL) """
sql """ INSERT INTO ${tableName} VALUES(4,[1,2,3,4,5,4,3,2,1],[],[],NULL,NULL,NULL) """
sql """ INSERT INTO ${tableName} VALUES(5,[],["a","b","c","d","c","b","a"],NULL,NULL,NULL,NULL) """
sql """ INSERT INTO ${tableName} VALUES(6,[1,2,3,4,5,4,3,2,1],["a","b","c","d","c","b","a"],NULL,NULL,NULL,NULL) """
sql """ INSERT INTO ${tableName} VALUES(7,[8,9,NULL,10,NULL],["f",NULL,"g",NULL,"h"],NULL,NULL,NULL,NULL) """
qt_select "SELECT k1, size(k2), size(k3) FROM ${tableName} ORDER BY k1"
qt_select "SELECT k1, cardinality(k2), cardinality(k3) FROM ${tableName} ORDER BY k1"
@ -61,4 +63,5 @@ suite("test_array_functions") {
qt_select "SELECT k1, array_join(k2, '_', 'null'), array_join(k3, '-', 'null') FROM ${tableName} ORDER BY k1"
qt_select "SELECT k1, array_contains(k5, 'hi') FROM ${tableName} ORDER BY k1"
qt_select "SELECT k1, array_contains(k5, 'hi222') FROM ${tableName} ORDER BY k1"
qt_select "SELECT k1, array_contains(k6, null) from ${tableName} ORDER BY k1"
}