From c5d5ebf3437ebcfeb94e9f23f19c24e7ad05b5f1 Mon Sep 17 00:00:00 2001 From: Przemyslaw Delewski <102958445+pdelewski@users.noreply.github.com> Date: Wed, 6 Nov 2024 11:48:34 +0100 Subject: [PATCH] Adding override as target property (#952) --- quesma/quesma/config/config_v2.go | 10 ++++++++++ quesma/quesma/config/config_v2_test.go | 12 +++++++++++- quesma/quesma/config/index_config.go | 2 +- .../config/test_configs/target_new_variant.yaml | 8 ++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/quesma/quesma/config/config_v2.go b/quesma/quesma/config/config_v2.go index 92ccaaf8c..b919153c9 100644 --- a/quesma/quesma/config/config_v2.go +++ b/quesma/quesma/config/config_v2.go @@ -598,6 +598,10 @@ func (c *QuesmaNewConfiguration) TranslateToLegacyConfig() QuesmaConfiguration { if val, exists := target.properties["useCommonTable"]; exists { processedConfig.UseCommonTable = val == "true" } + if val, exists := target.properties["tableName"]; exists { + processedConfig.Override = val.(string) + } + } if len(processedConfig.QueryTarget) == 2 && !((processedConfig.QueryTarget[0] == ClickhouseTarget && processedConfig.QueryTarget[1] == ElasticsearchTarget) || (processedConfig.QueryTarget[0] == ElasticsearchTarget && processedConfig.QueryTarget[1] == ClickhouseTarget)) { @@ -718,6 +722,9 @@ func (c *QuesmaNewConfiguration) TranslateToLegacyConfig() QuesmaConfiguration { if val, exists := target.properties["useCommonTable"]; exists { processedConfig.UseCommonTable = val == true } + if val, exists := target.properties["tableName"]; exists { + processedConfig.Override = val.(string) + } } if len(processedConfig.QueryTarget) == 2 && !((processedConfig.QueryTarget[0] == ClickhouseTarget && processedConfig.QueryTarget[1] == ElasticsearchTarget) || (processedConfig.QueryTarget[0] == ElasticsearchTarget && processedConfig.QueryTarget[1] == ClickhouseTarget)) { @@ -764,6 +771,9 @@ func (c *QuesmaNewConfiguration) TranslateToLegacyConfig() QuesmaConfiguration { if val, exists := target.properties["useCommonTable"]; exists { processedConfig.UseCommonTable = val == true } + if val, exists := target.properties["tableName"]; exists { + processedConfig.Override = val.(string) + } } conf.IndexConfig[indexName] = processedConfig } diff --git a/quesma/quesma/config/config_v2_test.go b/quesma/quesma/config/config_v2_test.go index b61ea7843..5ff2fb366 100644 --- a/quesma/quesma/config/config_v2_test.go +++ b/quesma/quesma/config/config_v2_test.go @@ -238,10 +238,11 @@ func TestTargetNewVariant(t *testing.T) { } legacyConf := cfg.TranslateToLegacyConfig() assert.False(t, legacyConf.TransparentProxy) - assert.Equal(t, 3, len(legacyConf.IndexConfig)) + assert.Equal(t, 4, len(legacyConf.IndexConfig)) ecommerce := legacyConf.IndexConfig["kibana_sample_data_ecommerce"] flights := legacyConf.IndexConfig["kibana_sample_data_flights"] logs := legacyConf.IndexConfig["kibana_sample_data_logs"] + override := legacyConf.IndexConfig["test_override"] assert.Equal(t, []string{ClickhouseTarget}, ecommerce.QueryTarget) assert.Equal(t, []string{ClickhouseTarget}, ecommerce.IngestTarget) @@ -252,8 +253,17 @@ func TestTargetNewVariant(t *testing.T) { assert.Equal(t, []string{ClickhouseTarget}, logs.QueryTarget) assert.Equal(t, []string{ClickhouseTarget}, logs.IngestTarget) + assert.Equal(t, []string{ClickhouseTarget}, override.QueryTarget) + assert.Equal(t, []string{ClickhouseTarget}, override.IngestTarget) + assert.Equal(t, false, flights.UseCommonTable) + assert.Equal(t, "", flights.Override) assert.Equal(t, false, ecommerce.UseCommonTable) + assert.Equal(t, "", ecommerce.Override) assert.Equal(t, true, logs.UseCommonTable) + assert.Equal(t, "", logs.Override) assert.Equal(t, true, legacyConf.EnableIngest) + + const expectedOverride = "new_override" + assert.Equal(t, expectedOverride, override.Override) } diff --git a/quesma/quesma/config/index_config.go b/quesma/quesma/config/index_config.go index d5980cf5c..9b8b04046 100644 --- a/quesma/quesma/config/index_config.go +++ b/quesma/quesma/config/index_config.go @@ -16,7 +16,7 @@ const ( type IndexConfiguration struct { SchemaOverrides *SchemaConfiguration `koanf:"schemaOverrides"` Optimizers map[string]OptimizerConfiguration `koanf:"optimizers"` - Override string `koanf:"override"` + Override string `koanf:"tableName"` UseCommonTable bool `koanf:"useCommonTable"` Target any `koanf:"target"` diff --git a/quesma/quesma/config/test_configs/target_new_variant.yaml b/quesma/quesma/config/test_configs/target_new_variant.yaml index 127deb721..8f907518a 100644 --- a/quesma/quesma/config/test_configs/target_new_variant.yaml +++ b/quesma/quesma/config/test_configs/target_new_variant.yaml @@ -40,6 +40,10 @@ processors: target: - my-clickhouse-data-source: useCommonTable: true + "test_override": + target: + - my-clickhouse-data-source: + tableName: "new_override" "*": target: [ my-minimal-elasticsearch ] @@ -58,6 +62,10 @@ processors: target: - my-clickhouse-data-source: useCommonTable: true + "test_override": + target: + - my-clickhouse-data-source: + tableName: "new_override" "*": target: [ my-minimal-elasticsearch ] pipelines: