diff --git a/docs/en/engines/table-engines/mergetree-family/invertedindexes.md b/docs/en/engines/table-engines/mergetree-family/invertedindexes.md index 693902b7d9b..9facb746eff 100644 --- a/docs/en/engines/table-engines/mergetree-family/invertedindexes.md +++ b/docs/en/engines/table-engines/mergetree-family/invertedindexes.md @@ -43,12 +43,12 @@ To use the index, no special functions or syntax are required. Typical string se examples, consider: ```sql -SELECT * from tab WHERE s == 'Hello World;; +SELECT * from tab WHERE s == 'Hello World; SELECT * from tab WHERE s IN (‘Hello’, ‘World’); SELECT * from tab WHERE s LIKE ‘%Hello%’; SELECT * from tab WHERE multiSearchAny(s, ‘Hello’, ‘World’); SELECT * from tab WHERE hasToken(s, ‘Hello’); -SELECT * from tab WHERE multiSearchAll(s, [‘Hello’, ‘World’]) +SELECT * from tab WHERE multiSearchAll(s, [‘Hello’, ‘World’]); ``` The inverted index also works on columns of type `Array(String)`, `Array(FixedString)`, `Map(String)` and `Map(String)`. diff --git a/docs/en/sql-reference/functions/date-time-functions.md b/docs/en/sql-reference/functions/date-time-functions.md index f634ca903f8..c8ac19afe01 100644 --- a/docs/en/sql-reference/functions/date-time-functions.md +++ b/docs/en/sql-reference/functions/date-time-functions.md @@ -529,6 +529,7 @@ SELECT toDate('2016-12-27') AS date, toYearWeek(date) AS yearWeek0, toYearWeek(d Returns the `unit` component of the difference between `startdate` and `enddate`. The difference is calculated using a precision of 1 second. E.g. the difference between `2021-12-29` and `2022-01-01` is 3 days for `day` unit, 0 months for `month` unit, 0 years for `year` unit. +For an alternative to `age`, see function `date\_diff`. **Syntax** @@ -600,8 +601,12 @@ Result: ## date\_diff -Returns the count of the specified `unit` boundaries crossed between the `startdate` and `enddate`. -The difference is calculated using relative units, e.g. the difference between `2021-12-29` and `2022-01-01` is 3 days for day unit (see [toRelativeDayNum](#torelativedaynum)), 1 month for month unit (see [toRelativeMonthNum](#torelativemonthnum)), 1 year for year unit (see [toRelativeYearNum](#torelativeyearnum)). +Returns the count of the specified `unit` boundaries crossed between the `startdate` and the `enddate`. +The difference is calculated using relative units, e.g. the difference between `2021-12-29` and `2022-01-01` is 3 days for unit `day` (see [toRelativeDayNum](#torelativedaynum)), 1 month for unit `month` (see [toRelativeMonthNum](#torelativemonthnum)) and 1 year for unit `year` (see [toRelativeYearNum](#torelativeyearnum)). + +If unit `week` was specified, `date\_diff` assumes that weeks start on Monday. Note that this behavior is different from that of function `toWeek()` in which weeks start by default on Sunday. + +For an alternative to `date\_diff`, see function `age`. **Syntax** diff --git a/src/Functions/transform.cpp b/src/Functions/transform.cpp index cc82b48efe4..c8a94bcffa6 100644 --- a/src/Functions/transform.cpp +++ b/src/Functions/transform.cpp @@ -859,7 +859,12 @@ private: { const auto * it = table.find(bit_cast(src[i])); if (it) - memcpy(&dst[i], &it->getMapped(), sizeof(dst[i])); /// little endian. + { + if (std::endian::native == std::endian::little) + memcpy(&dst[i], &it->getMapped(), sizeof(dst[i])); + else + memcpy(&dst[i], reinterpret_cast(&it->getMapped()) + sizeof(UInt64) - sizeof(dst[i]), sizeof(dst[i])); + } else dst[i] = dst_default; } @@ -875,7 +880,12 @@ private: { const auto * it = table.find(bit_cast(src[i])); if (it) - memcpy(&dst[i], &it->getMapped(), sizeof(dst[i])); /// little endian. + { + if (std::endian::native == std::endian::little) + memcpy(&dst[i], &it->getMapped(), sizeof(dst[i])); + else + memcpy(&dst[i], reinterpret_cast(&it->getMapped()) + sizeof(UInt64) - sizeof(dst[i]), sizeof(dst[i])); + } else if constexpr (is_decimal) dst[i] = static_cast(dst_default[i]); else @@ -893,7 +903,12 @@ private: { const auto * it = table.find(bit_cast(src[i])); if (it) - memcpy(&dst[i], &it->getMapped(), sizeof(dst[i])); + { + if (std::endian::native == std::endian::little) + memcpy(&dst[i], &it->getMapped(), sizeof(dst[i])); + else + memcpy(&dst[i], reinterpret_cast(&it->getMapped()) + sizeof(UInt64) - sizeof(dst[i]), sizeof(dst[i])); + } else dst[i] = src[i]; } @@ -964,7 +979,12 @@ private: current_src_offset = src_offsets[i]; const auto * it = table.find(ref); if (it) - memcpy(&dst[i], &it->getMapped(), sizeof(dst[i])); + { + if (std::endian::native == std::endian::little) + memcpy(&dst[i], &it->getMapped(), sizeof(dst[i])); + else + memcpy(&dst[i], reinterpret_cast(&it->getMapped()) + sizeof(UInt64) - sizeof(dst[i]), sizeof(dst[i])); + } else dst[i] = dst_default; } @@ -985,7 +1005,12 @@ private: current_src_offset = src_offsets[i]; const auto * it = table.find(ref); if (it) - memcpy(&dst[i], &it->getMapped(), sizeof(dst[i])); + { + if (std::endian::native == std::endian::little) + memcpy(&dst[i], &it->getMapped(), sizeof(dst[i])); + else + memcpy(&dst[i], reinterpret_cast(&it->getMapped()) + sizeof(UInt64) - sizeof(dst[i]), sizeof(dst[i])); + } else if constexpr (is_decimal) dst[i] = static_cast(dst_default[i]); else