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
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---

Check notice on line 1 in docs/sql-manual/sql-functions/ai-functions/distance-functions/cosine-similarity.md

View workflow job for this annotation

GitHub Actions / Build Check

i18n-sync-locale-candidate

Japanese docs are report-only. Generate a candidate translation from the changed files and merge it only after human review. Owner%3A @apache/doris-website-maintainers
{
"title": "COSINE_SIMILARITY",
"language": "en",
"description": "Calculates the cosine similarity between two vectors."
}
---

## Description

Calculates the cosine similarity between two vectors.
The similarity is computed from the dot product and vector norms, and the result is in `[-1, 1]`.

## Syntax

```sql
COSINE_SIMILARITY(<array1>, <array2>)
```

## Parameters

| Parameter | Description |
|---|--|
| `<array1>` | The first vector. The input type must be `ARRAY<FLOAT>`. |
| `<array2>` | The second vector. The input type must be `ARRAY<FLOAT>`, and the number of elements must be the same as `<array1>`. |

## Return Value

Returns the cosine similarity between two vectors, in FLOAT type.
If the input array is `NULL`, or any element in the array is `NULL`, an error is returned.
If the two arrays have different numbers of elements, an error is returned.
If the array is empty, or either vector is a zero vector, `0.0` is returned.

## Example

```sql
-- Two identical vectors have similarity 1
SELECT COSINE_SIMILARITY([1, 2, 3], [1, 2, 3]);
```

```text
+-----------------------------------------+
| COSINE_SIMILARITY([1, 2, 3], [1, 2, 3]) |
+-----------------------------------------+
| 1 |
+-----------------------------------------+
```

`[1, 2, 3]` and `[1, 2, 3]` point in the same direction, so the similarity is `1`.

```sql
-- Orthogonal vectors have similarity 0
SELECT COSINE_SIMILARITY([1, 0], [0, 1]);
```

```text
+-----------------------------------+
| COSINE_SIMILARITY([1, 0], [0, 1]) |
+-----------------------------------+
| 0 |
+-----------------------------------+
```

The vectors are orthogonal, so their dot product is `0` and the similarity is `0`.

```sql
-- A zero vector returns 0
SELECT COSINE_SIMILARITY([0, 0, 0], [1, 2, 3]);
```

```text
+-----------------------------------------+
| COSINE_SIMILARITY([0, 0, 0], [1, 2, 3]) |
+-----------------------------------------+
| 0 |
+-----------------------------------------+
```

A zero vector has no valid direction, so the result is `0`.

```sql
-- An empty array returns 0
SELECT COSINE_SIMILARITY([], []);
```

```text
+---------------------------+
| COSINE_SIMILARITY([], []) |
+---------------------------+
| 0 |
+---------------------------+
```

```sql
-- NULL inside the input array raises an error
SELECT COSINE_SIMILARITY([1, NULL, 3], [1, 2, 3]);
```

```text
ERROR 1105 (HY000): errCode = 2, detailMessage = (127.0.0.1)[INVALID_ARGUMENT]First argument for function cosine_similarity cannot have null
```

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check notice on line 1 in docs/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md

View workflow job for this annotation

GitHub Actions / Build Check

i18n-sync-locale-candidate

Japanese docs are report-only. Generate a candidate translation from the changed files and merge it only after human review. Owner%3A @apache/doris-website-maintainers

Check notice on line 1 in docs/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md

View workflow job for this annotation

GitHub Actions / Build Check

i18n-sync-version-candidate

