Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCS-526: ifNotFinite docs. Ternary operator RU translation #9650

Merged
merged 11 commits into from
Mar 17, 2020
8 changes: 6 additions & 2 deletions docs/en/query_language/functions/conditional_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,22 @@ WHERE isNotNull(left) AND isNotNull(right)
```
Note: `NULL` values are not used in this example, check [NULL values in conditionals](#null-values-in-conditionals) section.

## Ternary operator
## Ternary Operator {#ternary-operator}

It works same as `if` function.

Syntax: `cond ? then : else`

Returns `then` if the `cond` is truthy(greater than zero), otherwise returns `else`.
Returns `then` if the `cond` evaluates to be true (greater than zero), otherwise returns `else`.

* `cond` must be of type of `UInt8`, and `then` and `else` must have the lowest common type.

* `then` and `else` can be `NULL`

**See also**

- [ifNotFinite](other_functions.md#ifnotfinite).

## multiIf

Allows you to write the [CASE](../operators.md#operator_case) operator more compactly in the query.
Expand Down
37 changes: 37 additions & 0 deletions docs/en/query_language/functions/other_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,43 @@ Accepts Float32 and Float64 and returns UInt8 equal to 1 if the argument is not

Accepts Float32 and Float64 and returns UInt8 equal to 1 if the argument is infinite, otherwise 0. Note that 0 is returned for a NaN.

## ifNotFinite {#ifnotfinite}

Checks whether floating point value is finite.

**Syntax**

```
ifNotFinite(x,y)
```
**Parameters**

- `x` — Value to be checked for infinity. Type: [Float*](../../data_types/float.md).
- `y` — Fallback value. Type: [Float*](../../data_types/float.md).
BayoNet marked this conversation as resolved.
Show resolved Hide resolved

**Returned value**

- `x` if `x` is finite.
- `y` if `x` is not finite.

**Example**

Query:

```
SELECT 1/0 as infimum, ifNotFinite(infimum,42)
```

Result:

```
┌─infimum─┬─ifNotFinite(divide(1, 0), 42)─┐
│ inf │ 42 │
└─────────┴───────────────────────────────┘
```

You can get similar result by using [ternary operator](conditional_functions.md#ternary-operator): `isFinite(x) ? x : y`.

## isNaN(x)

Accepts Float32 and Float64 and returns UInt8 equal to 1 if the argument is a NaN, otherwise 0.
Expand Down
16 changes: 16 additions & 0 deletions docs/ru/query_language/functions/conditional_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ SELECT if(0, plus(2, 2), plus(2, 6))
└────────────┘
```

## Тернарный оператор {#ternary-operator}

Работает так же, как функция `if`.

Синтаксис: `cond ? then : else`

Возвращает `then`, если `cond` верно (больше нуля), в остальных случаях возвращает `else`.

* `cond` должно быть типа `UInt8`, `then` и `else` должны относиться к наименьшему общему типу.

* `then` и `else` могут быть `NULL`.

**Смотрите также**

- [ifNotFinite](other_functions.md#ifnotfinite).

## multiIf

Позволяет более компактно записать оператор [CASE](../operators.md#operator_case) в запросе.
Expand Down
38 changes: 38 additions & 0 deletions docs/ru/query_language/functions/other_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,44 @@ SELECT currentUser();
## isFinite(x)
Принимает Float32 или Float64 и возвращает UInt8, равный 1, если аргумент не бесконечный и не NaN, иначе 0.

## ifNotFinite {#ifnotfinite}

Проверяет, является ли значение дробного числа с плавающей точкой конечным.

**Синтаксис**

```
ifNotFinite(x,y)
```

**Параметры**

- `x` — Значение, которое нужно проверить на бесконечность. Тип: [Float*](../../data_types/float.md).
- `y` — Запасное значение. Тип: [Float*](../../data_types/float.md).

**Возвращаемые значения**

- `x`, если `x` принимает конечное значение.
- `y`, если`x` принимает не конечное значение.

**Пример**

Запрос:

```
SELECT 1/0 as infimum, ifNotFinite(infimum,42)
```

Результат:

```
┌─infimum─┬─ifNotFinite(divide(1, 0), 42)─┐
│ inf │ 42 │
└─────────┴───────────────────────────────┘
```

Аналогичный результат можно получить с помощью [тернарного оператора](conditional_functions.md#ternary-operator) `isFinite(x) ? x : y`.

## isInfinite(x)
Принимает Float32 или Float64 и возвращает UInt8, равный 1, если аргумент бесконечный, иначе 0. Отметим, что в случае NaN возвращается 0.

Expand Down