Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 295f0f8

Browse files
committed
Schema field source fixes
1 parent 18e8966 commit 295f0f8

File tree

6 files changed

+11
-8
lines changed

6 files changed

+11
-8
lines changed

quesma/ingest/alter_table_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ func TestAlterTable(t *testing.T) {
5151

5252
ip := newIngestProcessorWithEmptyTableMap(fieldsMap, &config.QuesmaConfiguration{})
5353
for i := range rowsToInsert {
54-
alter, _, onlySchemaFields, nonSchemaFields, err := ip.GenerateIngestContent(table, types.MustJSON(rowsToInsert[i]), nil, chConfig, encodings)
54+
alter, onlySchemaFields, nonSchemaFields, err := ip.GenerateIngestContent(table, types.MustJSON(rowsToInsert[i]), nil, chConfig, encodings)
5555
assert.NoError(t, err)
5656
insert, err := generateInsertJson(nonSchemaFields, onlySchemaFields)
5757
assert.Equal(t, expectedInsert[i], insert)
58-
assert.Equal(t, alters[i], alter[0])
58+
assert.Equal(t, alters[i], alter["Test1"])
5959
// Table will grow with each iteration
6060
assert.Equal(t, i+1, len(table.Cols))
6161
for _, col := range columns[:i+1] {
@@ -130,7 +130,7 @@ func TestAlterTableHeuristic(t *testing.T) {
130130

131131
assert.Equal(t, int64(0), ip.ingestCounter)
132132
for i := range rowsToInsert {
133-
_, _, _, _, err := ip.GenerateIngestContent(table, types.MustJSON(rowsToInsert[i]), nil, chConfig, encodings)
133+
_, _, _, err := ip.GenerateIngestContent(table, types.MustJSON(rowsToInsert[i]), nil, chConfig, encodings)
134134
assert.NoError(t, err)
135135
}
136136
assert.Equal(t, tc.expected, len(table.Cols))

quesma/ingest/processor.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,13 +761,15 @@ func (ip *IngestProcessor) processInsertQueryInternal(ctx context.Context, table
761761
var columnsFromDynamicMapping []string
762762
for _, field := range sourceIndexSchema.Fields {
763763
if _, ok := alterDDLMap[field.InternalPropertyName.AsString()]; !ok {
764+
764765
if field.Origin == schema.FieldSourceMapping {
765766
columnsFromDynamicMapping = append(columnsFromDynamicMapping, fmt.Sprintf("ALTER TABLE \"%s\" ADD COLUMN IF NOT EXISTS \"%s\" %s", tableName, field.InternalPropertyName, field.InternalPropertyType))
766767
metadata := comment_metadata.NewCommentMetadata()
767768
metadata.Values[comment_metadata.ElasticFieldName] = field.PropertyName.AsString()
768769
comment := metadata.Marshall()
769770
columnsFromDynamicMapping = append(columnsFromDynamicMapping, fmt.Sprintf("ALTER TABLE \"%s\" COMMENT COLUMN \"%s\" '%s'", tableName, field.InternalPropertyName, comment))
770771
}
772+
771773
}
772774
}
773775
statements = append(columnsFromDynamicMapping, statements...)

quesma/ingest/processor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func TestInsertNonSchemaFieldsToOthers_1(t *testing.T) {
7272
assert.True(t, exists)
7373
f := func(t1, t2 TableMap) {
7474
ip := newIngestProcessorWithEmptyTableMap(fieldsMap, &config.QuesmaConfiguration{})
75-
alter, _, onlySchemaFields, nonSchemaFields, err := ip.GenerateIngestContent(tableName, types.MustJSON(rowToInsert), nil, hasOthersConfig, encodings)
75+
alter, onlySchemaFields, nonSchemaFields, err := ip.GenerateIngestContent(tableName, types.MustJSON(rowToInsert), nil, hasOthersConfig, encodings)
7676
assert.NoError(t, err)
7777
j, err := generateInsertJson(nonSchemaFields, onlySchemaFields)
7878
assert.NoError(t, err)

quesma/quesma/schema_transformer.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,9 @@ func (s *SchemaCheckPass) applyWildcardExpansion(indexSchema schema.Schema, quer
463463

464464
cols := make([]string, 0, len(indexSchema.Fields))
465465
for _, col := range indexSchema.Fields {
466-
cols = append(cols, col.InternalPropertyName.AsString())
466+
if col.Origin == schema.FieldSourceIngest {
467+
cols = append(cols, col.InternalPropertyName.AsString())
468+
}
467469
}
468470
sort.Strings(cols)
469471

@@ -490,7 +492,7 @@ func (s *SchemaCheckPass) applyFullTextField(indexSchema schema.Schema, query *m
490492
var fullTextFields []string
491493

492494
for _, field := range indexSchema.Fields {
493-
if field.Type.IsFullText() {
495+
if field.Type.IsFullText() && field.Origin == schema.FieldSourceIngest {
494496
fullTextFields = append(fullTextFields, field.InternalPropertyName.AsString())
495497
}
496498
}

quesma/schema/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func (s *schemaRegistry) populateSchemaFromTableDefinition(definitions map[strin
246246
fields[propertyName] = Field{PropertyName: propertyName, InternalPropertyName: FieldName(column.Name), InternalPropertyType: column.Type, Type: QuesmaTypeKeyword}
247247
}
248248
} else {
249-
fields[propertyName] = Field{PropertyName: propertyName, InternalPropertyName: FieldName(column.Name), InternalPropertyType: column.Type, Type: existing.Type, Origin: existing.Origin}
249+
fields[propertyName] = Field{PropertyName: propertyName, InternalPropertyName: FieldName(column.Name), InternalPropertyType: column.Type, Type: existing.Type, Origin: FieldSourceIngest}
250250
}
251251
}
252252
}

quesma/schema/schema.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ type FieldSource int
1212
const (
1313
FieldSourceIngest FieldSource = iota
1414
FieldSourceMapping
15-
FieldSourceAutoDiscovery
1615
FieldSourceStaticConfiguration
1716
)
1817

0 commit comments

Comments
 (0)