Skip to content

Adds `to_redacted_sql` support for ClickHouse QueryBuilder

What does this MR do and why?

Adds to_redacted_sql support for ClickHouse QueryBuilder

This commit adds to_redacted_sql support for ClickHouse QueryBuilder and also fixes issues of incorrect sql being generated when to_sql was called multiple times.

Changelog: added

How to set up and validate locally

  1. Write SQL queries using query builder, you can test with different calls below is an example:
ClickHouse::QueryBuilder.new("test_table").select(:column1, :column2).where(column1: 'value1', column2: 'value2')
               .order(:column1, 'desc').limit(10)
               .offset(5).to_sql

"SELECT \"test_table\".\"column1\", \"test_table\".\"column2\" FROM \"test_table\" WHERE \"test_table\".\"column1\" = 'value1' AND \"test_table\".\"column2\" = 'value2' ORDER BY \"test_table\".\"column1\" DESC LIMIT 10 OFFSET 5"
  1. Try calling to_sql on same instance multiple times and check correct sql is generated

  2. Try calling to_redacted_sql on query builder instance, it should replace values with placeholders.

ClickHouse::QueryBuilder.new("test_table").select(:column1, :column2).where(column1: 'value1', column2: 'value2')
.order(:column1, 'desc').limit(10)ted_sql

"SELECT \"test_table\".\"column1\", \"test_table\".\"column2\" FROM \"test_table\" WHERE \"test_table\".\"column1\" = '$1' AND \"test_table\".\"column2\" = '$2' ORDER BY \"test_table\".\"column1\" DESC LIMIT 10 OFFSET 5"

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #421403 (closed)

Edited by Harsimar Sandhu

Merge request reports