Skip to content

Commit f1fd2c9

Browse files
vojtabiberleclaude
andcommitted
DMD-919 - Remove debug flag and fix ctx parameter order in configparser
- Remove debug bool parameter from ParseTransformationConfig and ParseCodeBlocks - Logger handles log level filtering, no need for debug conditionals - Move ctx to first parameter position per Go conventions - Update callers in fetcher.go and tests Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a78bbb2 commit f1fd2c9

3 files changed

Lines changed: 25 additions & 57 deletions

File tree

internal/pkg/llm/twinformat/configparser/parser.go

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
// ParseTransformationConfig parses a Config into TransformationConfig.
15-
func ParseTransformationConfig(componentID string, cfg *keboola.ConfigWithRows, debug bool, logger log.Logger, ctx context.Context) *TransformationConfig {
15+
func ParseTransformationConfig(ctx context.Context, componentID string, cfg *keboola.ConfigWithRows, logger log.Logger) *TransformationConfig {
1616
config := &TransformationConfig{
1717
ID: cfg.ID.String(),
1818
Name: cfg.Name,
@@ -27,61 +27,50 @@ func ParseTransformationConfig(componentID string, cfg *keboola.ConfigWithRows,
2727
return config
2828
}
2929

30-
// Debug: log available keys
31-
if debug {
32-
logger.Debugf(ctx, "Config %s keys: %v", cfg.Name, cfg.Content.Keys())
33-
}
30+
logger.Debugf(ctx, "Config %s keys: %v", cfg.Name, cfg.Content.Keys())
3431

3532
// Parse storage.input.tables and storage.output.tables
36-
parseStorageSection(config, cfg, debug, logger, ctx)
33+
parseStorageSection(ctx, config, cfg, logger)
3734

3835
// Parse parameters.blocks for transformation code
39-
parseParametersSection(config, cfg, debug, logger, ctx)
36+
parseParametersSection(ctx, config, cfg, logger)
4037

4138
return config
4239
}
4340

4441
// parseStorageSection parses the storage section of a transformation config.
45-
func parseStorageSection(config *TransformationConfig, cfg *keboola.ConfigWithRows, debug bool, logger log.Logger, ctx context.Context) {
42+
func parseStorageSection(ctx context.Context, config *TransformationConfig, cfg *keboola.ConfigWithRows, logger log.Logger) {
4643
storage, ok := cfg.Content.Get("storage")
4744
if !ok {
4845
return
4946
}
5047

5148
storageMap := toStringMap(storage)
5249
if storageMap == nil {
53-
if debug {
54-
logger.Debugf(ctx, "Config %s storage type: %T", cfg.Name, storage)
55-
}
50+
logger.Debugf(ctx, "Config %s storage type: %T", cfg.Name, storage)
5651
return
5752
}
5853

59-
if debug {
60-
logger.Debugf(ctx, "Config %s storage keys: %v", cfg.Name, maps.Keys(storageMap))
61-
}
54+
logger.Debugf(ctx, "Config %s storage keys: %v", cfg.Name, maps.Keys(storageMap))
6255
config.InputTables = ParseStorageMappings(storageMap, "input")
6356
config.OutputTables = ParseStorageMappings(storageMap, "output")
6457
}
6558

6659
// parseParametersSection parses the parameters section of a transformation config.
67-
func parseParametersSection(config *TransformationConfig, cfg *keboola.ConfigWithRows, debug bool, logger log.Logger, ctx context.Context) {
60+
func parseParametersSection(ctx context.Context, config *TransformationConfig, cfg *keboola.ConfigWithRows, logger log.Logger) {
6861
params, ok := cfg.Content.Get("parameters")
6962
if !ok {
7063
return
7164
}
7265

7366
paramsMap := toStringMap(params)
7467
if paramsMap == nil {
75-
if debug {
76-
logger.Debugf(ctx, "Config %s parameters type: %T", cfg.Name, params)
77-
}
68+
logger.Debugf(ctx, "Config %s parameters type: %T", cfg.Name, params)
7869
return
7970
}
8071

81-
if debug {
82-
logger.Debugf(ctx, "Config %s parameters keys: %v", cfg.Name, maps.Keys(paramsMap))
83-
}
84-
config.Blocks = ParseCodeBlocks(paramsMap, debug, logger, ctx)
72+
logger.Debugf(ctx, "Config %s parameters keys: %v", cfg.Name, maps.Keys(paramsMap))
73+
config.Blocks = ParseCodeBlocks(ctx, paramsMap, logger)
8574
}
8675

8776
// toStringMap converts various map types to map[string]any.
@@ -162,11 +151,11 @@ func parseTableMapping(t any) (StorageMapping, bool) {
162151
}
163152

164153
// ParseCodeBlocks parses code blocks from transformation parameters.
165-
func ParseCodeBlocks(params map[string]any, debug bool, logger log.Logger, ctx context.Context) []*CodeBlock {
154+
func ParseCodeBlocks(ctx context.Context, params map[string]any, logger log.Logger) []*CodeBlock {
166155
blocks := make([]*CodeBlock, 0)
167156

168157
// Parse standard blocks format
169-
blocks = append(blocks, parseBlocks(params, debug, logger, ctx)...)
158+
blocks = append(blocks, parseBlocks(ctx, params, logger)...)
170159

171160
// Handle Snowflake/SQL transformations that use "queries" instead of "blocks"
172161
if queryBlock := parseQueries(params); queryBlock != nil {
@@ -177,7 +166,7 @@ func ParseCodeBlocks(params map[string]any, debug bool, logger log.Logger, ctx c
177166
}
178167

179168
// parseBlocks parses the "blocks" section from transformation parameters.
180-
func parseBlocks(params map[string]any, debug bool, logger log.Logger, ctx context.Context) []*CodeBlock {
169+
func parseBlocks(ctx context.Context, params map[string]any, logger log.Logger) []*CodeBlock {
181170
blocks := make([]*CodeBlock, 0)
182171

183172
blocksRaw, ok := params["blocks"]
@@ -191,7 +180,7 @@ func parseBlocks(params map[string]any, debug bool, logger log.Logger, ctx conte
191180
}
192181

193182
for _, b := range blocksSlice {
194-
if block := parseBlock(b, debug, logger, ctx); block != nil {
183+
if block := parseBlock(ctx, b, logger); block != nil {
195184
blocks = append(blocks, block)
196185
}
197186
}
@@ -200,7 +189,7 @@ func parseBlocks(params map[string]any, debug bool, logger log.Logger, ctx conte
200189
}
201190

202191
// parseBlock parses a single block from the configuration.
203-
func parseBlock(b any, debug bool, logger log.Logger, ctx context.Context) *CodeBlock {
192+
func parseBlock(ctx context.Context, b any, logger log.Logger) *CodeBlock {
204193
blockMap := toStringMap(b)
205194
if blockMap == nil {
206195
return nil
@@ -211,11 +200,9 @@ func parseBlock(b any, debug bool, logger log.Logger, ctx context.Context) *Code
211200
block.Name = name
212201
}
213202

214-
if debug {
215-
logger.Debugf(ctx, "Block %s keys: %v", block.Name, maps.Keys(blockMap))
216-
}
203+
logger.Debugf(ctx, "Block %s keys: %v", block.Name, maps.Keys(blockMap))
217204

218-
block.Codes = parseCodes(blockMap, debug, logger, ctx)
205+
block.Codes = parseCodes(ctx, blockMap, logger)
219206

220207
if block.Name == "" && len(block.Codes) == 0 {
221208
return nil
@@ -225,7 +212,7 @@ func parseBlock(b any, debug bool, logger log.Logger, ctx context.Context) *Code
225212
}
226213

227214
// parseCodes parses the codes within a block.
228-
func parseCodes(blockMap map[string]any, debug bool, logger log.Logger, ctx context.Context) []*Code {
215+
func parseCodes(ctx context.Context, blockMap map[string]any, logger log.Logger) []*Code {
229216
codesRaw, ok := blockMap["codes"]
230217
if !ok {
231218
return nil
@@ -238,7 +225,7 @@ func parseCodes(blockMap map[string]any, debug bool, logger log.Logger, ctx cont
238225

239226
var codes []*Code
240227
for _, c := range codesSlice {
241-
if code := parseCode(c, debug, logger, ctx); code != nil {
228+
if code := parseCode(ctx, c, logger); code != nil {
242229
codes = append(codes, code)
243230
}
244231
}
@@ -247,7 +234,7 @@ func parseCodes(blockMap map[string]any, debug bool, logger log.Logger, ctx cont
247234
}
248235

249236
// parseCode parses a single code entry from a block.
250-
func parseCode(c any, debug bool, logger log.Logger, ctx context.Context) *Code {
237+
func parseCode(ctx context.Context, c any, logger log.Logger) *Code {
251238
codeMap := toStringMap(c)
252239
if codeMap == nil {
253240
return nil
@@ -258,15 +245,11 @@ func parseCode(c any, debug bool, logger log.Logger, ctx context.Context) *Code
258245
code.Name = name
259246
}
260247

261-
if debug {
262-
logger.Debugf(ctx, "Code %s keys: %v", code.Name, maps.Keys(codeMap))
263-
}
248+
logger.Debugf(ctx, "Code %s keys: %v", code.Name, maps.Keys(codeMap))
264249

265250
code.Script = parseScript(codeMap)
266251

267-
if debug {
268-
logger.Debugf(ctx, "Code %s script length: %d", code.Name, len(code.Script))
269-
}
252+
logger.Debugf(ctx, "Code %s script length: %d", code.Name, len(code.Script))
270253

271254
if code.Name == "" && code.Script == "" {
272255
return nil

internal/pkg/llm/twinformat/configparser/parser_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ func TestParseCodeBlocks(t *testing.T) {
573573
for _, tt := range tests {
574574
t.Run(tt.name, func(t *testing.T) {
575575
t.Parallel()
576-
result := ParseCodeBlocks(tt.params, false, logger, ctx)
576+
result := ParseCodeBlocks(ctx, tt.params, logger)
577577
assert.Equal(t, tt.expected, result)
578578
})
579579
}

internal/pkg/llm/twinformat/fetcher.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,34 +179,19 @@ func (f *Fetcher) FetchTransformationConfigs(ctx context.Context, branchID keboo
179179
}
180180

181181
configs = make([]*configparser.TransformationConfig, 0)
182-
debugCount := 0
183182
for _, comp := range *components {
184183
// Only process transformation components
185184
if !comp.IsTransformation() {
186185
continue
187186
}
188187

189188
for _, cfg := range comp.Configs {
190-
debug := debugCount < 3
191-
config := configparser.ParseTransformationConfig(comp.ID.String(), cfg, debug, f.logger, ctx)
189+
config := configparser.ParseTransformationConfig(ctx, comp.ID.String(), cfg, f.logger)
192190
if config == nil {
193191
continue
194192
}
195193

196194
configs = append(configs, config)
197-
198-
// Debug: Log parsing results for first few configs
199-
if !debug {
200-
continue
201-
}
202-
203-
codeCount := 0
204-
for _, b := range config.Blocks {
205-
codeCount += len(b.Codes)
206-
}
207-
f.logger.Debugf(ctx, "Transformation %s: %d inputs, %d outputs, %d blocks, %d codes",
208-
config.Name, len(config.InputTables), len(config.OutputTables), len(config.Blocks), codeCount)
209-
debugCount++
210195
}
211196
}
212197

0 commit comments

Comments
 (0)