Compare commits

..

No commits in common. "5c1cfeec4c2f7a0a2fa68d6a41a9f607a26be378" and "e7054029c4e2721855b599d874c74d68ae2cd45a" have entirely different histories.

8 changed files with 34 additions and 63 deletions

View File

@ -8,7 +8,4 @@ set (CMAKE_CXX_COMPILER_TARGET "x86_64-pc-freebsd11")
set (CMAKE_ASM_COMPILER_TARGET "x86_64-pc-freebsd11") set (CMAKE_ASM_COMPILER_TARGET "x86_64-pc-freebsd11")
set (CMAKE_SYSROOT "${CMAKE_CURRENT_LIST_DIR}/../../contrib/sysroot/freebsd-x86_64") set (CMAKE_SYSROOT "${CMAKE_CURRENT_LIST_DIR}/../../contrib/sysroot/freebsd-x86_64")
# dprintf is used in a patched version of replxx
add_compile_definitions(_WITH_DPRINTF)
set (CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) # disable linkage check - it doesn't work in CMake set (CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) # disable linkage check - it doesn't work in CMake

2
contrib/replxx vendored

@ -1 +1 @@
Subproject commit 711c18e7f4d951255aa8b0851e5a55d5a5fb0ddb Subproject commit 5d04501f93a4fb7f0bb8b73b8f614bc986f9e25b

View File