A 3.x counterpart exists. Confirm whether the change is supported in 3.x before leaving it unsynced. Owner%3A @apache/doris-website-maintainers
{
"title": "ARRAY_CUM_SUM",
"language": "en",
Expand Down Expand Up @@ -103,8 +103,7 @@
| [null, 1, null, 3, null, 6] |
+-----------------------------------------+
```
Hello Hello.,Hello123hello
Hello Hello.,Hello123hello

Empty array returns empty array:
```sql
SELECT array_cum_sum(int_array) FROM array_cum_sum_test WHERE id = 3;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---

Check notice on line 1 in docs/sql-manual/sql-functions/scalar-functions/date-time-functions/quarter-ceil.md

View workflow job for this annotation

GitHub Actions / Build Check

i18n-sync-locale-candidate

Japanese docs are report-only. Generate a candidate translation from the changed files and merge it only after human review. Owner%3A @apache/doris-website-maintainers

Check warning on line 1 in docs/sql-manual/sql-functions/scalar-functions/date-time-functions/quarter-ceil.md

View workflow job for this annotation

GitHub Actions / Build Check

frontmatter-description-required

Missing required front matter field%3A description. Owner%3A @apache/doris-website-maintainers
{
"title": "QUARTER_CEIL",
"language": "en"
}
---

## Description

Rounds a datetime value up to the nearest specified quarter period boundary. If an origin time is specified, the period is calculated based on that time.

## Syntax

```sql
QUARTER_CEIL(<datetime>)
QUARTER_CEIL(<datetime>, <origin>)
QUARTER_CEIL(<datetime>, <period>)
QUARTER_CEIL(<datetime>, <period>, <origin>)
```

## Parameters

| Parameter | Description |
| ---- | ---- |
| `<datetime>` | The datetime value to round up, type is DATE or DATETIME |
| `<period>` | Quarter period value, type is INT, representing the number of quarters contained in each period |
| `<origin>` | The starting point of the period, type is DATE or DATETIME, default value is 0001-01-01 00:00:00 |

Notes:
- When period is not specified, it is equivalent to using 1 quarter as the period
- When period is not a positive integer, the function result will be NULL
- The result always rounds to the future time
- The time part of the return value is always 00:00:00

## Return Value

When `<datetime>` is of DATE type, the return type is DATE.
When `<datetime>` is of DATETIME type, the return type is DATETIME.
Represents the rounded up datetime value. The time part of the result will be set to 00:00:00.

## Examples

Starting from '0001-01-01 00:00:00', with periods of 5 / 4 quarters each, return the next period start point closest to the input date.
```sql
SELECT QUARTER_CEIL("2023-07-13 22:28:18", 5), QUARTER_CEIL("2023-07-13 22:28:18", 4);
```

```text
+----------------------------------------+----------------------------------------+
| QUARTER_CEIL("2023-07-13 22:28:18", 5) | QUARTER_CEIL("2023-07-13 22:28:18", 4) |
+----------------------------------------+----------------------------------------+
| 2024-10-01 00:00:00.000000 | 2024-01-01 00:00:00.000000 |
+----------------------------------------+----------------------------------------+
```

Using '2022-01-01 00:00:00' as the period start point, with periods of 2 / 4 quarters each, return the next period start point closest to the input date.
```sql
SELECT QUARTER_CEIL("2023-03-13 22:28:18", 2, "2022-01-01 00:00:00"), QUARTER_CEIL("2023-07-13 22:28:18", 4, "2022-01-01 00:00:00");
```

```text
+---------------------------------------------------------------+---------------------------------------------------------------+
| QUARTER_CEIL("2023-03-13 22:28:18", 2, "2022-01-01 00:00:00") | QUARTER_CEIL("2023-07-13 22:28:18", 4, "2022-01-01 00:00:00") |
+---------------------------------------------------------------+---------------------------------------------------------------+
| 2023-07-01 00:00:00 | 2024-01-01 00:00:00 |
+---------------------------------------------------------------+---------------------------------------------------------------+
```

## Best Practices

See also [date_ceil](./date-ceil)
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---

Check notice on line 1 in docs/sql-manual/sql-functions/scalar-functions/date-time-functions/quarter-floor.md

View workflow job for this annotation

GitHub Actions / Build Check

i18n-sync-locale-candidate

Japanese docs are report-only. Generate a candidate translation from the changed files and merge it only after human review. Owner%3A @apache/doris-website-maintainers

Check warning on line 1 in docs/sql-manual/sql-functions/scalar-functions/date-time-functions/quarter-floor.md

View workflow job for this annotation

GitHub Actions / Build Check

frontmatter-description-required

Missing required front matter field%3A description. Owner%3A @apache/doris-website-maintainers
{
"title": "QUARTER_FLOOR",
"language": "en"
}
---

## Description

Rounds a datetime value down to the nearest specified quarter period boundary. If an origin time is specified, the period is calculated based on that time.

## Syntax

```sql
QUARTER_FLOOR(<datetime>)
QUARTER_FLOOR(<datetime>, <origin>)
QUARTER_FLOOR(<datetime>, <period>)
QUARTER_FLOOR(<datetime>, <period>, <origin>)
```

## Parameters

| Parameter | Description |
| ---- | ---- |
| `<datetime>` | The datetime value to round down, type is DATE or DATETIME |
| `<period>` | Quarter period value, type is INT, representing the number of quarters contained in each period |
| `<origin>` | The starting point of the period, type is DATE or DATETIME, default value is 0001-01-01 00:00:00 |

Notes:
- When period is not specified, it is equivalent to using 1 quarter as the period
- When period is not a positive integer, the function result will be NULL
- The result always rounds to the past time
- The time part of the return value is always 00:00:00

## Return Value

When `<datetime>` is of DATE type, the return type is DATE.
When `<datetime>` is of DATETIME type, the return type is DATETIME.
The time part of the result will be set to 00:00:00.

## Examples

Starting from '0001-01-01 00:00:00', with periods of 5 / 4 quarters each, return the period start point closest to the input date.
```sql
SELECT QUARTER_FLOOR("2023-07-13 22:28:18", 5), QUARTER_FLOOR("2023-07-13 22:28:18", 4);
```

```text
+-----------------------------------------+-----------------------------------------+
| QUARTER_FLOOR("2023-07-13 22:28:18", 5) | QUARTER_FLOOR("2023-07-13 22:28:18", 4) |
+-----------------------------------------+-----------------------------------------+
| 2021-01-01 00:00:00 | 2022-01-01 00:00:00 |
+-----------------------------------------+-----------------------------------------+
```

Using '2022-01-01 00:00:00' as the period start point, with periods of 2 / 4 quarters each, return the period start point closest to the input date.
```sql
SELECT QUARTER_FLOOR("2023-03-13 22:28:18", 2, "2022-01-01 00:00:00"), QUARTER_FLOOR("2023-07-13 22:28:18", 4, "2022-01-01 00:00:00");
```

```text
+----------------------------------------------------------------+----------------------------------------------------------------+
| QUARTER_FLOOR("2023-03-13 22:28:18", 2, "2022-01-01 00:00:00") | QUARTER_FLOOR("2023-07-13 22:28:18", 4, "2022-01-01 00:00:00") |
+----------------------------------------------------------------+----------------------------------------------------------------+
| 2023-01-01 00:00:00 | 2022-01-01 00:00:00 |
+----------------------------------------------------------------+----------------------------------------------------------------+
```

## Best Practices

See also [date_floor](./date-floor)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---

Check notice on line 1 in docs/sql-manual/sql-functions/scalar-functions/date-time-functions/quarters-diff.md

View workflow job for this annotation

GitHub Actions / Build Check

i18n-sync-locale-candidate

Japanese docs are report-only. Generate a candidate translation from the changed files and merge it only after human review. Owner%3A @apache/doris-website-maintainers

Check warning on line 1 in docs/sql-manual/sql-functions/scalar-functions/date-time-functions/quarters-diff.md

View workflow job for this annotation

GitHub Actions / Build Check

frontmatter-description-required

Missing required front matter field%3A description. Owner%3A @apache/doris-website-maintainers
{
"title": "QUARTERS_DIFF",
"language": "en"
}
---

## Description

The `QUARTERS_DIFF` function calculates the number of quarters between two dates. This function accepts two date parameters and returns the difference in quarters after subtracting the second date from the first date. The difference in quarters is equivalent to the difference in months divided by 3 (rounded towards zero).

## Syntax

```sql
QUARTERS_DIFF(<enddate>, <startdate>)
```

## Parameters

| Parameter | Description |
|---------------|--------------------------------------------------------------------------------------|
| `<enddate>` | End date, represents the later date when calculating the difference. Supports `DATE` or `DATETIME` types |
| `<startdate>` | Start date, represents the earlier date when calculating the difference. Supports `DATE` or `DATETIME` types |

## Return Value

Returns the number of quarters obtained by subtracting `<startdate>` from `<enddate>`
- When either `<enddate>` or `<startdate>` is NULL, returns NULL

## Examples

```sql
select QUARTERS_DIFF('2021-03-25', '2020-10-25'), QUARTERS_DIFF('2020-10-25 10:00:00', '2022-12-25 11:00:00');
```

```text
+------------------------------------------+------------------------------------------------------------+
| QUARTERS_DIFF('2021-03-25','2020-10-25') | QUARTERS_DIFF('2020-10-25 10:00:00','2022-12-25 11:00:00') |
+------------------------------------------+------------------------------------------------------------+
| 1 | -8 |
+------------------------------------------+------------------------------------------------------------+
```
Loading
Loading