Skip to content

Commit

Permalink
add array join caveat
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed Apr 17, 2023
1 parent 96f21a3 commit 4d08839
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Hex Package](https://img.shields.io/hexpm/v/chto.svg)](https://hex.pm/packages/chto)
[![Hex Docs](https://img.shields.io/badge/hex-docs-blue.svg)](https://hexdocs.pm/chto)

Uses [`Ch`](https://github.com/plausible/ch) as driver.
Uses [Ch](https://github.com/plausible/ch) as driver.

## Installation

Expand Down Expand Up @@ -87,6 +87,29 @@ MyApp.Repo.insert_all(MyApp.Example, rows, settings: [async_insert: 1])
MyApp.Repo.delete_all("example", settings: [allow_experimental_lightweight_delete: 1])
```

#### Array join

Ecto query doesn't `:array_join` type, so as a workaround `:inner_lateral` and `:left_lateral` are used instead for [`ARRAY JOIN`](https://clickhouse.com/docs/en/sql-reference/statements/select/array-join) and `LEFT ARRAY JOIN`, respectively:

```elixir
query =
"arrays_test"
|> join(:inner_lateral, [a], r in "arr", on: true)
|> select([a, r], {a.s, r.arr})

{sql, _params} = Repo.to_sql(:all, query)

IO.puts(sql)
```

(Prettified) output:

```sql
SELECT a0."s", a1."arr"
FROM "arrays_test" AS a0
ARRAY JOIN "arr" AS a1
```

#### UNION and co

As of version `22.8` ClickHouse [doesn't allow](https://clickhouse.com/docs/en/sql-reference/statements/select/union) ordering or limiting combined queries:
Expand Down Expand Up @@ -136,11 +159,15 @@ LIMIT 2

#### NULL

`DEFAULT` clauses on tables are ignored when inserting RowBinary. [Please see Ch for more details and an example.](https://github.com/plausible/ch#null-in-rowbinary)
`DEFAULT` clauses on tables are ignored when inserting RowBinary.

[Ch has more details and an example.](https://github.com/plausible/ch#null-in-rowbinary)

#### UTF-8

Both `:binary` and `:string` Ecto schema fields are decoded as UTF-8 since Ecto doesn't allow overriding `:binary` and `:string` loaders. If that causes problems (e.g. you want to have access to the raw binary stored in `String` column), please open an issue. [See Ch for more details and an example.](https://github.com/plausible/ch#utf-8-in-rowbinary)
Both `:binary` and `:string` Ecto schema fields are decoded as UTF-8 since Ecto doesn't allow overriding `:binary` and `:string` loaders. If that causes problems (e.g. you want to have access to the raw binary stored in `String` column), please open an issue.

[See Ch for more details and an example.](https://github.com/plausible/ch#utf-8-in-rowbinary)

## Benchmarks

Expand Down

0 comments on commit 4d08839

Please sign in to comment.