Skip to content

Commit

Permalink
wip: param bind env work
Browse files Browse the repository at this point in the history
  • Loading branch information
stergiotis committed Jan 5, 2025
1 parent af5e7a8 commit 595acfa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion public/db/clickhouse/dsl/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
)

type ParamBindEnv struct {
bind map[string]*chparser.SettingExprList
bind map[string]*chparser.SettingExprList
inputSql string
}

func NewParamBindEnv() *ParamBindEnv {
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions public/db/clickhouse/dsl/parseddqlquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 595acfa

Please sign in to comment.