Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(query): Fix histogram query rewrite to exclude summaries #1887

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kamon.Kamon
import monix.execution.Scheduler

import filodb.core.{DatasetRef, GlobalConfig}
import filodb.core.memstore.PartLookupResult
import filodb.core.metadata.Schemas
import filodb.core.query.{ColumnFilter, QueryConfig, QueryContext, QuerySession, QueryWarnings}
import filodb.core.query.Filter.Equals
Expand Down Expand Up @@ -44,6 +45,8 @@ final case class MultiSchemaPartitionsExec(queryContext: QueryContext,
// Remove _columnName suffix from metricName and generate PartLookupResult
private def removeSuffixAndGenerateLookupResult(filters: Seq[ColumnFilter], metricName: String, columnName: String,
source: ChunkSource,
datasetRef: DatasetRef,
originalLookupResult: PartLookupResult,
querySession: QuerySession) = {
// Assume metric name has only equal filter
val filterWithoutColumn = filters.filterNot(_.column == metricColumn) :+
Expand All @@ -53,7 +56,15 @@ final case class MultiSchemaPartitionsExec(queryContext: QueryContext,
// clear stats since previous call to lookupPartitions set the stat with metric name that has suffix
querySession.queryStats.clear()
val lookupRes = source.lookupPartitions(dataset, partMethod, chunkMethod, querySession)
(lookupRes, Some(columnName))
// Accept only if lookupResult schema has a data column with name as the requested columnName.
// This is true generally for histogram queries where we rewrite the query to remove _sum, _count suffix.
// Check is needed since summaries are not columnized, and we don't want the rewrite to happen for summaries.
// If column does not exist, return original lookup result and don't change the query
val schemas = source.schemas(datasetRef).get
if (lookupRes.firstSchemaId.exists(s => schemas.apply(s).data.columns.exists(_.name == columnName)))
vishramachandran marked this conversation as resolved.
Show resolved Hide resolved
(lookupRes, Some(columnName))
else
(originalLookupResult, None)
}

/**
Expand Down Expand Up @@ -90,9 +101,9 @@ final case class MultiSchemaPartitionsExec(queryContext: QueryContext,
if (lookupRes.firstSchemaId.isEmpty && querySession.queryConfig.translatePromToFilodbHistogram &&
colName.isEmpty && metricName.isDefined) {
val res = if (metricName.get.endsWith("_sum"))
removeSuffixAndGenerateLookupResult(filters, metricName.get, "sum", source, querySession)
removeSuffixAndGenerateLookupResult(filters, metricName.get, "sum", source, dataset, lookupRes, querySession)
else if (metricName.get.endsWith("_count"))
removeSuffixAndGenerateLookupResult(filters, metricName.get, "count", source, querySession)
removeSuffixAndGenerateLookupResult(filters, metricName.get, "count", source, dataset, lookupRes, querySession)
else (lookupRes, newColName)

lookupRes = res._1
Expand Down
Loading