Search code examples
clickhousedbt

how to allow_nullable_key in dbt-clickhouse?


I'm building my tables using dbt with clickhouse plugin. I would like to enable allow_nullable_key setting. I tried specifying it on the config but it's not working.

{{
    config(
        materialized = "incremental",
        engine = "ReplicatedMergeTree",
        unique_key = "transaction_id",
        order_by = "last_mod",
        allow_nullable_key = 1,
        indexes=[
          {'columns': ['transaction_id'], 'type': 'btree', 'unique': True },
          {'columns': ['merchant_id'], 'type': 'btree'},
          {'columns': ['shop_id'], 'type': 'btree'},
          {'columns': ['last_mod'], 'type': 'btree'}
        ]
    )
}}

I've also tried to add it in the profile but also no luck:

local_clickhouse:
      type: clickhouse
      schema: schema
      user: user
      password: password
      port: 9000
      host: localhost
      cluster: cluster
      retries: 1
      connect_timeout: 10
      use_lw_deletes: True # `delete+insert` as the default incremental strategy
      custom_settings:
        allow_nullable_key: 1

Solution

  • Turns out I just needed to add allow_nullable_key: 1 but as a dictionary of settings in my model.

    {{
        config(
            materialized = "incremental",
            engine = "ReplicatedMergeTree",
            unique_key = "transaction_id",
            order_by = "last_mod",
            settings = {'allow_nullable_key': 1},
            indexes=[
              {'columns': ['transaction_id'], 'type': 'btree', 'unique': True },
              {'columns': ['merchant_id'], 'type': 'btree'},
              {'columns': ['shop_id'], 'type': 'btree'},
              {'columns': ['last_mod'], 'type': 'btree'}
            ]
        )
    }}