From 0461d8ee2fd23ce395a69016fae9204ce6b7b904 Mon Sep 17 00:00:00 2001 From: Przemyslaw Delewski <102958445+pdelewski@users.noreply.github.com> Date: Thu, 24 Oct 2024 15:06:24 +0200 Subject: [PATCH] Using `UseCommonTableForWildcard`property for wildcard config (#917) This is PR to handle queries where following configuration is used (no explicit index configuration) ``` '*': useCommonTable: true target: [ my-clickhouse-data-source ] ``` --- quesma/quesma/schema_transformer.go | 6 ++++-- quesma/quesma/schema_transformer_test.go | 10 +++++----- quesma/quesma/search.go | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/quesma/quesma/schema_transformer.go b/quesma/quesma/schema_transformer.go index db7dc02a2..90446a2ce 100644 --- a/quesma/quesma/schema_transformer.go +++ b/quesma/quesma/schema_transformer.go @@ -16,7 +16,7 @@ import ( ) type SchemaCheckPass struct { - cfg map[string]config.IndexConfiguration + cfg *config.QuesmaConfiguration } func (s *SchemaCheckPass) applyBooleanLiteralLowering(index schema.Schema, query *model.Query) (*model.Query, error) { @@ -354,8 +354,10 @@ func (s *SchemaCheckPass) applyPhysicalFromExpression(currentSchema schema.Schem var useCommonTable bool if len(query.Indexes) == 1 { - if indexConf, ok := s.cfg[query.Indexes[0]]; ok { + if indexConf, ok := s.cfg.IndexConfig[query.Indexes[0]]; ok { useCommonTable = indexConf.UseCommonTable + } else if s.cfg.UseCommonTableForWildcard { + useCommonTable = true } } else { // we can handle querying multiple indexes from common table only useCommonTable = true diff --git a/quesma/quesma/schema_transformer_test.go b/quesma/quesma/schema_transformer_test.go index 949207a7e..bf2510f63 100644 --- a/quesma/quesma/schema_transformer_test.go +++ b/quesma/quesma/schema_transformer_test.go @@ -81,7 +81,7 @@ func Test_ipRangeTransform(t *testing.T) { TableName: "kibana_sample_data_logs_nested", FieldName: "nested.clientip"}: "nested_clientip", } s := schema.NewSchemaRegistry(tableDiscovery, &cfg, clickhouse.SchemaTypeAdapter{}) - transform := &SchemaCheckPass{cfg: indexConfig} + transform := &SchemaCheckPass{cfg: &cfg} s.UpdateFieldEncodings(fieldEncodings) selectColumns := []model.Expr{model.NewColumnRef("message")} @@ -430,7 +430,7 @@ func Test_arrayType(t *testing.T) { Fields: fields, } - transform := &SchemaCheckPass{cfg: indexConfig} + transform := &SchemaCheckPass{cfg: &config.QuesmaConfiguration{IndexConfig: indexConfig}} tests := []struct { name string @@ -607,7 +607,7 @@ func TestApplyWildCard(t *testing.T) { }, } - transform := &SchemaCheckPass{cfg: indexConfig} + transform := &SchemaCheckPass{cfg: &config.QuesmaConfiguration{IndexConfig: indexConfig}} tests := []struct { name string @@ -697,7 +697,7 @@ func TestApplyPhysicalFromExpression(t *testing.T) { td.Store(tableDefinition.Name, &tableDefinition) s := schema.NewSchemaRegistry(tableDiscovery, &cfg, clickhouse.SchemaTypeAdapter{}) - transform := &SchemaCheckPass{cfg: indexConfig} + transform := &SchemaCheckPass{cfg: &config.QuesmaConfiguration{IndexConfig: indexConfig}} tests := []struct { name string @@ -958,7 +958,7 @@ func TestFullTextFields(t *testing.T) { } s := schema.NewSchemaRegistry(tableDiscovery, &cfg, clickhouse.SchemaTypeAdapter{}) - transform := &SchemaCheckPass{cfg: indexConfig} + transform := &SchemaCheckPass{cfg: &config.QuesmaConfiguration{IndexConfig: indexConfig}} indexSchema, ok := s.FindSchema("test") if !ok { diff --git a/quesma/quesma/search.go b/quesma/quesma/search.go index d23c7cb5b..de7204654 100644 --- a/quesma/quesma/search.go +++ b/quesma/quesma/search.go @@ -81,7 +81,7 @@ func NewQueryRunner(lm *clickhouse.LogManager, AsyncQueriesContexts: async_search_storage.NewAsyncQueryContextStorageInMemory(), transformationPipeline: TransformationPipeline{ transformers: []model.QueryTransformer{ - &SchemaCheckPass{cfg: cfg.IndexConfig}, + &SchemaCheckPass{cfg: cfg}, }, }, schemaRegistry: schemaRegistry,