@ -6,7 +6,7 @@ title: "Functions for Working with Geohash"
## Geohash ## Geohash
[Geohash](https://en.wikipedia.org/wiki/Geohash) is the geocode system, which subdivides Earths surface into buckets of grid shape and encodes each cell into a short string of letters and digits. It is a hierarchical data structure, so the longer the geohash string is, the more precise the geographic location will be. [Geohash](https://en.wikipedia.org/wiki/Geohash) is the geocode system, which subdivides Earths surface into buckets of grid shape and encodes each cell into a short string of letters and digits. It is a hierarchical data structure, so the longer is the geohash string, the more precise is the geographic location.
If you need to manually convert geographic coordinates to geohash strings, you can use [geohash.org](http://geohash.org/). If you need to manually convert geographic coordinates to geohash strings, you can use [geohash.org](http://geohash.org/).
@ -14,37 +14,26 @@ If you need to manually convert geographic coordinates to geohash strings, you c
Encodes latitude and longitude as a [geohash](#geohash)-string. Encodes latitude and longitude as a [geohash](#geohash)-string.
**Syntax**
``` sql ``` sql
geohashEncode(longitude, latitude, [precision]) geohashEncode(longitude, latitude, [precision])
``` ```
**Input values** **Input values**
- `longitude` — Longitude part of the coordinate you want to encode. Floating in range`[-180°, 180°]`. [Float](../../data-types/float.md). - longitude - longitude part of the coordinate you want to encode. Floating in range`[-180°, 180°]`
- `latitude` — Latitude part of the coordinate you want to encode. Floating in range `[-90°, 90°]`. [Float](../../data-types/float.md). - latitude - latitude part of the coordinate you want to encode. Floating in range `[-90°, 90°]`
- `precision` (optional) — Length of the resulting encoded string. Defaults to `12`. Integer in the range `[1, 12]`. [Int8](../../data-types/int-uint.md). - precision - Optional, length of the resulting encoded string, defaults to `12`. Integer in range `[1, 12]`. Any value less than `1` or greater than `12` is silently converted to `12`.
:::note
- All coordinate parameters must be of the same type: either `Float32` or `Float64`.
- For the `precision` parameter, any value less than `1` or greater than `12` is silently converted to `12`.
:::
**Returned values** **Returned values**
- Alphanumeric string of the encoded coordinate (modified version of the base32-encoding alphabet is used). [String](../../data-types/string.md). - alphanumeric `String` of encoded coordinate (modified version of the base32-encoding alphabet is used).
**Example** **Example**
Query:
``` sql ``` sql
SELECT geohashEncode(-5.60302734375, 42.593994140625, 0) AS res; SELECT geohashEncode(-5.60302734375, 42.593994140625, 0) AS res;
``` ```
Result:
``` text ``` text
┌─res──────────┐ ┌─res──────────┐
│ ezs42d000000 │ │ ezs42d000000 │
@ -55,19 +44,13 @@ Result:
Decodes any [geohash](#geohash)-encoded string into longitude and latitude. Decodes any [geohash](#geohash)-encoded string into longitude and latitude.
**Syntax**
```sql
geohashDecode(hash_str)
```
**Input values** **Input values**
- `hash_str` — Geohash-encoded string. - encoded string - geohash-encoded string.
**Returned values** **Returned values**
- Tuple `(longitude, latitude)` of `Float64` values of longitude and latitude. [Tuple](../../data-types/tuple.md)([Float64](../../data-types/float.md)) - (longitude, latitude) - 2-tuple of `Float64` values of longitude and latitude.
**Example** **Example**

View File

@ -299,14 +299,13 @@ ReplxxLineReader::ReplxxLineReader(
Patterns delimiters_, Patterns delimiters_,
const char word_break_characters_[], const char word_break_characters_[],
replxx::Replxx::highlighter_callback_t highlighter_, replxx::Replxx::highlighter_callback_t highlighter_,
std::istream & input_stream_, [[ maybe_unused ]] std::istream & input_stream_,
std::ostream & output_stream_, [[ maybe_unused ]] std::ostream & output_stream_,
int in_fd_, [[ maybe_unused ]] int in_fd_,
int out_fd_, [[ maybe_unused ]] int out_fd_,
int err_fd_ [[ maybe_unused ]] int err_fd_
) )
: LineReader(history_file_path_, multiline_, std::move(extenders_), std::move(delimiters_), input_stream_, output_stream_, in_fd_) : LineReader(history_file_path_, multiline_, std::move(extenders_), std::move(delimiters_), input_stream_, output_stream_, in_fd_)
, rx(input_stream_, output_stream_, in_fd_, out_fd_, err_fd_)
, highlighter(std::move(highlighter_)) , highlighter(std::move(highlighter_))
, word_break_characters(word_break_characters_) , word_break_characters(word_break_characters_)
, editor(getEditor()) , editor(getEditor())
@ -517,7 +516,7 @@ void ReplxxLineReader::addToHistory(const String & line)
rx.history_add(line); rx.history_add(line);
// flush changes to the disk // flush changes to the disk
if (history_file_fd >= 0 && !rx.history_save(history_file_path)) if (!rx.history_save(history_file_path))
rx.print("Saving history failed: %s\n", errnoToString().c_str()); rx.print("Saving history failed: %s\n", errnoToString().c_str());
if (history_file_fd >= 0 && locked && 0 != flock(history_file_fd, LOCK_UN)) if (history_file_fd >= 0 && locked && 0 != flock(history_file_fd, LOCK_UN))

View File

@ -254,3 +254,4 @@
15 13 0 0 0 0 0 0 15 13 0 0 0 0 0 0
15 14 0 0 0 0 0 0 15 14 0 0 0 0 0 0
15 15 0 0 0 0 0 0 15 15 0 0 0 0 0 0
0 0 0

View File

@ -9,11 +9,8 @@ SIZE=13
for OFFSET in {0..15}; do for OFFSET in {0..15}; do
for LIMIT in {0..15}; do for LIMIT in {0..15}; do
echo "SELECT echo "SELECT
$OFFSET, $OFFSET, $LIMIT,
$LIMIT, count() AS c, min(number) AS first, max(number) AS last,
count() AS c,
min(number) AS first,
max(number) AS last,
throwIf(first != ($OFFSET < $SIZE AND $LIMIT > 0 ? $OFFSET : 0)), throwIf(first != ($OFFSET < $SIZE AND $LIMIT > 0 ? $OFFSET : 0)),
throwIf(last != ($OFFSET < $SIZE AND $LIMIT > 0 ? least($SIZE - 1, $OFFSET + $LIMIT - 1) : 0)), throwIf(last != ($OFFSET < $SIZE AND $LIMIT > 0 ? least($SIZE - 1, $OFFSET + $LIMIT - 1) : 0)),
throwIf((c != 0 OR first != 0 OR last != 0) AND (c != last - first + 1)) throwIf((c != 0 OR first != 0 OR last != 0) AND (c != last - first + 1))
@ -21,3 +18,20 @@ for OFFSET in {0..15}; do
" "
done done
done | $CLICKHOUSE_CLIENT -n --max_block_size 5 done | $CLICKHOUSE_CLIENT -n --max_block_size 5
# Randomized test
ITERATIONS=1000
for _ in $(seq $ITERATIONS); do
SIZE=$(($RANDOM % 100))
OFFSET=$(($RANDOM % 111))
LIMIT=$(($RANDOM % 111))
echo "WITH count() AS c, min(number) AS first, max(number) AS last
SELECT
throwIf(first != ($OFFSET < $SIZE AND $LIMIT > 0 ? $OFFSET : 0)),
throwIf(last != ($OFFSET < $SIZE AND $LIMIT > 0 ? least($SIZE - 1, $OFFSET + $LIMIT - 1) : 0)),
throwIf((c != 0 OR first != 0 OR last != 0) AND (c != last - first + 1))
FROM (SELECT * FROM numbers($SIZE) LIMIT $OFFSET, $LIMIT);
"
done | $CLICKHOUSE_CLIENT -n --max_block_size $(($RANDOM % 20 + 1)) | uniq

View File

@ -1,22 +0,0 @@
#!/usr/bin/env bash
# Tags: no-fasttest
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
SIZE=13
ITERATIONS=300
for _ in $(seq $ITERATIONS); do
SIZE=$(($RANDOM % 100))
OFFSET=$(($RANDOM % 111))
LIMIT=$(($RANDOM % 111))
echo "WITH count() AS c, min(number) AS first, max(number) AS last
SELECT
throwIf(first != ($OFFSET < $SIZE AND $LIMIT > 0 ? $OFFSET : 0)),
throwIf(last != ($OFFSET < $SIZE AND $LIMIT > 0 ? least($SIZE - 1, $OFFSET + $LIMIT - 1) : 0)),
throwIf((c != 0 OR first != 0 OR last != 0) AND (c != last - first + 1))
FROM (SELECT * FROM numbers($SIZE) LIMIT $OFFSET, $LIMIT);
"
done | $CLICKHOUSE_CLIENT -n --max_block_size $(($RANDOM % 20 + 1)) | uniq