AshClickhouse.DataLayer (AshClickhouse v0.1.0)

Copy Markdown View Source

An Ash data layer for ClickHouse.

This data layer implements the Ash.DataLayer behaviour so that Ash resources can be backed by a ClickHouse columnar OLAP database. It uses the clickhouse client under the hood.

Configuration

defmodule MyApp.MyResource do
  use Ash.Resource,
    data_layer: AshClickhouse.DataLayer

  clickhouse do
    table "my_table"
    repo MyApp.Repo
  end

  attributes do
    uuid_primary_key :id
    attribute :name, :string
  end
end

Features Supported

  • :create / :read / :update / :destroy
  • :filter — full WHERE support
  • :limit / :offset — ClickHouse supports both natively
  • :select — column projection
  • :sortORDER BY
  • :distinctSELECT DISTINCT
  • :multitenancy — database- or attribute-based
  • :bulk_create — batch INSERT
  • :update_query / :destroy_queryALTER TABLE ... UPDATE/DELETE
  • :calculate — in-memory calculations
  • :composite_primary_key
  • :nested_expressions / :boolean_filter
  • :async_engine
  • :expression_calculation
  • {:aggregate, :count | :sum | :avg | :min | :max} — native aggregates

  • {:query_aggregate, :count | :sum | :avg | :min | :max}

  • Combination queries (UNION/INTERSECT) — executed by Ash in memory

Features NOT Supported

  • :transact — ClickHouse has no multi-statement transactions
  • :lock — locking is a no-op
  • :keyset — ClickHouse has no token-based keyset pagination
  • :upsert — ClickHouse has no ON CONFLICT (use :create + :update_query)
  • :expression_calculation_sort — not supported
  • :aggregate_filter / :aggregate_sort — not supported
  • :update_many — use :update_query
  • :composite_type / :through_relationship
  • :join — JOINs are not yet implemented
  • :filter_relationship / {:exists, :unrelated} / {:aggregate_relationship, _}
  • {:query_aggregate, :list | :first | :exists | :custom} — only count/sum/avg/min/max

Summary

Types

t()

@type t() :: AshClickhouse.Query.t()