This repository was archived by the owner on Nov 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Fix /*/_mapping and /*/_field_caps handling
#1475
Merged
nablaone
merged 10 commits into
main
from
que-278-quesma-request-failed-common-table-is-not-allowed-to-be
Jun 26, 2025
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8e5cf1c
Do not use table resolver on _mapping and _field_caps endpoints
nablaone 676af5e
filter common table
nablaone c97d266
Handle /*/_mappings
nablaone fb36190
We should use table resolver. Fallback to the elastic search depends …
nablaone afc7f27
Add Meta internal pipeline. It is similar to the Query pipeline, but …
nablaone c99026e
Add e2e test
nablaone 2be77f2
Don't stop on common_table
nablaone 8331c83
Extract function to filter common table index
nablaone 8989de3
Merge branch 'main' into que-278-quesma-request-failed-common-table-i…
nablaone 7527a51
Increase timeout
pdelewski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
ci/it/configs/quesma-common-table-and-regular-table.yml.template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| flags: | ||
| defaultStringColumnType: keyword | ||
| ingestStatistics: false | ||
|
|
||
| frontendConnectors: | ||
| - name: elastic-ingest | ||
| type: elasticsearch-fe-ingest | ||
| config: | ||
| listenPort: 8080 | ||
| disableAuth: true | ||
| - name: elastic-query | ||
| type: elasticsearch-fe-query | ||
| config: | ||
| listenPort: 8080 | ||
|
|
||
| backendConnectors: | ||
| - name: my-minimal-elasticsearch | ||
| type: elasticsearch | ||
| config: | ||
| url: "http://{{ .elasticsearch_host }}:{{ .elasticsearch_port }}" | ||
| user: elastic | ||
| password: quesmaquesma | ||
| - name: my-clickhouse-data-source | ||
| type: clickhouse-os | ||
| config: | ||
| url: clickhouse://{{ .clickhouse_host }}:{{ .clickhouse_port }} | ||
|
|
||
| processors: | ||
| - name: my-query-processor | ||
| type: quesma-v1-processor-query | ||
| config: | ||
| indexes: | ||
| first: | ||
| schemaOverrides: | ||
| fields: | ||
| "message": | ||
| type: text | ||
| target: | ||
| - my-clickhouse-data-source | ||
| second: | ||
| schemaOverrides: | ||
| fields: | ||
| "message": | ||
| type: text | ||
| target: | ||
| - my-clickhouse-data-source | ||
| third: | ||
| schemaOverrides: | ||
| fields: | ||
| "message": | ||
| type: text | ||
| target: | ||
| - my-clickhouse-data-source | ||
| "*": | ||
| useCommonTable: true | ||
| schemaOverrides: | ||
| fields: | ||
| "message": | ||
| type: text | ||
| target: | ||
| - my-clickhouse-data-source | ||
| - name: my-ingest-processor | ||
| type: quesma-v1-processor-ingest | ||
| config: | ||
| indexes: | ||
| first: | ||
| schemaOverrides: | ||
| fields: | ||
| "message": | ||
| type: text | ||
| target: | ||
| - my-clickhouse-data-source | ||
| second: | ||
| schemaOverrides: | ||
| fields: | ||
| "message": | ||
| type: text | ||
| target: | ||
| - my-clickhouse-data-source | ||
| third: | ||
| schemaOverrides: | ||
| fields: | ||
| "message": | ||
| type: text | ||
| target: | ||
| - my-clickhouse-data-source | ||
| "*": | ||
| useCommonTable: true | ||
| schemaOverrides: | ||
| fields: | ||
| "message": | ||
| type: text | ||
| target: | ||
| - my-clickhouse-data-source | ||
| pipelines: | ||
| - name: my-pipeline-elasticsearch-query-clickhouse | ||
| frontendConnectors: [elastic-query] | ||
| processors: [my-query-processor] | ||
| backendConnectors: [my-minimal-elasticsearch, my-clickhouse-data-source] | ||
| - name: my-pipeline-elasticsearch-ingest-to-clickhouse | ||
| frontendConnectors: [elastic-ingest] | ||
| processors: [my-ingest-processor] | ||
| backendConnectors: [my-minimal-elasticsearch, my-clickhouse-data-source] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| // Copyright Quesma, licensed under the Elastic License 2.0. | ||
| // SPDX-License-Identifier: Elastic-2.0 | ||
|
|
||
| package testcases | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "github.com/stretchr/testify/assert" | ||
| "sort" | ||
| "testing" | ||
| ) | ||
|
|
||
| type CommonTableAndRegularTable struct { | ||
| IntegrationTestcaseBase | ||
| } | ||
|
|
||
| func NewCommonTableAndRegularTable() *CommonTableAndRegularTable { | ||
| return &CommonTableAndRegularTable{ | ||
| IntegrationTestcaseBase: IntegrationTestcaseBase{ | ||
| ConfigTemplate: "quesma-common-table-and-regular-table.yml.template", | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (a *CommonTableAndRegularTable) SetupContainers(ctx context.Context) error { | ||
| containers, err := setupAllContainersWithCh(ctx, a.ConfigTemplate) | ||
| a.Containers = containers | ||
| return err | ||
| } | ||
|
|
||
| func (a *CommonTableAndRegularTable) RunTests(ctx context.Context, t *testing.T) error { | ||
|
|
||
| t.Run("all mappings", func(t *testing.T) { a.mappingsAll(ctx, t) }) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (a *CommonTableAndRegularTable) mappingsAll(ctx context.Context, t *testing.T) { | ||
|
|
||
| fetchStarFieldCaps := func() map[string]any { | ||
|
|
||
| resp, body := a.RequestToQuesma(ctx, t, "GET", "/*/_field_caps", nil) | ||
| if resp.StatusCode != 200 { | ||
| t.Fatalf("Failed to fetch mappings: %s", body) | ||
| } | ||
|
|
||
| var fieldCaps map[string]any | ||
| if err := json.Unmarshal(body, &fieldCaps); err != nil { | ||
| t.Fatalf("Failed to unmarshal mappings: %v", err) | ||
| } | ||
|
|
||
| return fieldCaps | ||
| } | ||
|
|
||
| fetchFieldCaps := func(index string) { | ||
|
|
||
| resp, body := a.RequestToQuesma(ctx, t, "GET", fmt.Sprintf("/%s/_field_caps", index), nil) | ||
| if resp.StatusCode != 200 { | ||
| t.Fatalf("Failed to fetch mappings: %s", body) | ||
| } | ||
|
|
||
| var fieldCaps map[string]any | ||
| if err := json.Unmarshal(body, &fieldCaps); err != nil { | ||
| t.Fatalf("Failed to unmarshal mappings: %v", err) | ||
| } | ||
| if len(fieldCaps) == 0 { | ||
| t.Fatalf("Expected field caps for index %s, got empty response", index) | ||
| } | ||
| } | ||
|
|
||
| checkFieldCaps := func(fieldCaps map[string]any, expectedIndexes []string) { | ||
|
|
||
| indicesAny, ok := fieldCaps["indices"].([]any) | ||
| if !ok { | ||
| t.Fatalf("Expected 'indices' to be a slice of strings, got: %T", fieldCaps["indices"]) | ||
| } | ||
|
|
||
| indices := make([]string, len(indicesAny)) | ||
| for i, index := range indicesAny { | ||
| indexStr, ok := index.(string) | ||
| if !ok { | ||
| t.Fatalf("Expected index to be a string, got: %T", index) | ||
| } | ||
| indices[i] = indexStr | ||
| } | ||
|
|
||
| assert.Equal(t, len(expectedIndexes), len(indices)) | ||
|
|
||
| sort.Strings(indices) | ||
| sort.Strings(expectedIndexes) | ||
|
|
||
| for i, index := range expectedIndexes { | ||
| assert.Equal(t, index, indices[i], fmt.Sprintf("Index %s should exist in field caps", index)) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| fetchStarMapping := func() map[string]any { | ||
|
|
||
| resp, body := a.RequestToQuesma(ctx, t, "GET", "/*/_mapping", nil) | ||
| if resp.StatusCode != 200 { | ||
| t.Fatalf("Failed to fetch mappings: %s", body) | ||
| } | ||
|
|
||
| var mappings map[string]any | ||
| if err := json.Unmarshal(body, &mappings); err != nil { | ||
| t.Fatalf("Failed to unmarshal mappings: %v", err) | ||
| } | ||
| return mappings | ||
| } | ||
|
|
||
| fetchMappings := func(index string) { | ||
| resp, body := a.RequestToQuesma(ctx, t, "GET", fmt.Sprintf("/%s/_mapping", index), nil) | ||
| if resp.StatusCode != 200 { | ||
| t.Fatalf("Failed to fetch mappings: %s", body) | ||
| } | ||
|
|
||
| var mappings map[string]any | ||
| if err := json.Unmarshal(body, &mappings); err != nil { | ||
| t.Fatalf("Failed to unmarshal mappings: %v", err) | ||
| } | ||
| if len(mappings) == 0 { | ||
| t.Fatalf("Expected mappings for index %s, got empty response", index) | ||
| } | ||
| } | ||
|
|
||
| checkMappings := func(mappings map[string]any, expectedIndexes []string) { | ||
|
|
||
| assert.Equal(t, len(expectedIndexes), len(mappings)) | ||
|
|
||
| for _, index := range expectedIndexes { | ||
| _, exists := mappings[index] | ||
| assert.True(t, exists, fmt.Sprintf("Index %s should exist in mappings", index)) | ||
| } | ||
| } | ||
|
|
||
| expectedIndexes := []string{"first", "second", "third"} // explicitly defined indexes in the config | ||
|
|
||
| mappings := fetchStarMapping() | ||
| checkMappings(mappings, expectedIndexes) | ||
|
|
||
| fieldCaps := fetchStarFieldCaps() | ||
| checkFieldCaps(fieldCaps, expectedIndexes) | ||
|
|
||
| for _, index := range expectedIndexes { | ||
| fetchFieldCaps(index) | ||
| fetchMappings(index) | ||
| } | ||
|
|
||
| // add a new index (common table) | ||
|
|
||
| a.RequestToQuesma(ctx, t, "POST", "/go_to_common_table/_doc", []byte(`{"name": "Przemyslaw", "age": 31337}`)) | ||
|
|
||
| expectedIndexes = append(expectedIndexes, "go_to_common_table") | ||
| mappings = fetchStarMapping() | ||
| checkMappings(mappings, expectedIndexes) | ||
|
|
||
| fieldCaps = fetchStarFieldCaps() | ||
| checkFieldCaps(fieldCaps, expectedIndexes) | ||
|
|
||
| for _, index := range expectedIndexes { | ||
| fetchFieldCaps(index) | ||
| fetchMappings(index) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,7 @@ | ||
| GET http://localhost:8080/kibana_sample_data_ecommerce/_mapping | ||
|
|
||
| #### | ||
| GET localhost:8080/*/_field_caps | ||
|
|
||
| ### | ||
| GET localhost:8080/*/_mapping |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same as below, it would be better to filter out
common_tableinResolveIndexPatternThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed