From bed128b03705757924775aa3756781d5bd554563 Mon Sep 17 00:00:00 2001 From: Przemek Delewski Date: Thu, 22 Aug 2024 17:18:37 +0200 Subject: [PATCH] Gather statistics #1 --- quesma/clickhouse/clickhouse.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/quesma/clickhouse/clickhouse.go b/quesma/clickhouse/clickhouse.go index bab19ab1b..349435465 100644 --- a/quesma/clickhouse/clickhouse.go +++ b/quesma/clickhouse/clickhouse.go @@ -497,14 +497,17 @@ func generateNonSchemaFieldsString(attrsMap map[string][]interface{}) (string, e // This function implements heuristic for deciding if we should add new columns func (lm *LogManager) shouldAlterColumns(table *Table, attrsMap map[string][]interface{}) bool { - _ = attrsMap + if len(table.Cols) < maxColumns { + return true + } if lm.ingestFieldStatistics == nil { lm.ingestFieldStatistics = make(IngestFieldStatistics) } - - lm.ingestFieldStatistics[IngestFieldBucketKey{indexName: table.Name, field: "test", insertBucket: 0}]++ - - return len(table.Cols) < maxColumns + attrKeys := getAttributesByArrayName(AttributesKeyColumn, attrsMap) + for _, field := range attrKeys { + lm.ingestFieldStatistics[IngestFieldBucketKey{indexName: table.Name, field: field, insertBucket: 0}]++ + } + return false } func (lm *LogManager) BuildIngestSQLStatements(tableName string, data types.JSON, inValidJson types.JSON,