From 595acfa7ee64554bf41a01fd695e9bf7a6aa41ef Mon Sep 17 00:00:00 2001 From: Panos Stergiotis
Date: Sun, 5 Jan 2025 22:57:21 +0100 Subject: [PATCH] wip: param bind env work --- public/db/clickhouse/dsl/params.go | 8 +++++++- public/db/clickhouse/dsl/parseddqlquery.go | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/public/db/clickhouse/dsl/params.go b/public/db/clickhouse/dsl/params.go index fe67e56..ce8c1fe 100644 --- a/public/db/clickhouse/dsl/params.go +++ b/public/db/clickhouse/dsl/params.go @@ -10,7 +10,8 @@ import ( ) type ParamBindEnv struct { - bind map[string]*chparser.SettingExprList + bind map[string]*chparser.SettingExprList + inputSql string } func NewParamBindEnv() *ParamBindEnv { @@ -40,6 +41,10 @@ func (inst *ParamBindEnv) AddDistinct(p *chparser.SettingExprList) (err error) { inst.bind[name] = p return } +func (inst *ParamBindEnv) Clear() { + clear(inst.bind) + inst.inputSql = "" +} func (inst *ParamBindEnv) Set(p *chparser.SettingExprList) { if p == nil { return @@ -51,6 +56,7 @@ func (inst *ParamBindEnv) Set(p *chparser.SettingExprList) { func (inst *ParamBindEnv) IterSql() iter.Seq2[string, string] { return func(yield func(string, string) bool) { for _, p := range inst.bind { + // FIXME use inputSql together with p.Expr.Pos for expression? if !yield(p.Name.String(), p.Expr.String()) { return } diff --git a/public/db/clickhouse/dsl/parseddqlquery.go b/public/db/clickhouse/dsl/parseddqlquery.go index 020b22d..38a3fce 100644 --- a/public/db/clickhouse/dsl/parseddqlquery.go +++ b/public/db/clickhouse/dsl/parseddqlquery.go @@ -77,6 +77,8 @@ func NewParsedDqlQuery(sql string) (inst *ParsedDqlQuery, err error) { func (inst *ParsedDqlQuery) removeParamSettingsFromExprs(exprs []chparser.Expr) (exprsOut []chparser.Expr, err error) { const paramPrefixName = "param_" // Note: param names are case-sensitive bindEnv := inst.paramBindEnv + bindEnv.Clear() + bindEnv.inputSql = inst.inputSql for _, expr := range exprs { switch exprt := expr.(type) { case *chparser.SetStmt: