Skip to content

Commit f3923da

Browse files
Cleanup
1 parent fbd4760 commit f3923da

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

bundle/config/mutator/apply_presets.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ type applyPresets struct{}
2222

2323
// Apply all presets, e.g. the prefix presets that
2424
// adds a prefix to all names of all resources.
25-
// Note the catalog/schema presets are applied in ApplyPresetsCatalogSchema.
25+
//
26+
// Note that the catalog/schema presets are applied in ApplyPresetsCatalogSchema.
2627
func ApplyPresets() *applyPresets {
2728
return &applyPresets{}
2829
}

bundle/config/mutator/apply_presets_catalog_schema.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (m *applyPresetsCatalogSchema) Apply(ctx context.Context, b *bundle.Bundle)
3535
if p.Catalog == "" && p.Schema == "" {
3636
return diags
3737
}
38-
if (p.Schema == "") || (p.Catalog == "" && p.Schema != "") {
38+
if (p.Schema == "" && p.Catalog != "") || (p.Catalog == "" && p.Schema != "") {
3939
return diag.Diagnostics{{
4040
Summary: "presets.catalog and presets.schema must always be set together",
4141
Severity: diag.Error,
@@ -164,12 +164,12 @@ func (m *applyPresetsCatalogSchema) Apply(ctx context.Context, b *bundle.Bundle)
164164

165165
for i := range e.CreateServingEndpoint.Config.ServedEntities {
166166
e.CreateServingEndpoint.Config.ServedEntities[i].EntityName = fullyQualifyName(
167-
e.CreateServingEndpoint.Config.ServedEntities[i].EntityName, p.Catalog, p.Schema,
167+
e.CreateServingEndpoint.Config.ServedEntities[i].EntityName, p,
168168
)
169169
}
170170
for i := range e.CreateServingEndpoint.Config.ServedModels {
171171
e.CreateServingEndpoint.Config.ServedModels[i].ModelName = fullyQualifyName(
172-
e.CreateServingEndpoint.Config.ServedModels[i].ModelName, p.Catalog, p.Schema,
172+
e.CreateServingEndpoint.Config.ServedModels[i].ModelName, p,
173173
)
174174
}
175175
}
@@ -192,7 +192,7 @@ func (m *applyPresetsCatalogSchema) Apply(ctx context.Context, b *bundle.Bundle)
192192
if q.CreateMonitor == nil {
193193
continue
194194
}
195-
q.TableName = fullyQualifyName(q.TableName, p.Catalog, p.Schema)
195+
q.TableName = fullyQualifyName(q.TableName, p)
196196
if q.OutputSchemaName == "" {
197197
q.OutputSchemaName = p.Catalog + "." + p.Schema
198198
}
@@ -207,8 +207,6 @@ func (m *applyPresetsCatalogSchema) Apply(ctx context.Context, b *bundle.Bundle)
207207
s.CatalogName = p.Catalog
208208
}
209209
if s.Name == "" {
210-
// If there is a schema preset such as 'dev', we directly
211-
// use that name and don't add any prefix (which might result in dev_dev).
212210
s.Name = p.Schema
213211
}
214212
}
@@ -239,26 +237,19 @@ func addCatalogSchemaParameters(b *bundle.Bundle, key string, job *resources.Job
239237
diags = diags.Extend(diag.Diagnostics{{
240238
Summary: fmt.Sprintf("job %s already has 'schema' parameter defined; ignoring preset value", key),
241239
Severity: diag.Warning,
242-
Locations: []dyn.Location{b.Config.GetLocation("resources.jobs." + key)},
240+
Locations: []dyn.Location{b.Config.GetLocation("resources.jobs." + key + ".parameters")},
243241
}})
244242
}
245243
}
246244
}
247245

248-
// Initialize parameters if nil
249-
if job.Parameters == nil {
250-
job.Parameters = []jobs.JobParameterDefinition{}
251-
}
252-
253-
// Add catalog parameter if not already present
246+
// Add catalog/schema parameters
254247
if !hasCatalog {
255248
job.Parameters = append(job.Parameters, jobs.JobParameterDefinition{
256249
Name: "catalog",
257250
Default: p.Catalog,
258251
})
259252
}
260-
261-
// Add schema parameter if not already present
262253
if !hasSchema {
263254
job.Parameters = append(job.Parameters, jobs.JobParameterDefinition{
264255
Name: "schema",
@@ -329,14 +320,13 @@ func recommendCatalogSchemaUsage(b *bundle.Bundle, ctx context.Context, key stri
329320
}
330321

331322
return diags
332-
333323
}
334324

335325
// fullyQualifyName checks if the given name is already qualified with a catalog and schema.
336326
// If not, and both catalog and schema are available, it prefixes the name with catalog.schema.
337327
// If name is empty, returns name as-is.
338-
func fullyQualifyName(name, catalog, schema string) string {
339-
if name == "" || catalog == "" || schema == "" {
328+
func fullyQualifyName(name string, p config.Presets) string {
329+
if name == "" || p.Catalog == "" || p.Schema == "" {
340330
return name
341331
}
342332
// If it's already qualified (contains at least two '.'), we assume it's fully qualified.
@@ -346,10 +336,10 @@ func fullyQualifyName(name, catalog, schema string) string {
346336
return name
347337
}
348338
// Otherwise, fully qualify it
349-
return fmt.Sprintf("%s.%s.%s", catalog, schema, name)
339+
return fmt.Sprintf("%s.%s.%s", p.Catalog, p.Schema, name)
350340
}
351341

352-
func fileIncludesPattern(ctx context.Context, filePath string, expected string) bool {
342+
func fileIncludesPattern(ctx context.Context, filePath, expected string) bool {
353343
content, err := os.ReadFile(filePath)
354344
if err != nil {
355345
log.Warnf(ctx, "failed to check file %s: %v", filePath, err)

0 commit comments

Comments
 (0)