SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
chore: align usage of negative operators in JSON Body (#10758)
Piyush Singariya72ce8768b31b
diff --git a/pkg/querybuilder/fallback_expr.go b/pkg/querybuilder/fallback_expr.goindex 787d9110b4..aaab790f6f 100644--- a/pkg/querybuilder/fallback_expr.go+++ b/pkg/querybuilder/fallback_expr.go@@ -211,6 +211,8 @@ func DataTypeCollisionHandledFieldName(key *telemetrytypes.TelemetryFieldKey, vacase float64:// try to convert the string value to to numbertblFieldName = castFloat(tblFieldName)+ case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:+ tblFieldName = castFloat(tblFieldName)case []any:if allFloats(v) {tblFieldName = castFloat(tblFieldName)@@ -277,6 +279,18 @@ func DataTypeCollisionHandledFieldName(key *telemetrytypes.TelemetryFieldKey, vatblFieldName, value = castString(tblFieldName), toStrings(v)}}+ case telemetrytypes.FieldDataTypeArrayDynamic:+ switch v := value.(type) {+ case string:+ tblFieldName = castString(tblFieldName)+ case float32, float64, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:+ tblFieldName = accurateCastFloat(tblFieldName)+ case bool:+ tblFieldName = castBool(tblFieldName)+ case []any:+ // dynamic array elements will be default casted to string+ tblFieldName, value = castString(tblFieldName), toStrings(v)+ }}return tblFieldName, value}@@ -284,6 +298,10 @@ func DataTypeCollisionHandledFieldName(key *telemetrytypes.TelemetryFieldKey, vafunc castFloat(col string) string { return fmt.Sprintf("toFloat64OrNull(%s)", col) }func castFloatHack(col string) string { return fmt.Sprintf("toFloat64(%s)", col) }func castString(col string) string { return fmt.Sprintf("toString(%s)", col) }+func castBool(col string) string { return fmt.Sprintf("accurateCastOrNull(%s, 'Bool')", col) }+func accurateCastFloat(col string) string {+ return fmt.Sprintf("accurateCastOrNull(%s, 'Float64')", col)+}func allFloats(in []any) bool {for _, x := range in {diff --git a/pkg/telemetrylogs/json_condition_builder.go b/pkg/telemetrylogs/json_condition_builder.goindex 00edfc26be..b25795900b 100644--- a/pkg/telemetrylogs/json_condition_builder.go+++ b/pkg/telemetrylogs/json_condition_builder.go@@ -3,6 +3,7 @@ package telemetrylogsimport ("fmt""slices"+ "strings"schemamigrator "github.com/SigNoz/signoz-otel-collector/cmd/signozschemamigrator/schema_migrator""github.com/SigNoz/signoz/pkg/errors"@@ -33,158 +34,279 @@ func NewJSONConditionBuilder(key *telemetrytypes.TelemetryFieldKey, valueType te// BuildCondition builds the full WHERE condition for body_v2 JSON paths.func (c *jsonConditionBuilder) buildJSONCondition(operator qbtypes.FilterOperator, value any, sb *sqlbuilder.SelectBuilder) (string, error) {- conditions := []string{}- for _, node := range c.key.JSONPlan {- condition, err := c.emitPlannedCondition(node, operator, value, sb)- if err != nil {- return "", err- }- conditions = append(conditions, condition)+ baseCond, err := c.emitPlannedCondition(operator, value, sb)+ if err != nil {+ return "", err}- baseCond := sb.Or(conditions...)// path indexif operator.AddDefaultExistsFilter() {pathIndex := fmt.Sprintf(`has(%s, '%s')`, schemamigrator.JSONPathsIndexExpr(LogsV2BodyV2Column), c.key.ArrayParentPaths()[0])return sb.And(baseCond, pathIndex), nil}+return baseCond, nil}-// emitPlannedCondition handles paths with array traversal.-func (c *jsonConditionBuilder) emitPlannedCondition(node *telemetrytypes.JSONAccessNode, operator qbtypes.FilterOperator, value any, sb *sqlbuilder.SelectBuilder) (string, error) {+func (c *jsonConditionBuilder) emitPlannedCondition(operator qbtypes.FilterOperator, value any, sb *sqlbuilder.SelectBuilder) (string, error) {// Build traversal + terminal recursively per-hop- compiled, err := c.recurseArrayHops(node, operator, value, sb)+ conditions := []string{}+ for _, node := range c.key.JSONPlan {+ condition, err := c.recurseArrayHops(node, operator, value, sb)+ if err != nil {+ return "", err+ }+ conditions = append(conditions, condition)+ }++ return sb.Or(conditions...), nil+}++func (c *jsonConditionBuilder) recurseArrayHops(current *telemetrytypes.JSONAccessNode, operator qbtypes.FilterOperator, value any, sb *sqlbuilder.SelectBuilder) (string, error) {+ if current == nil {+ return "", errors.NewInternalf(CodeArrayNavigationFailed, "navigation failed, current node is nil")+ }++ if current.IsTerminal {+ terminalCond, err := c.buildTerminalCondition(current, operator, value, sb)+ if err != nil {+ return "", err+ }+ return terminalCond, nil+ }++ // apply NOT at top level arrayExists so that any subsequent arrayExists fails we count it as true (matching log)+ yes, operator := applyNotCondition(operator)+ condition, err := c.buildAccessNodeBranches(current, operator, value, sb)if err != nil {return "", err}- return compiled, nil++ if yes {+ return sb.Not(condition), nil+ }++ return condition, nil}-// buildTerminalCondition creates the innermost condition.-func (c *jsonConditionBuilder) buildTerminalCondition(node *telemetrytypes.JSONAccessNode, operator qbtypes.FilterOperator, value any, sb *sqlbuilder.SelectBuilder) (string, error) {- if node.TerminalConfig.ElemType.IsArray {- conditions := []string{}- // if the value type is not an array- // TODO(piyush): Confirm the Query built for Array case and add testcases for it later- if !c.valueType.IsArray {- // if operator is a String search Operator, then we need to build one more String comparison condition along with the Strict match condition- if operator.IsStringSearchOperator() {- formattedValue := querybuilder.FormatValueForContains(value)- arrayCond, err := c.buildArrayMembershipCondition(node, operator, formattedValue, sb)- if err != nil {- return "", err- }- conditions = append(conditions, arrayCond)- }+func applyNotCondition(operator qbtypes.FilterOperator) (bool, qbtypes.FilterOperator) {+ if operator.IsNegativeOperator() {+ return true, operator.Inverse()+ }+ return false, operator+}- // switch operator for array membership checks- switch operator {- case qbtypes.FilterOperatorContains:- operator = qbtypes.FilterOperatorEqual- case qbtypes.FilterOperatorNotContains:- operator = qbtypes.FilterOperatorNotEqual- }+// buildAccessNodeBranches builds conditions for each branch of the access node.+func (c *jsonConditionBuilder) buildAccessNodeBranches(current *telemetrytypes.JSONAccessNode, operator qbtypes.FilterOperator, value any, sb *sqlbuilder.SelectBuilder) (string, error) {+ if current == nil {+ return "", errors.NewInternalf(CodeArrayNavigationFailed, "navigation failed, current node is nil")+ }++ currAlias := current.Alias()+ fieldPath := current.FieldPath()+ // Determine availability of Array(JSON) and Array(Dynamic) at this hop+ hasArrayJSON := current.Branches[telemetrytypes.BranchJSON] != nil+ hasArrayDynamic := current.Branches[telemetrytypes.BranchDynamic] != nil++ // Then, at this hop, compute child per branch and wrap+ branches := make([]string, 0, 2)+ if hasArrayJSON {+ jsonArrayExpr := fmt.Sprintf("dynamicElement(%s, 'Array(JSON(max_dynamic_types=%d, max_dynamic_paths=%d))')", fieldPath, current.MaxDynamicTypes, current.MaxDynamicPaths)+ childGroupJSON, err := c.recurseArrayHops(current.Branches[telemetrytypes.BranchJSON], operator, value, sb)+ if err != nil {+ return "", err}+ branches = append(branches, fmt.Sprintf("arrayExists(%s-> %s, %s)", currAlias, childGroupJSON, jsonArrayExpr))+ }+ if hasArrayDynamic {+ dynBaseExpr := fmt.Sprintf("dynamicElement(%s, 'Array(Dynamic)')", fieldPath)+ dynFilteredExpr := fmt.Sprintf("arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), %s))", dynBaseExpr)- arrayCond, err := c.buildArrayMembershipCondition(node, operator, value, sb)+ // Create the Query for Dynamic array+ childGroupDyn, err := c.recurseArrayHops(current.Branches[telemetrytypes.BranchDynamic], operator, value, sb)if err != nil {return "", err}- conditions = append(conditions, arrayCond)- // or the conditions together- return sb.Or(conditions...), nil+ branches = append(branches, fmt.Sprintf("arrayExists(%s-> %s, %s)", currAlias, childGroupDyn, dynFilteredExpr))+ }++ if len(branches) == 1 {+ return branches[0], nil+ }+ return sb.Or(branches...), nil+}++// buildTerminalCondition creates the innermost condition.+func (c *jsonConditionBuilder) buildTerminalCondition(node *telemetrytypes.JSONAccessNode, operator qbtypes.FilterOperator, value any, sb *sqlbuilder.SelectBuilder) (string, error) {+ if node.TerminalConfig.ElemType.IsArray {+ // Note: here applyNotCondition will return true only if; top level path is an array; and operator is a negative operator+ // Otherwise this code will be triggered by buildAccessNodeBranches; Where operator would've been already inverted if needed.+ yes, operator := applyNotCondition(operator)+ cond, err := c.buildTerminalArrayCondition(node, operator, value, sb)+ if err != nil {+ return "", err+ }++ if yes {+ return sb.Not(cond), nil+ }+ return cond, nil}return c.buildPrimitiveTerminalCondition(node, operator, value, sb)}+func getEmptyValue(elemType telemetrytypes.JSONDataType) any {+ switch elemType {+ case telemetrytypes.String:+ return ""+ case telemetrytypes.Int64, telemetrytypes.Float64, telemetrytypes.Bool:+ return 0+ default:+ return nil+ }+}++func (c *jsonConditionBuilder) terminalIndexedCondition(node *telemetrytypes.JSONAccessNode, operator qbtypes.FilterOperator, value any, sb *sqlbuilder.SelectBuilder) (string, error) {+ fieldPath := node.FieldPath()+ if strings.Contains(fieldPath, telemetrytypes.ArraySepSuffix) {+ return "", errors.NewInternalf(CodeArrayNavigationFailed, "can not build index condition for array field %s", fieldPath)+ }++ elemType := node.TerminalConfig.ElemType+ dynamicExpr := fmt.Sprintf("dynamicElement(%s, '%s')", fieldPath, elemType.StringValue())+ indexedExpr := assumeNotNull(dynamicExpr)++ // switch the operator and value for exists and not exists+ switch operator {+ case qbtypes.FilterOperatorExists:+ operator = qbtypes.FilterOperatorNotEqual+ value = getEmptyValue(elemType)+ case qbtypes.FilterOperatorNotExists:+ operator = qbtypes.FilterOperatorEqual+ value = getEmptyValue(elemType)+ default:+ // do nothing+ }++ indexedExpr, formattedValue := querybuilder.DataTypeCollisionHandledFieldName(node.TerminalConfig.Key, value, indexedExpr, operator)+ cond, err := c.applyOperator(sb, indexedExpr, operator, formattedValue)+ if err != nil {+ return "", err+ }++ return cond, nil+}+// buildPrimitiveTerminalCondition builds the condition if the terminal node is a primitive type// it handles the data type collisions and utilizes indexes for the condition if available.func (c *jsonConditionBuilder) buildPrimitiveTerminalCondition(node *telemetrytypes.JSONAccessNode, operator qbtypes.FilterOperator, value any, sb *sqlbuilder.SelectBuilder) (string, error) {fieldPath := node.FieldPath()conditions := []string{}++ // utilize indexes for the condition if available+ //+ // Note: Indexing code doesn't get executed for Array Nested fields because they can not be indexed+ indexed := slices.ContainsFunc(node.TerminalConfig.Key.Indexes, func(index telemetrytypes.JSONDataTypeIndex) bool {+ return index.Type == node.TerminalConfig.ElemType+ })+ if node.TerminalConfig.ElemType.IndexSupported && indexed {+ indexCond, err := c.terminalIndexedCondition(node, operator, value, sb)+ if err != nil {+ return "", err+ }+ // if qb has a definitive value, we can skip adding a condition to+ // check the existence of the path in the json column+ if value != nil && value != getEmptyValue(node.TerminalConfig.ElemType) {+ return indexCond, nil+ }++ conditions = append(conditions, indexCond)++ // Switch operator to EXISTS except when operator is NOT EXISTS since+ // indexed paths on assumedNotNull, indexes will always have a default+ // value so we flip the operator to Exists and filter the rows that+ // actually have the value+ if operator != qbtypes.FilterOperatorNotExists {+ operator = qbtypes.FilterOperatorExists+ }+ }+var formattedValue = valueif operator.IsStringSearchOperator() {formattedValue = querybuilder.FormatValueForContains(value)}- elemType := node.TerminalConfig.ElemType- fieldExpr := fmt.Sprintf("dynamicElement(%s, '%s')", fieldPath, elemType.StringValue())- fieldExpr, formattedValue = querybuilder.DataTypeCollisionHandledFieldName(node.TerminalConfig.Key, formattedValue, fieldExpr, operator)+ fieldExpr := fmt.Sprintf("dynamicElement(%s, '%s')", fieldPath, node.TerminalConfig.ElemType.StringValue())- // utilize indexes for the condition if available- indexed := slices.ContainsFunc(node.TerminalConfig.Key.Indexes, func(index telemetrytypes.JSONDataTypeIndex) bool {- return index.Type == elemType && index.ColumnExpression == fieldPath- })- if elemType.IndexSupported && indexed {- indexedExpr := assumeNotNull(fieldPath, elemType)- emptyValue := func() any {- switch elemType {- case telemetrytypes.String:- return ""- case telemetrytypes.Int64, telemetrytypes.Float64, telemetrytypes.Bool:- return 0+ // if operator is negative and has a value comparison i.e. excluding EXISTS and NOT EXISTS, we need to assume that the field exists everywhere+ //+ // Note: here applyNotCondition will return true only if; top level path is being queried and operator is a negative operator+ // Otherwise this code will be triggered by buildAccessNodeBranches; Where operator would've been already inverted if needed.+ if node.IsNonNestedPath() {+ yes, _ := applyNotCondition(operator)+ if yes {+ switch operator {+ case qbtypes.FilterOperatorNotExists:+ // skipdefault:- return nil+ fieldExpr = assumeNotNull(fieldExpr)}- }()-- // switch the operator and value for exists and not exists- switch operator {- case qbtypes.FilterOperatorExists:- operator = qbtypes.FilterOperatorNotEqual- value = emptyValue- case qbtypes.FilterOperatorNotExists:- operator = qbtypes.FilterOperatorEqual- value = emptyValue- default:- // do nothing}+ }++ fieldExpr, formattedValue = querybuilder.DataTypeCollisionHandledFieldName(node.TerminalConfig.Key, formattedValue, fieldExpr, operator)+ cond, err := c.applyOperator(sb, fieldExpr, operator, formattedValue)+ if err != nil {+ return "", err+ }+ conditions = append(conditions, cond)+ if len(conditions) > 1 {+ return sb.And(conditions...), nil+ }+ return conditions[0], nil+}- indexedExpr, indexedComparisonValue := querybuilder.DataTypeCollisionHandledFieldName(node.TerminalConfig.Key, formattedValue, indexedExpr, operator)- cond, err := c.applyOperator(sb, indexedExpr, operator, indexedComparisonValue)+func (c *jsonConditionBuilder) buildTerminalArrayCondition(node *telemetrytypes.JSONAccessNode, operator qbtypes.FilterOperator, value any, sb *sqlbuilder.SelectBuilder) (string, error) {+ conditions := []string{}+ // if operator is a String search Operator, then we need to build one more String comparison condition along with the Strict match condition+ if operator.IsStringSearchOperator() {+ formattedValue := querybuilder.FormatValueForContains(value)+ arrayCond, err := c.buildArrayMembershipCondition(node, operator, formattedValue, sb)if err != nil {return "", err}+ conditions = append(conditions, arrayCond)- // if qb has a definitive value, we can skip adding a condition to- // check the existence of the path in the json column- if value != emptyValue {- return cond, nil+ // switch operator for array membership checks+ switch operator {+ case qbtypes.FilterOperatorContains:+ operator = qbtypes.FilterOperatorEqual+ case qbtypes.FilterOperatorNotContains:+ operator = qbtypes.FilterOperatorNotEqual}-- conditions = append(conditions, cond)- // Switch operator to EXISTS since indexed paths on assumedNotNull, indexes will always have a default value- // So we flip the operator to Exists and filter the rows that actually have the value- operator = qbtypes.FilterOperatorExists}- cond, err := c.applyOperator(sb, fieldExpr, operator, formattedValue)+ arrayCond, err := c.buildArrayMembershipCondition(node, operator, value, sb)if err != nil {return "", err}- conditions = append(conditions, cond)+ conditions = append(conditions, arrayCond)if len(conditions) > 1 {- return sb.And(conditions...), nil+ return sb.Or(conditions...), nil}+return conditions[0], nil}-// buildArrayMembershipCondition handles array membership checks.+// buildArrayMembershipCondition builds condition of the part where Arrays becomes primitive typed Arrays+// e.g. [300, 404, 500], and value operations will work on the array elements.func (c *jsonConditionBuilder) buildArrayMembershipCondition(node *telemetrytypes.JSONAccessNode, operator qbtypes.FilterOperator, value any, sb *sqlbuilder.SelectBuilder) (string, error) {arrayPath := node.FieldPath()- localKeyCopy := *node.TerminalConfig.Key// create typed array out of a dynamic arrayfilteredDynamicExpr := func() string {- // Change the field data type from []dynamic to the value type- // since we've filtered the value type out of the dynamic array, we need to change the field data corresponding to the value type- localKeyCopy.FieldDataType = telemetrytypes.MappingJSONDataTypeToFieldDataType[telemetrytypes.ScalerTypeToArrayType[c.valueType]]-baseArrayDynamicExpr := fmt.Sprintf("dynamicElement(%s, 'Array(Dynamic)')", arrayPath)- return fmt.Sprintf("arrayMap(x->dynamicElement(x, '%s'), arrayFilter(x->(dynamicType(x) = '%s'), %s))",- c.valueType.StringValue(),- c.valueType.StringValue(),+ return fmt.Sprintf("arrayFilter(x->(dynamicType(x) IN ('String', 'Int64', 'Float64', 'Bool')), %s)",baseArrayDynamicExpr)}typedArrayExpr := func() string {@@ -199,7 +321,7 @@ func (c *jsonConditionBuilder) buildArrayMembershipCondition(node *telemetrytype}key := "x"- fieldExpr, value := querybuilder.DataTypeCollisionHandledFieldName(&localKeyCopy, value, key, operator)+ fieldExpr, value := querybuilder.DataTypeCollisionHandledFieldName(node.TerminalConfig.Key, value, key, operator)op, err := c.applyOperator(sb, fieldExpr, operator, value)if err != nil {return "", err@@ -208,54 +330,6 @@ func (c *jsonConditionBuilder) buildArrayMembershipCondition(node *telemetrytypereturn fmt.Sprintf("arrayExists(%s -> %s, %s)", key, op, arrayExpr), nil}-// recurseArrayHops recursively builds array traversal conditions.-func (c *jsonConditionBuilder) recurseArrayHops(current *telemetrytypes.JSONAccessNode, operator qbtypes.FilterOperator, value any, sb *sqlbuilder.SelectBuilder) (string, error) {- if current == nil {- return "", errors.NewInternalf(CodeArrayNavigationFailed, "navigation failed, current node is nil")- }-- if current.IsTerminal {- terminalCond, err := c.buildTerminalCondition(current, operator, value, sb)- if err != nil {- return "", err- }- return terminalCond, nil- }-- currAlias := current.Alias()- fieldPath := current.FieldPath()- // Determine availability of Array(JSON) and Array(Dynamic) at this hop- hasArrayJSON := current.Branches[telemetrytypes.BranchJSON] != nil- hasArrayDynamic := current.Branches[telemetrytypes.BranchDynamic] != nil-- // Then, at this hop, compute child per branch and wrap- branches := make([]string, 0, 2)- if hasArrayJSON {- jsonArrayExpr := fmt.Sprintf("dynamicElement(%s, 'Array(JSON(max_dynamic_types=%d, max_dynamic_paths=%d))')", fieldPath, current.MaxDynamicTypes, current.MaxDynamicPaths)- childGroupJSON, err := c.recurseArrayHops(current.Branches[telemetrytypes.BranchJSON], operator, value, sb)- if err != nil {- return "", err- }- branches = append(branches, fmt.Sprintf("arrayExists(%s-> %s, %s)", currAlias, childGroupJSON, jsonArrayExpr))- }- if hasArrayDynamic {- dynBaseExpr := fmt.Sprintf("dynamicElement(%s, 'Array(Dynamic)')", fieldPath)- dynFilteredExpr := fmt.Sprintf("arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), %s))", dynBaseExpr)-- // Create the Query for Dynamic array- childGroupDyn, err := c.recurseArrayHops(current.Branches[telemetrytypes.BranchDynamic], operator, value, sb)- if err != nil {- return "", err- }- branches = append(branches, fmt.Sprintf("arrayExists(%s-> %s, %s)", currAlias, childGroupDyn, dynFilteredExpr))- }-- if len(branches) == 1 {- return branches[0], nil- }- return sb.Or(branches...), nil-}-func (c *jsonConditionBuilder) applyOperator(sb *sqlbuilder.SelectBuilder, fieldExpr string, operator qbtypes.FilterOperator, value any) (string, error) {switch operator {case qbtypes.FilterOperatorEqual:@@ -317,6 +391,6 @@ func (c *jsonConditionBuilder) applyOperator(sb *sqlbuilder.SelectBuilder, field}}-func assumeNotNull(column string, elemType telemetrytypes.JSONDataType) string {- return fmt.Sprintf("assumeNotNull(dynamicElement(%s, '%s'))", column, elemType.StringValue())+func assumeNotNull(fieldExpr string) string {+ return fmt.Sprintf("assumeNotNull(%s)", fieldExpr)}diff --git a/pkg/telemetrylogs/json_stmt_builder_test.go b/pkg/telemetrylogs/json_stmt_builder_test.goindex 4945b70513..014b20a0e8 100644--- a/pkg/telemetrylogs/json_stmt_builder_test.go+++ b/pkg/telemetrylogs/json_stmt_builder_test.go@@ -2,9 +2,12 @@ package telemetrylogsimport ("context"+ "slices"+ "strings""testing""time"+ schemamigrator "github.com/SigNoz/signoz-otel-collector/cmd/signozschemamigrator/schema_migrator""github.com/SigNoz/signoz/pkg/instrumentation/instrumentationtest""github.com/SigNoz/signoz/pkg/querybuilder"qbtypes "github.com/SigNoz/signoz/pkg/types/querybuildertypes/querybuildertypesv5"@@ -13,11 +16,26 @@ import ("github.com/stretchr/testify/require")-func TestStmtBuilderTimeSeriesBodyGroupByJSON(t *testing.T) {+const (+ testJSONQueryPrefix = "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND"+ testJSONQuerySuffix = "AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?"+)++type TestExpected struct {+ WhereClause string+ Args []any+ Warnings []string+}++func (t TestExpected) GetQuery() string {+ return strings.Join([]string{testJSONQueryPrefix, t.WhereClause, testJSONQuerySuffix}, " ")+}++func TestJSONStmtBuilder_TimeSeries(t *testing.T) {enable, disable := jsonQueryTestUtil(t)enable()defer disable()- statementBuilder := buildJSONTestStatementBuilder(t)+ statementBuilder := buildJSONTestStatementBuilder(t, false)cases := []struct {name string@@ -135,7 +153,6 @@ func TestStmtBuilderTimeSeriesBodyGroupByPromoted(t *testing.T) {},},expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?), __limit_cte AS (SELECT toString(multiIf((dynamicElement(body_v2.`user.age`, 'Int64') IS NOT NULL OR dynamicElement(body_promoted.`user.age`, 'Int64') IS NOT NULL), toString(coalesce(dynamicElement(body_promoted.`user.age`, 'Int64'), dynamicElement(body_v2.`user.age`, 'Int64'))), (dynamicElement(body_v2.`user.age`, 'String') IS NOT NULL OR dynamicElement(body_promoted.`user.age`, 'String') IS NOT NULL), coalesce(dynamicElement(body_promoted.`user.age`, 'String'), dynamicElement(body_v2.`user.age`, 'String')), NULL)) AS `user.age`, toString(multiIf((dynamicElement(body_v2.`user.name`, 'String') IS NOT NULL OR dynamicElement(body_promoted.`user.name`, 'String') IS NOT NULL), coalesce(dynamicElement(body_promoted.`user.name`, 'String'), dynamicElement(body_v2.`user.name`, 'String')), NULL)) AS `user.name`, count() AS __result_0 FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? GROUP BY `user.age`, `user.name` ORDER BY __result_0 DESC LIMIT ?) SELECT toStartOfInterval(fromUnixTimestamp64Nano(timestamp), INTERVAL 30 SECOND) AS ts, toString(multiIf((dynamicElement(body_v2.`user.age`, 'Int64') IS NOT NULL OR dynamicElement(body_promoted.`user.age`, 'Int64') IS NOT NULL), toString(coalesce(dynamicElement(body_promoted.`user.age`, 'Int64'), dynamicElement(body_v2.`user.age`, 'Int64'))), (dynamicElement(body_v2.`user.age`, 'String') IS NOT NULL OR dynamicElement(body_promoted.`user.age`, 'String') IS NOT NULL), coalesce(dynamicElement(body_promoted.`user.age`, 'String'), dynamicElement(body_v2.`user.age`, 'String')), NULL)) AS `user.age`, toString(multiIf((dynamicElement(body_v2.`user.name`, 'String') IS NOT NULL OR dynamicElement(body_promoted.`user.name`, 'String') IS NOT NULL), coalesce(dynamicElement(body_promoted.`user.name`, 'String'), dynamicElement(body_v2.`user.name`, 'String')), NULL)) AS `user.name`, count() AS __result_0 FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? AND (`user.age`, `user.name`) GLOBAL IN (SELECT `user.age`, `user.name` FROM __limit_cte) GROUP BY ts, `user.age`, `user.name`",Args: []any{uint64(1747945619), uint64(1747983448), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448)},},},@@ -158,107 +175,193 @@ func TestStmtBuilderTimeSeriesBodyGroupByPromoted(t *testing.T) {}*/-func TestStatementBuilderListQueryBodyHas(t *testing.T) {+func TestJSONStmtBuilder_PrimitivePaths(t *testing.T) {enable, disable := jsonQueryTestUtil(t)enable()defer disable()- statementBuilder := buildJSONTestStatementBuilder(t)+ statementBuilder := buildJSONTestStatementBuilder(t, false)cases := []struct {name string- requestType qbtypes.RequestType- query qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]- expected qbtypes.Statement+ filter string+ expected TestExpectedexpectedErr error}{+ // ── intrinsic sub-column (body_v2.message) ──────────────────────────────{- name: "Simple has filter",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "has(body.education[].parameters, 1.65)"},- Limit: 10,+ name: "message Exists",+ filter: "message Exists",+ expected: TestExpected{+ WhereClause: "body_v2.message <> ?",+ Args: []any{uint64(1747945619), uint64(1747983448), "", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (has(arrayFlatten(arrayConcat(arrayMap(`body_v2.education`->dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))'), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')))), ?) OR has(arrayFlatten(arrayConcat(arrayMap(`body_v2.education`->dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)'), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')))), ?)) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), 1.65, 1.65, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},- Warnings: []string{- "Key `education[].parameters` is ambiguous, found 2 different combinations of field context / data type: [name=education[].parameters,context=body,datatype=[]float64,jsondatatype=Array(Nullable(Float64)) name=education[].parameters,context=body,datatype=[]dynamic,jsondatatype=Array(Dynamic)].",- },+ },+ {+ name: "message Contains 'Iron Award'",+ filter: "message Contains 'Iron Award'",+ expected: TestExpected{+ WhereClause: "LOWER(body_v2.message) LIKE LOWER(?)",+ Args: []any{uint64(1747945619), uint64(1747983448), "%Iron Award%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expectedErr: nil,},++ // ── flat nested primitive (x.y) ─────────────────────────────────────────{- name: "Flat path hasAll filter",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "hasAll(body.user.permissions, ['read', 'write'])"},- Limit: 10,+ name: "Simple string filter",+ filter: "body.user.name = 'x'",+ expected: TestExpected{+ WhereClause: "((dynamicElement(body_v2.`user.name`, 'String') = ?) AND has(JSONAllPaths(body_v2), 'user.name'))",+ Args: []any{uint64(1747945619), uint64(1747983448), "x", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND hasAll(dynamicElement(body_v2.`user.permissions`, 'Array(Nullable(String))'), ?) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), []any{[]any{"read", "write"}}, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ {+ name: "Simple Int field Contains value",+ filter: "body.user.age Contains 25",+ expected: TestExpected{+ WhereClause: "(((LOWER(toString(dynamicElement(body_v2.`user.age`, 'Int64'))) LIKE LOWER(?)) AND has(JSONAllPaths(body_v2), 'user.age')) OR ((LOWER(dynamicElement(body_v2.`user.age`, 'String')) LIKE LOWER(?)) AND has(JSONAllPaths(body_v2), 'user.age')))",+ Args: []any{uint64(1747945619), uint64(1747983448), "%25%", "%25%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ Warnings: []string{"Key `user.age` is ambiguous, found 2 different combinations of field context / data type: [name=user.age,context=body,datatype=int64,jsondatatype=Int64 name=user.age,context=body,datatype=string,jsondatatype=String]."},},- expectedErr: nil,},{- name: "Nested path hasAny filter",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "hasAny(education[].awards[].participated[].members, ['Piyush', 'Tushar'])"},- Limit: 10,+ name: "Simple Float field Contains value",+ filter: "body.user.height Contains 5.8",+ expected: TestExpected{+ WhereClause: "((LOWER(toString(dynamicElement(body_v2.`user.height`, 'Float64'))) LIKE LOWER(?)) AND has(JSONAllPaths(body_v2), 'user.height'))",+ Args: []any{uint64(1747945619), uint64(1747983448), "%5.8%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND hasAny(arrayFlatten(arrayConcat(arrayMap(`body_v2.education`->arrayConcat(arrayMap(`body_v2.education[].awards`->arrayConcat(arrayMap(`body_v2.education[].awards[].participated`->dynamicElement(`body_v2.education[].awards[].participated`.`members`, 'Array(Nullable(String))'), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(JSON(max_dynamic_types=4, max_dynamic_paths=0))')), arrayMap(`body_v2.education[].awards[].participated`->dynamicElement(`body_v2.education[].awards[].participated`.`members`, 'Array(Nullable(String))'), arrayMap(x->assumeNotNull(dynamicElement(x, 'JSON')), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(Dynamic)'))))), dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')), arrayMap(`body_v2.education[].awards`->arrayConcat(arrayMap(`body_v2.education[].awards[].participated`->dynamicElement(`body_v2.education[].awards[].participated`.`members`, 'Array(Nullable(String))'), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))')), arrayMap(`body_v2.education[].awards[].participated`->dynamicElement(`body_v2.education[].awards[].participated`.`members`, 'Array(Nullable(String))'), arrayMap(x->assumeNotNull(dynamicElement(x, 'JSON')), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(Dynamic)'))))), arrayMap(x->assumeNotNull(dynamicElement(x, 'JSON')), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')))), ?) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), []any{[]any{"Piyush", "Tushar"}}, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ {+ name: "Float GT",+ filter: "body.user.height > 5.8",+ expected: TestExpected{+ WhereClause: "((toFloat64(dynamicElement(body_v2.`user.height`, 'Float64')) > ?) AND has(JSONAllPaths(body_v2), 'user.height'))",+ Args: []any{uint64(1747945619), uint64(1747983448), 5.8, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ {+ name: "String Like",+ filter: "body.user.name LIKE '%ali%'",+ expected: TestExpected{+ WhereClause: "((dynamicElement(body_v2.`user.name`, 'String') LIKE ?) AND has(JSONAllPaths(body_v2), 'user.name'))",+ Args: []any{uint64(1747945619), uint64(1747983448), "%ali%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ {+ name: "String Regexp",+ filter: "body.user.name REGEXP 'al.*'",+ expected: TestExpected{+ WhereClause: "((match(dynamicElement(body_v2.`user.name`, 'String'), ?)) AND has(JSONAllPaths(body_v2), 'user.name'))",+ Args: []any{uint64(1747945619), uint64(1747983448), "al.*", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ {+ name: "Primitive Bool NotEqual",+ filter: "body.user.active != true",+ expected: TestExpected{+ WhereClause: "(assumeNotNull(dynamicElement(body_v2.`user.active`, 'Bool')) <> ?)",+ Args: []any{uint64(1747945619), uint64(1747983448), true, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ {+ name: "Primitive Bool NotExists",+ filter: "body.user.active NOT EXISTS",+ expected: TestExpected{+ WhereClause: "(dynamicElement(body_v2.`user.active`, 'Bool') IS NULL)",+ Args: []any{uint64(1747945619), uint64(1747983448), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ {+ name: "Primitive String NotContains",+ filter: "body.user.name NOT CONTAINS 'IIT'",+ expected: TestExpected{+ WhereClause: "(LOWER(assumeNotNull(dynamicElement(body_v2.`user.name`, 'String'))) NOT LIKE LOWER(?))",+ Args: []any{uint64(1747945619), uint64(1747983448), "%IIT%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ {+ name: "Primitive String NotLike",+ filter: "body.user.name NOT LIKE '%ali%'",+ expected: TestExpected{+ WhereClause: "(assumeNotNull(dynamicElement(body_v2.`user.name`, 'String')) NOT LIKE ?)",+ Args: []any{uint64(1747945619), uint64(1747983448), "%ali%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ {+ name: "Primitive String NotRegexp",+ filter: "body.user.name NOT REGEXP 'al.*'",+ expected: TestExpected{+ WhereClause: "(NOT match(assumeNotNull(dynamicElement(body_v2.`user.name`, 'String')), ?))",+ Args: []any{uint64(1747945619), uint64(1747983448), "al.*", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ {+ name: "Primitive String NotIn",+ filter: "body.user.name NOT IN ['alice', 'bob']",+ expected: TestExpected{+ WhereClause: "(assumeNotNull(dynamicElement(body_v2.`user.name`, 'String')) NOT IN (?, ?))",+ Args: []any{uint64(1747945619), uint64(1747983448), "alice", "bob", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },++ // ── deeply nested primitive (x.y.z) ─────────────────────────────────────+ {+ name: "Primitive Int64 NotBetween",+ filter: "body.user.address.zip NOT BETWEEN 100000 AND 999999",+ expected: TestExpected{+ WhereClause: "(toFloat64(assumeNotNull(dynamicElement(body_v2.`user.address.zip`, 'Int64'))) NOT BETWEEN ? AND ?)",+ Args: []any{uint64(1747945619), uint64(1747983448), float64(100000), float64(999999), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expectedErr: nil,},}for _, c := range cases {t.Run(c.name, func(t *testing.T) {-- q, err := statementBuilder.Build(context.Background(), 1747947419000, 1747983448000, c.requestType, c.query, nil)+ q, err := statementBuilder.Build(context.Background(), 1747947419000, 1747983448000, qbtypes.RequestTypeRaw,+ qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{+ Signal: telemetrytypes.SignalLogs,+ Filter: &qbtypes.Filter{Expression: c.filter},+ Limit: 10,+ }, nil)if c.expectedErr != nil {require.Error(t, err)require.Contains(t, err.Error(), c.expectedErr.Error())- } else {- require.NoError(t, err)- require.Equal(t, c.expected.Query, q.Query)- require.Equal(t, c.expected.Args, q.Args)- require.Equal(t, c.expected.Warnings, q.Warnings)+ return}+ require.NoError(t, err)+ require.Equal(t, c.expected.GetQuery(), q.Query)+ require.Equal(t, c.expected.Args, q.Args)+ require.Equal(t, c.expected.Warnings, q.Warnings)})}}-func TestStatementBuilderListQueryBody(t *testing.T) {+/* Promoted path list-query tests commented out — Materialized now means type hint+ (direct sub-column access), not a body_promoted.* column.++func TestStatementBuilderListQueryBodyPromoted(t *testing.T) {enable, disable := jsonQueryTestUtil(t)enable()defer disable()- statementBuilder := buildJSONTestStatementBuilder(t)+ statementBuilder := buildJSONTestStatementBuilder(t, "education", "tags")cases := []struct {name stringrequestType qbtypes.RequestTypequery qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]- expected qbtypes.Statement+ expected TestExpectedexpectedErr error}{{- name: "Simple string filter",+ name: "Has Array promoted uses body fallback",requestType: qbtypes.RequestTypeRaw,query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "body.user.name = 'x'"},+ Filter: &qbtypes.Filter{Expression: "has(body.tags, 'production')"},Limit: 10,},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND ((dynamicElement(body_v2.`user.name`, 'String') = ?) AND has(JSONAllPaths(body_v2), 'user.name')) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "x", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ expected: TestExpected{+ Args: []any{uint64(1747945619), uint64(1747983448), "production", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},expectedErr: nil,},@@ -270,8 +373,7 @@ func TestStatementBuilderListQueryBody(t *testing.T) {Filter: &qbtypes.Filter{Expression: "body.education[].name Exists"},Limit: 10,},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (arrayExists(`body_v2.education`-> dynamicElement(`body_v2.education`.`name`, 'String') IS NOT NULL, dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",+ expected: TestExpected{Args: []any{uint64(1747945619), uint64(1747983448), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},expectedErr: nil,@@ -284,8 +386,7 @@ func TestStatementBuilderListQueryBody(t *testing.T) {Filter: &qbtypes.Filter{Expression: "body.education[].awards[].name Exists"},Limit: 10,},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (arrayExists(`body_v2.education`-> (arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`name`, 'String') IS NOT NULL, dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`name`, 'String') IS NOT NULL, arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",+ expected: TestExpected{Args: []any{uint64(1747945619), uint64(1747983448), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},expectedErr: nil,@@ -298,24 +399,22 @@ func TestStatementBuilderListQueryBody(t *testing.T) {Filter: &qbtypes.Filter{Expression: "body.education[].awards[].name = 'Iron Award'"},Limit: 10,},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND ((arrayExists(`body_v2.education`-> (arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`name`, 'String') = ?, dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`name`, 'String') = ?, arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "Iron Award", "Iron Award", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ expected: TestExpected{+ Args: []any{uint64(1747945619), uint64(1747983448), "Iron Award", "Iron Award", "Iron Award", "Iron Award", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},expectedErr: nil,},{- name: "Key inside Array(JSON) contains Float value",+ name: "Key inside Array(JSON) contains value",requestType: qbtypes.RequestTypeRaw,query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{Signal: telemetrytypes.SignalLogs,Filter: &qbtypes.Filter{Expression: "body.education[].parameters Contains 1.65"},Limit: 10,},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (((arrayExists(`body_v2.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))')) OR arrayExists(x -> toFloat64(x) = ?, dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))'))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')) OR ((arrayExists(`body_v2.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), arrayMap(x->dynamicElement(x, 'Float64'), arrayFilter(x->(dynamicType(x) = 'Float64'), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)')))) OR arrayExists(x -> toFloat64(x) = ?, arrayMap(x->dynamicElement(x, 'Float64'), arrayFilter(x->(dynamicType(x) = 'Float64'), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education'))) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "%1.65%", 1.65, "%1.65%", 1.65, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},- Warnings: []string{"Key `education[].parameters` is ambiguous, found 2 different combinations of field context / data type: [name=education[].parameters,context=body,datatype=[]float64,jsondatatype=Array(Nullable(Float64)) name=education[].parameters,context=body,datatype=[]dynamic,jsondatatype=Array(Dynamic)]."},+ expected: TestExpected{+ Args: []any{uint64(1747945619), uint64(1747983448), "%1.65%", 1.65, "%1.65%", 1.65, "%1.65%", 1.65, "%1.65%", 1.65, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ Warnings: []string{"Key `education[].parameters` is ambiguous, found 2 different combinations of field context / data type: [name=education[].parameters,context=body,datatype=[]float64,materialized=true,jsondatatype=Array(Nullable(Float64)) name=education[].parameters,context=body,datatype=[]dynamic,materialized=true,jsondatatype=Array(Dynamic)]."},},expectedErr: nil,},@@ -327,9 +426,8 @@ func TestStatementBuilderListQueryBody(t *testing.T) {Filter: &qbtypes.Filter{Expression: "body.education[].name Contains 'IIT'"},Limit: 10,},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND ((arrayExists(`body_v2.education`-> LOWER(dynamicElement(`body_v2.education`.`name`, 'String')) LIKE LOWER(?), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "%IIT%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ expected: TestExpected{+ Args: []any{uint64(1747945619), uint64(1747983448), "%IIT%", "%IIT%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},expectedErr: nil,},@@ -341,10 +439,9 @@ func TestStatementBuilderListQueryBody(t *testing.T) {Filter: &qbtypes.Filter{Expression: "body.education[].parameters Contains true"},Limit: 10,},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (((arrayExists(`body_v2.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))')) OR arrayExists(x -> x = ?, dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))'))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')) OR ((arrayExists(`body_v2.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), arrayMap(x->dynamicElement(x, 'Bool'), arrayFilter(x->(dynamicType(x) = 'Bool'), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)')))) OR arrayExists(x -> x = ?, arrayMap(x->dynamicElement(x, 'Bool'), arrayFilter(x->(dynamicType(x) = 'Bool'), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education'))) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "%true%", true, "%true%", true, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},- Warnings: []string{"Key `education[].parameters` is ambiguous, found 2 different combinations of field context / data type: [name=education[].parameters,context=body,datatype=[]float64,jsondatatype=Array(Nullable(Float64)) name=education[].parameters,context=body,datatype=[]dynamic,jsondatatype=Array(Dynamic)]."},+ expected: TestExpected{+ Args: []any{uint64(1747945619), uint64(1747983448), "%true%", true, "%true%", true, "%true%", true, "%true%", true, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ Warnings: []string{"Key `education[].parameters` is ambiguous, found 2 different combinations of field context / data type: [name=education[].parameters,context=body,datatype=[]float64,materialized=true,jsondatatype=Array(Nullable(Float64)) name=education[].parameters,context=body,datatype=[]dynamic,materialized=true,jsondatatype=Array(Dynamic)]."},},expectedErr: nil,},@@ -356,97 +453,22 @@ func TestStatementBuilderListQueryBody(t *testing.T) {Filter: &qbtypes.Filter{Expression: "body.education[].parameters Contains 'passed'"},Limit: 10,},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (((arrayExists(`body_v2.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))')) OR arrayExists(x -> toString(x) = ?, dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))'))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')) OR ((arrayExists(`body_v2.education`-> (arrayExists(x -> LOWER(x) LIKE LOWER(?), arrayMap(x->dynamicElement(x, 'String'), arrayFilter(x->(dynamicType(x) = 'String'), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)')))) OR arrayExists(x -> x = ?, arrayMap(x->dynamicElement(x, 'String'), arrayFilter(x->(dynamicType(x) = 'String'), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education'))) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "%passed%", "passed", "%passed%", "passed", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},- Warnings: []string{"Key `education[].parameters` is ambiguous, found 2 different combinations of field context / data type: [name=education[].parameters,context=body,datatype=[]float64,jsondatatype=Array(Nullable(Float64)) name=education[].parameters,context=body,datatype=[]dynamic,jsondatatype=Array(Dynamic)]."},- },- expectedErr: nil,- },- {- name: "Dynamic array IN Operator",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "body.education[].parameters IN [1.65, 1.99]"},- Limit: 10,- },- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (((arrayExists(`body_v2.education`-> (arrayExists(x -> toFloat64(x) IN (?, ?), dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))'))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')) OR ((arrayExists(`body_v2.education`-> (arrayExists(x -> x IN (?, ?), arrayMap(x->dynamicElement(x, 'Array(Nullable(Float64))'), arrayFilter(x->(dynamicType(x) = 'Array(Nullable(Float64))'), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education'))) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), 1.65, 1.99, 1.65, 1.99, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},- Warnings: []string{"Key `education[].parameters` is ambiguous, found 2 different combinations of field context / data type: [name=education[].parameters,context=body,datatype=[]float64,jsondatatype=Array(Nullable(Float64)) name=education[].parameters,context=body,datatype=[]dynamic,jsondatatype=Array(Dynamic)]."},- },- expectedErr: nil,- },- {- name: "Integer BETWEEN Operator",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "education[].awards[].semester BETWEEN 2 AND 4"},- Limit: 10,- },- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND ((arrayExists(`body_v2.education`-> (arrayExists(`body_v2.education[].awards`-> toFloat64(dynamicElement(`body_v2.education[].awards`.`semester`, 'Int64')) BETWEEN ? AND ?, dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards`-> toFloat64(dynamicElement(`body_v2.education[].awards`.`semester`, 'Int64')) BETWEEN ? AND ?, arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), float64(2), float64(4), float64(2), float64(4), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},- },- expectedErr: nil,- },- {- name: "Integer IN Operator",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "education[].awards[].semester IN [2, 4]"},- Limit: 10,- },- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND ((arrayExists(`body_v2.education`-> (arrayExists(`body_v2.education[].awards`-> toFloat64(dynamicElement(`body_v2.education[].awards`.`semester`, 'Int64')) IN (?, ?), dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards`-> toFloat64(dynamicElement(`body_v2.education[].awards`.`semester`, 'Int64')) IN (?, ?), arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), float64(2), float64(4), float64(2), float64(4), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ expected: TestExpected{+ Args: []any{uint64(1747945619), uint64(1747983448), "%passed%", "passed", "%passed%", "passed", "%passed%", "passed", "%passed%", "passed", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ Warnings: []string{"Key `education[].parameters` is ambiguous, found 2 different combinations of field context / data type: [name=education[].parameters,context=body,datatype=[]float64,materialized=true,jsondatatype=Array(Nullable(Float64)) name=education[].parameters,context=body,datatype=[]dynamic,materialized=true,jsondatatype=Array(Dynamic)]."},},expectedErr: nil,},{- name: "Equals to 'sports' inside array of awards",+ name: "Array(Dynamic) + Array(JSON) both can contain a value",requestType: qbtypes.RequestTypeRaw,query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{Signal: telemetrytypes.SignalLogs,Filter: &qbtypes.Filter{Expression: "body.education[].awards[].type = 'sports'"},Limit: 10,},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND ((arrayExists(`body_v2.education`-> (arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`type`, 'String') = ?, dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`type`, 'String') = ?, arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "sports", "sports", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},- },- expectedErr: nil,- },- {- name: "Super nested array contains Int64 value",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "body.interests[].entities[].reviews[].entries[].metadata[].positions[].ratings Contains 4"},- Limit: 10,- },- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (((arrayExists(`body_v2.interests`-> arrayExists(`body_v2.interests[].entities`-> arrayExists(`body_v2.interests[].entities[].reviews`-> arrayExists(`body_v2.interests[].entities[].reviews[].entries`-> arrayExists(`body_v2.interests[].entities[].reviews[].entries[].metadata`-> arrayExists(`body_v2.interests[].entities[].reviews[].entries[].metadata[].positions`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), dynamicElement(`body_v2.interests[].entities[].reviews[].entries[].metadata[].positions`.`ratings`, 'Array(Nullable(Int64))')) OR arrayExists(x -> toFloat64(x) = ?, dynamicElement(`body_v2.interests[].entities[].reviews[].entries[].metadata[].positions`.`ratings`, 'Array(Nullable(Int64))'))), dynamicElement(`body_v2.interests[].entities[].reviews[].entries[].metadata`.`positions`, 'Array(JSON(max_dynamic_types=0, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests[].entities[].reviews[].entries`.`metadata`, 'Array(JSON(max_dynamic_types=1, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests[].entities[].reviews`.`entries`, 'Array(JSON(max_dynamic_types=2, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests[].entities`.`reviews`, 'Array(JSON(max_dynamic_types=4, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests`.`entities`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')), dynamicElement(body_v2.`interests`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'interests')) OR ((arrayExists(`body_v2.interests`-> arrayExists(`body_v2.interests[].entities`-> arrayExists(`body_v2.interests[].entities[].reviews`-> arrayExists(`body_v2.interests[].entities[].reviews[].entries`-> arrayExists(`body_v2.interests[].entities[].reviews[].entries[].metadata`-> arrayExists(`body_v2.interests[].entities[].reviews[].entries[].metadata[].positions`-> (arrayExists(x -> LOWER(x) LIKE LOWER(?), dynamicElement(`body_v2.interests[].entities[].reviews[].entries[].metadata[].positions`.`ratings`, 'Array(Nullable(String))')) OR arrayExists(x -> toFloat64OrNull(x) = ?, dynamicElement(`body_v2.interests[].entities[].reviews[].entries[].metadata[].positions`.`ratings`, 'Array(Nullable(String))'))), dynamicElement(`body_v2.interests[].entities[].reviews[].entries[].metadata`.`positions`, 'Array(JSON(max_dynamic_types=0, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests[].entities[].reviews[].entries`.`metadata`, 'Array(JSON(max_dynamic_types=1, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests[].entities[].reviews`.`entries`, 'Array(JSON(max_dynamic_types=2, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests[].entities`.`reviews`, 'Array(JSON(max_dynamic_types=4, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests`.`entities`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')), dynamicElement(body_v2.`interests`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'interests'))) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "%4%", float64(4), "%4%", float64(4), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},- Warnings: []string{"Key `interests[].entities[].reviews[].entries[].metadata[].positions[].ratings` is ambiguous, found 2 different combinations of field context / data type: [name=interests[].entities[].reviews[].entries[].metadata[].positions[].ratings,context=body,datatype=[]int64,jsondatatype=Array(Nullable(Int64)) name=interests[].entities[].reviews[].entries[].metadata[].positions[].ratings,context=body,datatype=[]string,jsondatatype=Array(Nullable(String))]."},- },- expectedErr: nil,- },- {- name: "Super nested array contains value - x2",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "body.interests[].entities[].reviews[].entries[].metadata[].positions[].ratings Contains 'Good'"},- Limit: 10,- },- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (((arrayExists(`body_v2.interests`-> arrayExists(`body_v2.interests[].entities`-> arrayExists(`body_v2.interests[].entities[].reviews`-> arrayExists(`body_v2.interests[].entities[].reviews[].entries`-> arrayExists(`body_v2.interests[].entities[].reviews[].entries[].metadata`-> arrayExists(`body_v2.interests[].entities[].reviews[].entries[].metadata[].positions`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), dynamicElement(`body_v2.interests[].entities[].reviews[].entries[].metadata[].positions`.`ratings`, 'Array(Nullable(Int64))')) OR arrayExists(x -> toString(x) = ?, dynamicElement(`body_v2.interests[].entities[].reviews[].entries[].metadata[].positions`.`ratings`, 'Array(Nullable(Int64))'))), dynamicElement(`body_v2.interests[].entities[].reviews[].entries[].metadata`.`positions`, 'Array(JSON(max_dynamic_types=0, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests[].entities[].reviews[].entries`.`metadata`, 'Array(JSON(max_dynamic_types=1, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests[].entities[].reviews`.`entries`, 'Array(JSON(max_dynamic_types=2, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests[].entities`.`reviews`, 'Array(JSON(max_dynamic_types=4, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests`.`entities`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')), dynamicElement(body_v2.`interests`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'interests')) OR ((arrayExists(`body_v2.interests`-> arrayExists(`body_v2.interests[].entities`-> arrayExists(`body_v2.interests[].entities[].reviews`-> arrayExists(`body_v2.interests[].entities[].reviews[].entries`-> arrayExists(`body_v2.interests[].entities[].reviews[].entries[].metadata`-> arrayExists(`body_v2.interests[].entities[].reviews[].entries[].metadata[].positions`-> (arrayExists(x -> LOWER(x) LIKE LOWER(?), dynamicElement(`body_v2.interests[].entities[].reviews[].entries[].metadata[].positions`.`ratings`, 'Array(Nullable(String))')) OR arrayExists(x -> x = ?, dynamicElement(`body_v2.interests[].entities[].reviews[].entries[].metadata[].positions`.`ratings`, 'Array(Nullable(String))'))), dynamicElement(`body_v2.interests[].entities[].reviews[].entries[].metadata`.`positions`, 'Array(JSON(max_dynamic_types=0, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests[].entities[].reviews[].entries`.`metadata`, 'Array(JSON(max_dynamic_types=1, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests[].entities[].reviews`.`entries`, 'Array(JSON(max_dynamic_types=2, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests[].entities`.`reviews`, 'Array(JSON(max_dynamic_types=4, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests`.`entities`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')), dynamicElement(body_v2.`interests`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'interests'))) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "%Good%", "Good", "%Good%", "Good", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},- Warnings: []string{"Key `interests[].entities[].reviews[].entries[].metadata[].positions[].ratings` is ambiguous, found 2 different combinations of field context / data type: [name=interests[].entities[].reviews[].entries[].metadata[].positions[].ratings,context=body,datatype=[]int64,jsondatatype=Array(Nullable(Int64)) name=interests[].entities[].reviews[].entries[].metadata[].positions[].ratings,context=body,datatype=[]string,jsondatatype=Array(Nullable(String))]."},+ expected: TestExpected{+ Args: []any{uint64(1747945619), uint64(1747983448), "sports", "sports", "sports", "sports", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},expectedErr: nil,},@@ -458,52 +480,8 @@ func TestStatementBuilderListQueryBody(t *testing.T) {Filter: &qbtypes.Filter{Expression: "body.education[].awards[].participated[].team[].branch Contains 'Civil'"},Limit: 10,},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND ((arrayExists(`body_v2.education`-> (arrayExists(`body_v2.education[].awards`-> (arrayExists(`body_v2.education[].awards[].participated`-> arrayExists(`body_v2.education[].awards[].participated[].team`-> LOWER(dynamicElement(`body_v2.education[].awards[].participated[].team`.`branch`, 'String')) LIKE LOWER(?), dynamicElement(`body_v2.education[].awards[].participated`.`team`, 'Array(JSON(max_dynamic_types=2, max_dynamic_paths=0))')), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(JSON(max_dynamic_types=4, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards[].participated`-> arrayExists(`body_v2.education[].awards[].participated[].team`-> LOWER(dynamicElement(`body_v2.education[].awards[].participated[].team`.`branch`, 'String')) LIKE LOWER(?), dynamicElement(`body_v2.education[].awards[].participated`.`team`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))')), arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(Dynamic)'))))), dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards`-> (arrayExists(`body_v2.education[].awards[].participated`-> arrayExists(`body_v2.education[].awards[].participated[].team`-> LOWER(dynamicElement(`body_v2.education[].awards[].participated[].team`.`branch`, 'String')) LIKE LOWER(?), dynamicElement(`body_v2.education[].awards[].participated`.`team`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=64))')), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))')) OR arrayExists(`body_v2.education[].awards[].participated`-> arrayExists(`body_v2.education[].awards[].participated[].team`-> LOWER(dynamicElement(`body_v2.education[].awards[].participated[].team`.`branch`, 'String')) LIKE LOWER(?), dynamicElement(`body_v2.education[].awards[].participated`.`team`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))')), arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(Dynamic)'))))), arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "%Civil%", "%Civil%", "%Civil%", "%Civil%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},- },- expectedErr: nil,- },- {- name: "Simple Int field Contains value",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "body.user.age Contains 25"},- Limit: 10,- },- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (((LOWER(toString(dynamicElement(body_v2.`user.age`, 'Int64'))) LIKE LOWER(?)) AND has(JSONAllPaths(body_v2), 'user.age')) OR ((LOWER(dynamicElement(body_v2.`user.age`, 'String')) LIKE LOWER(?)) AND has(JSONAllPaths(body_v2), 'user.age'))) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "%25%", "%25%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},- Warnings: []string{"Key `user.age` is ambiguous, found 2 different combinations of field context / data type: [name=user.age,context=body,datatype=int64,jsondatatype=Int64 name=user.age,context=body,datatype=string,jsondatatype=String]."},- },- expectedErr: nil,- },- {- name: "Simple Float field Contains value",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "body.user.height Contains 5.8"},- Limit: 10,- },- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND ((LOWER(toString(dynamicElement(body_v2.`user.height`, 'Float64'))) LIKE LOWER(?)) AND has(JSONAllPaths(body_v2), 'user.height')) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "%5.8%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},- },- expectedErr: nil,- },- {- name: "Int in array Contains value",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "body.education[].year Contains 2020"},- Limit: 10,- },- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND ((arrayExists(`body_v2.education`-> LOWER(toString(dynamicElement(`body_v2.education`.`year`, 'Int64'))) LIKE LOWER(?), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "%2020%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ expected: TestExpected{+ Args: []any{uint64(1747945619), uint64(1747983448), "%Civil%", "%Civil%", "%Civil%", "%Civil%", "%Civil%", "%Civil%", "%Civil%", "%Civil%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},expectedErr: nil,},@@ -513,299 +491,462 @@ func TestStatementBuilderListQueryBody(t *testing.T) {t.Run(c.name, func(t *testing.T) {q, err := statementBuilder.Build(context.Background(), 1747947419000, 1747983448000, c.requestType, c.query, nil)+if c.expectedErr != nil {require.Error(t, err)require.Contains(t, err.Error(), c.expectedErr.Error())} else {require.NoError(t, err)- require.Equal(t, c.expected.Query, q.Query)+ require.Equal(t, c.expected.GetQuery(), q.Query)require.Equal(t, c.expected.Args, q.Args)require.Equal(t, c.expected.Warnings, q.Warnings)}})}}+*/-/* Promoted path list-query tests commented out — Materialized now means type hint- (direct sub-column access), not a body_promoted.* column.--func TestStatementBuilderListQueryBodyPromoted(t *testing.T) {+func TestJSONStmtBuilder_ArrayPaths(t *testing.T) {enable, disable := jsonQueryTestUtil(t)enable()defer disable()- statementBuilder := buildJSONTestStatementBuilder(t, "education", "tags")+ statementBuilder := buildJSONTestStatementBuilder(t, false)cases := []struct {name string- requestType qbtypes.RequestType- query qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]- expected qbtypes.Statement+ filter string+ expected TestExpectedexpectedErr error}{+ // ── single-hop (x[].y) ──────────────────────────────────────────────────{- name: "Has Array promoted uses body fallback",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "has(body.tags, 'production')"},- Limit: 10,+ name: "Key inside Array(JSON) exists",+ filter: "body.education[].name Exists",+ expected: TestExpected{+ WhereClause: "(arrayExists(`body_v2.education`-> dynamicElement(`body_v2.education`.`name`, 'String') IS NOT NULL, dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')))",+ Args: []any{uint64(1747945619), uint64(1747983448), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND has(if(length(dynamicElement(body_promoted.`tags`, 'Array(Nullable(String))')) > 0, dynamicElement(body_promoted.`tags`, 'Array(Nullable(String))'), dynamicElement(body_v2.`tags`, 'Array(Nullable(String))')), ?) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "production", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ {+ name: "Key inside Array(JSON) contains String value",+ filter: "body.education[].name Contains 'IIT'",+ expected: TestExpected{+ WhereClause: "((arrayExists(`body_v2.education`-> LOWER(dynamicElement(`body_v2.education`.`name`, 'String')) LIKE LOWER(?), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education'))",+ Args: []any{uint64(1747945619), uint64(1747983448), "%IIT%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expectedErr: nil,},{- name: "Key inside Array(JSON) exists",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "body.education[].name Exists"},- Limit: 10,+ name: "Int in array Contains value",+ filter: "body.education[].year Contains 2020",+ expected: TestExpected{+ WhereClause: "((arrayExists(`body_v2.education`-> LOWER(toString(dynamicElement(`body_v2.education`.`year`, 'Int64'))) LIKE LOWER(?), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education'))",+ Args: []any{uint64(1747945619), uint64(1747983448), "%2020%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (arrayExists(`body_v2.education`-> dynamicElement(`body_v2.education`.`name`, 'String') IS NOT NULL, dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')) OR arrayExists(`body_promoted.education`-> dynamicElement(`body_promoted.education`.`name`, 'String') IS NOT NULL, dynamicElement(body_promoted.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))'))) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ {+ name: "Array simple path NotEqual",+ filter: "body.education[].type != '10001'",+ expected: TestExpected{+ WhereClause: "((NOT arrayExists(`body_v2.education`-> toFloat64OrNull(dynamicElement(`body_v2.education`.`type`, 'String')) = ?, dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND (NOT arrayExists(`body_v2.education`-> dynamicElement(`body_v2.education`.`type`, 'Int64') = ?, dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))))",+ Args: []any{uint64(1747945619), uint64(1747983448), int64(10001), int64(10001), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ Warnings: []string{"Key `education[].type` is ambiguous, found 2 different combinations of field context / data type: [name=education[].type,context=body,datatype=string,jsondatatype=String name=education[].type,context=body,datatype=int64,jsondatatype=Int64]."},},- expectedErr: nil,},{- name: "Key inside Array(JSON) -> Array(Dynamic) + Array(JSON) exists",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "body.education[].awards[].name Exists"},- Limit: 10,+ name: "Array simple path NotExists",+ filter: "body.education[].name NOT EXISTS",+ expected: TestExpected{+ WhereClause: "(NOT arrayExists(`body_v2.education`-> dynamicElement(`body_v2.education`.`name`, 'String') IS NOT NULL, dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')))",+ Args: []any{uint64(1747945619), uint64(1747983448), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (arrayExists(`body_v2.education`-> (arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`name`, 'String') IS NOT NULL, dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`name`, 'String') IS NOT NULL, arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')) OR arrayExists(`body_promoted.education`-> (arrayExists(`body_promoted.education[].awards`-> dynamicElement(`body_promoted.education[].awards`.`name`, 'String') IS NOT NULL, dynamicElement(`body_promoted.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=64))')) OR arrayExists(`body_promoted.education[].awards`-> dynamicElement(`body_promoted.education[].awards`.`name`, 'String') IS NOT NULL, arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_promoted.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_promoted.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))'))) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ {+ name: "Array simple path NotContains",+ filter: "body.education[].name NOT CONTAINS 'IIT'",+ expected: TestExpected{+ WhereClause: "(NOT arrayExists(`body_v2.education`-> LOWER(dynamicElement(`body_v2.education`.`name`, 'String')) LIKE LOWER(?), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')))",+ Args: []any{uint64(1747945619), uint64(1747983448), "%IIT%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expectedErr: nil,},++ // ── single-hop terminal array (x[].y[]) ─────────────────────────────────{- name: "Key inside Array(JSON) -> Array(Dynamic) + Array(JSON) = 'Iron Award'",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "body.education[].awards[].name = 'Iron Award'"},- Limit: 10,+ name: "Key inside Array(JSON) contains Float value",+ filter: "body.education[].parameters Contains 1.65",+ expected: TestExpected{+ WhereClause: "(((arrayExists(`body_v2.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))')) OR arrayExists(x -> toFloat64(x) = ?, dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))'))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')) OR ((arrayExists(`body_v2.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), arrayFilter(x->(dynamicType(x) IN ('String', 'Int64', 'Float64', 'Bool')), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)'))) OR arrayExists(x -> accurateCastOrNull(x, 'Float64') = ?, arrayFilter(x->(dynamicType(x) IN ('String', 'Int64', 'Float64', 'Bool')), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)')))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')))",+ Args: []any{uint64(1747945619), uint64(1747983448), "%1.65%", 1.65, "%1.65%", 1.65, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ Warnings: []string{"Key `education[].parameters` is ambiguous, found 2 different combinations of field context / data type: [name=education[].parameters,context=body,datatype=[]float64,jsondatatype=Array(Nullable(Float64)) name=education[].parameters,context=body,datatype=[]dynamic,jsondatatype=Array(Dynamic)]."},},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (arrayExists(`body_v2.education`-> (arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`name`, 'String') = ?, dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`name`, 'String') = ?, arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')) OR arrayExists(`body_promoted.education`-> (arrayExists(`body_promoted.education[].awards`-> dynamicElement(`body_promoted.education[].awards`.`name`, 'String') = ?, dynamicElement(`body_promoted.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=64))')) OR arrayExists(`body_promoted.education[].awards`-> dynamicElement(`body_promoted.education[].awards`.`name`, 'String') = ?, arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_promoted.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_promoted.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))'))) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "Iron Award", "Iron Award", "Iron Award", "Iron Award", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ {+ name: "Dynamic array element comparison",+ filter: "body.education[].parameters = 'passed'",+ expected: TestExpected{+ WhereClause: "(((arrayExists(`body_v2.education`-> arrayExists(x -> toString(x) = ?, dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))')), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')) OR ((arrayExists(`body_v2.education`-> arrayExists(x -> toString(x) = ?, arrayFilter(x->(dynamicType(x) IN ('String', 'Int64', 'Float64', 'Bool')), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)'))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')))",+ Args: []any{uint64(1747945619), uint64(1747983448), "passed", "passed", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ Warnings: []string{"Key `education[].parameters` is ambiguous, found 2 different combinations of field context / data type: [name=education[].parameters,context=body,datatype=[]float64,jsondatatype=Array(Nullable(Float64)) name=education[].parameters,context=body,datatype=[]dynamic,jsondatatype=Array(Dynamic)]."},},- expectedErr: nil,},{- name: "Key inside Array(JSON) contains value",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "body.education[].parameters Contains 1.65"},- Limit: 10,+ name: "Dynamic array contains String",+ filter: "body.education[].parameters Contains 'passed'",+ expected: TestExpected{+ WhereClause: "(((arrayExists(`body_v2.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))')) OR arrayExists(x -> toString(x) = ?, dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))'))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')) OR ((arrayExists(`body_v2.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), arrayFilter(x->(dynamicType(x) IN ('String', 'Int64', 'Float64', 'Bool')), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)'))) OR arrayExists(x -> toString(x) = ?, arrayFilter(x->(dynamicType(x) IN ('String', 'Int64', 'Float64', 'Bool')), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)')))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')))",+ Args: []any{uint64(1747945619), uint64(1747983448), "%passed%", "passed", "%passed%", "passed", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ Warnings: []string{"Key `education[].parameters` is ambiguous, found 2 different combinations of field context / data type: [name=education[].parameters,context=body,datatype=[]float64,jsondatatype=Array(Nullable(Float64)) name=education[].parameters,context=body,datatype=[]dynamic,jsondatatype=Array(Dynamic)]."},},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND ((arrayExists(`body_v2.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))')) OR arrayExists(x -> toFloat64(x) = ?, dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))'))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')) OR arrayExists(`body_promoted.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), dynamicElement(`body_promoted.education`.`parameters`, 'Array(Nullable(Float64))')) OR arrayExists(x -> toFloat64(x) = ?, dynamicElement(`body_promoted.education`.`parameters`, 'Array(Nullable(Float64))'))), dynamicElement(body_promoted.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))'))) OR (arrayExists(`body_v2.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), arrayMap(x->dynamicElement(x, 'Float64'), arrayFilter(x->(dynamicType(x) = 'Float64'), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)')))) OR arrayExists(x -> toFloat64(x) = ?, arrayMap(x->dynamicElement(x, 'Float64'), arrayFilter(x->(dynamicType(x) = 'Float64'), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')) OR arrayExists(`body_promoted.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), arrayMap(x->dynamicElement(x, 'Float64'), arrayFilter(x->(dynamicType(x) = 'Float64'), dynamicElement(`body_promoted.education`.`parameters`, 'Array(Dynamic)')))) OR arrayExists(x -> toFloat64(x) = ?, arrayMap(x->dynamicElement(x, 'Float64'), arrayFilter(x->(dynamicType(x) = 'Float64'), dynamicElement(`body_promoted.education`.`parameters`, 'Array(Dynamic)'))))), dynamicElement(body_promoted.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))')))) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "%1.65%", 1.65, "%1.65%", 1.65, "%1.65%", 1.65, "%1.65%", 1.65, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},- Warnings: []string{"Key `education[].parameters` is ambiguous, found 2 different combinations of field context / data type: [name=education[].parameters,context=body,datatype=[]float64,materialized=true,jsondatatype=Array(Nullable(Float64)) name=education[].parameters,context=body,datatype=[]dynamic,materialized=true,jsondatatype=Array(Dynamic)]."},+ },+ {+ name: "Dynamic array IN Operator",+ filter: "body.education[].parameters IN [1.65, 1.99]",+ expected: TestExpected{+ WhereClause: "(((arrayExists(`body_v2.education`-> arrayExists(x -> toFloat64(x) IN (?, ?), dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))')), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')) OR ((arrayExists(`body_v2.education`-> arrayExists(x -> toString(x) IN (?, ?), arrayFilter(x->(dynamicType(x) IN ('String', 'Int64', 'Float64', 'Bool')), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)'))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education')))",+ Args: []any{uint64(1747945619), uint64(1747983448), 1.65, 1.99, "1.65", "1.99", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ Warnings: []string{"Key `education[].parameters` is ambiguous, found 2 different combinations of field context / data type: [name=education[].parameters,context=body,datatype=[]float64,jsondatatype=Array(Nullable(Float64)) name=education[].parameters,context=body,datatype=[]dynamic,jsondatatype=Array(Dynamic)]."},},- expectedErr: nil,},{- name: "Key inside Array(JSON) contains String value",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "body.education[].name Contains 'IIT'"},- Limit: 10,+ name: "Terminal array NotContains float",+ filter: "body.education[].parameters NOT CONTAINS 1.65",+ expected: TestExpected{+ WhereClause: "((NOT arrayExists(`body_v2.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))')) OR arrayExists(x -> toFloat64(x) = ?, dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))'))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND (NOT arrayExists(`body_v2.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), arrayFilter(x->(dynamicType(x) IN ('String', 'Int64', 'Float64', 'Bool')), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)'))) OR arrayExists(x -> accurateCastOrNull(x, 'Float64') = ?, arrayFilter(x->(dynamicType(x) IN ('String', 'Int64', 'Float64', 'Bool')), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)')))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))))",+ Args: []any{uint64(1747945619), uint64(1747983448), "%1.65%", float64(1.65), "%1.65%", float64(1.65), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ Warnings: []string{"Key `education[].parameters` is ambiguous, found 2 different combinations of field context / data type: [name=education[].parameters,context=body,datatype=[]float64,jsondatatype=Array(Nullable(Float64)) name=education[].parameters,context=body,datatype=[]dynamic,jsondatatype=Array(Dynamic)]."},},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (arrayExists(`body_v2.education`-> LOWER(dynamicElement(`body_v2.education`.`name`, 'String')) LIKE LOWER(?), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')) OR arrayExists(`body_promoted.education`-> LOWER(dynamicElement(`body_promoted.education`.`name`, 'String')) LIKE LOWER(?), dynamicElement(body_promoted.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))'))) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "%IIT%", "%IIT%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ {+ name: "Simple has filter",+ filter: "has(body.education[].parameters, 1.65)",+ expected: TestExpected{+ WhereClause: "(has(arrayFlatten(arrayConcat(arrayMap(`body_v2.education`->dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))'), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')))), ?) OR has(arrayFlatten(arrayConcat(arrayMap(`body_v2.education`->dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)'), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')))), ?))",+ Args: []any{uint64(1747945619), uint64(1747983448), 1.65, 1.65, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ Warnings: []string{+ "Key `education[].parameters` is ambiguous, found 2 different combinations of field context / data type: [name=education[].parameters,context=body,datatype=[]float64,jsondatatype=Array(Nullable(Float64)) name=education[].parameters,context=body,datatype=[]dynamic,jsondatatype=Array(Dynamic)].",+ },},- expectedErr: nil,},{- name: "Dynamic array contains boolean",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "body.education[].parameters Contains true"},- Limit: 10,+ name: "Flat path hasAll filter",+ filter: "hasAll(body.user.permissions, ['read', 'write'])",+ expected: TestExpected{+ WhereClause: "hasAll(dynamicElement(body_v2.`user.permissions`, 'Array(Nullable(String))'), ?)",+ Args: []any{uint64(1747945619), uint64(1747983448), []any{[]any{"read", "write"}}, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND ((arrayExists(`body_v2.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))')) OR arrayExists(x -> x = ?, dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))'))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')) OR arrayExists(`body_promoted.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), dynamicElement(`body_promoted.education`.`parameters`, 'Array(Nullable(Float64))')) OR arrayExists(x -> x = ?, dynamicElement(`body_promoted.education`.`parameters`, 'Array(Nullable(Float64))'))), dynamicElement(body_promoted.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))'))) OR (arrayExists(`body_v2.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), arrayMap(x->dynamicElement(x, 'Bool'), arrayFilter(x->(dynamicType(x) = 'Bool'), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)')))) OR arrayExists(x -> x = ?, arrayMap(x->dynamicElement(x, 'Bool'), arrayFilter(x->(dynamicType(x) = 'Bool'), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')) OR arrayExists(`body_promoted.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), arrayMap(x->dynamicElement(x, 'Bool'), arrayFilter(x->(dynamicType(x) = 'Bool'), dynamicElement(`body_promoted.education`.`parameters`, 'Array(Dynamic)')))) OR arrayExists(x -> x = ?, arrayMap(x->dynamicElement(x, 'Bool'), arrayFilter(x->(dynamicType(x) = 'Bool'), dynamicElement(`body_promoted.education`.`parameters`, 'Array(Dynamic)'))))), dynamicElement(body_promoted.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))')))) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "%true%", true, "%true%", true, "%true%", true, "%true%", true, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},- Warnings: []string{"Key `education[].parameters` is ambiguous, found 2 different combinations of field context / data type: [name=education[].parameters,context=body,datatype=[]float64,materialized=true,jsondatatype=Array(Nullable(Float64)) name=education[].parameters,context=body,datatype=[]dynamic,materialized=true,jsondatatype=Array(Dynamic)]."},+ },++ // ── non-array intermediate hop (x[].y.z) ────────────────────────────────+ {+ name: "Non-array intermediate NotEqual",+ filter: "body.http-events[].request-info.host != 'example.com'",+ expected: TestExpected{+ WhereClause: "(NOT arrayExists(`body_v2.http-events`-> dynamicElement(`body_v2.http-events`.`request-info.host`, 'String') = ?, dynamicElement(body_v2.`http-events`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')))",+ Args: []any{uint64(1747945619), uint64(1747983448), "example.com", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expectedErr: nil,},++ // ── double-hop (x[].y[].z) ──────────────────────────────────────────────{- name: "Dynamic array contains String",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "body.education[].parameters Contains 'passed'"},- Limit: 10,+ name: "Key inside Array(JSON) -> Array(Dynamic) + Array(JSON) exists",+ filter: "body.education[].awards[].name Exists",+ expected: TestExpected{+ WhereClause: "(arrayExists(`body_v2.education`-> (arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`name`, 'String') IS NOT NULL, dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`name`, 'String') IS NOT NULL, arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')))",+ Args: []any{uint64(1747945619), uint64(1747983448), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND ((arrayExists(`body_v2.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))')) OR arrayExists(x -> toString(x) = ?, dynamicElement(`body_v2.education`.`parameters`, 'Array(Nullable(Float64))'))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')) OR arrayExists(`body_promoted.education`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), dynamicElement(`body_promoted.education`.`parameters`, 'Array(Nullable(Float64))')) OR arrayExists(x -> toString(x) = ?, dynamicElement(`body_promoted.education`.`parameters`, 'Array(Nullable(Float64))'))), dynamicElement(body_promoted.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))'))) OR (arrayExists(`body_v2.education`-> (arrayExists(x -> LOWER(x) LIKE LOWER(?), arrayMap(x->dynamicElement(x, 'String'), arrayFilter(x->(dynamicType(x) = 'String'), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)')))) OR arrayExists(x -> x = ?, arrayMap(x->dynamicElement(x, 'String'), arrayFilter(x->(dynamicType(x) = 'String'), dynamicElement(`body_v2.education`.`parameters`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')) OR arrayExists(`body_promoted.education`-> (arrayExists(x -> LOWER(x) LIKE LOWER(?), arrayMap(x->dynamicElement(x, 'String'), arrayFilter(x->(dynamicType(x) = 'String'), dynamicElement(`body_promoted.education`.`parameters`, 'Array(Dynamic)')))) OR arrayExists(x -> x = ?, arrayMap(x->dynamicElement(x, 'String'), arrayFilter(x->(dynamicType(x) = 'String'), dynamicElement(`body_promoted.education`.`parameters`, 'Array(Dynamic)'))))), dynamicElement(body_promoted.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))')))) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "%passed%", "passed", "%passed%", "passed", "%passed%", "passed", "%passed%", "passed", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},- Warnings: []string{"Key `education[].parameters` is ambiguous, found 2 different combinations of field context / data type: [name=education[].parameters,context=body,datatype=[]float64,materialized=true,jsondatatype=Array(Nullable(Float64)) name=education[].parameters,context=body,datatype=[]dynamic,materialized=true,jsondatatype=Array(Dynamic)]."},+ },+ {+ name: "Key inside Array(JSON) -> Array(Dynamic) + Array(JSON) = 'Iron Award'",+ filter: "body.education[].awards[].name = 'Iron Award'",+ expected: TestExpected{+ WhereClause: "((arrayExists(`body_v2.education`-> (arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`name`, 'String') = ?, dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`name`, 'String') = ?, arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education'))",+ Args: []any{uint64(1747945619), uint64(1747983448), "Iron Award", "Iron Award", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expectedErr: nil,},{- name: "Array(Dynamic) + Array(JSON) both can contain a value",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "body.education[].awards[].type = 'sports'"},- Limit: 10,+ name: "Integer BETWEEN Operator",+ filter: "education[].awards[].semester BETWEEN 2 AND 4",+ expected: TestExpected{+ WhereClause: "((arrayExists(`body_v2.education`-> (arrayExists(`body_v2.education[].awards`-> toFloat64(dynamicElement(`body_v2.education[].awards`.`semester`, 'Int64')) BETWEEN ? AND ?, dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards`-> toFloat64(dynamicElement(`body_v2.education[].awards`.`semester`, 'Int64')) BETWEEN ? AND ?, arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education'))",+ Args: []any{uint64(1747945619), uint64(1747983448), float64(2), float64(4), float64(2), float64(4), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (arrayExists(`body_v2.education`-> (arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`type`, 'String') = ?, dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`type`, 'String') = ?, arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')) OR arrayExists(`body_promoted.education`-> (arrayExists(`body_promoted.education[].awards`-> dynamicElement(`body_promoted.education[].awards`.`type`, 'String') = ?, dynamicElement(`body_promoted.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=64))')) OR arrayExists(`body_promoted.education[].awards`-> dynamicElement(`body_promoted.education[].awards`.`type`, 'String') = ?, arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_promoted.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_promoted.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))'))) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "sports", "sports", "sports", "sports", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ {+ name: "Integer IN Operator",+ filter: "education[].awards[].semester IN [2, 4]",+ expected: TestExpected{+ WhereClause: "((arrayExists(`body_v2.education`-> (arrayExists(`body_v2.education[].awards`-> toFloat64(dynamicElement(`body_v2.education[].awards`.`semester`, 'Int64')) IN (?, ?), dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards`-> toFloat64(dynamicElement(`body_v2.education[].awards`.`semester`, 'Int64')) IN (?, ?), arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education'))",+ Args: []any{uint64(1747945619), uint64(1747983448), float64(2), float64(4), float64(2), float64(4), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expectedErr: nil,},{- name: "Multi nested Array(Dynamic) + Array(JSON) both can contain a value",- requestType: qbtypes.RequestTypeRaw,- query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{- Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "body.education[].awards[].participated[].team[].branch Contains 'Civil'"},- Limit: 10,+ name: "Nested array NotEqual",+ filter: "body.education[].awards[].type != 'sports'",+ expected: TestExpected{+ WhereClause: "(NOT arrayExists(`body_v2.education`-> (arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`type`, 'String') = ?, dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`type`, 'String') = ?, arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')))",+ Args: []any{uint64(1747945619), uint64(1747983448), "sports", "sports", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (arrayExists(`body_v2.education`-> (arrayExists(`body_v2.education[].awards`-> (arrayExists(`body_v2.education[].awards[].participated`-> arrayExists(`body_v2.education[].awards[].participated[].team`-> LOWER(dynamicElement(`body_v2.education[].awards[].participated[].team`.`branch`, 'String')) LIKE LOWER(?), dynamicElement(`body_v2.education[].awards[].participated`.`team`, 'Array(JSON(max_dynamic_types=2, max_dynamic_paths=0))')), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(JSON(max_dynamic_types=4, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards[].participated`-> arrayExists(`body_v2.education[].awards[].participated[].team`-> LOWER(dynamicElement(`body_v2.education[].awards[].participated[].team`.`branch`, 'String')) LIKE LOWER(?), dynamicElement(`body_v2.education[].awards[].participated`.`team`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))')), arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(Dynamic)'))))), dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards`-> (arrayExists(`body_v2.education[].awards[].participated`-> arrayExists(`body_v2.education[].awards[].participated[].team`-> LOWER(dynamicElement(`body_v2.education[].awards[].participated[].team`.`branch`, 'String')) LIKE LOWER(?), dynamicElement(`body_v2.education[].awards[].participated`.`team`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=64))')), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))')) OR arrayExists(`body_v2.education[].awards[].participated`-> arrayExists(`body_v2.education[].awards[].participated[].team`-> LOWER(dynamicElement(`body_v2.education[].awards[].participated[].team`.`branch`, 'String')) LIKE LOWER(?), dynamicElement(`body_v2.education[].awards[].participated`.`team`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))')), arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(Dynamic)'))))), arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')) OR arrayExists(`body_promoted.education`-> (arrayExists(`body_promoted.education[].awards`-> (arrayExists(`body_promoted.education[].awards[].participated`-> arrayExists(`body_promoted.education[].awards[].participated[].team`-> LOWER(dynamicElement(`body_promoted.education[].awards[].participated[].team`.`branch`, 'String')) LIKE LOWER(?), dynamicElement(`body_promoted.education[].awards[].participated`.`team`, 'Array(JSON(max_dynamic_types=2, max_dynamic_paths=4))')), dynamicElement(`body_promoted.education[].awards`.`participated`, 'Array(JSON(max_dynamic_types=4, max_dynamic_paths=16))')) OR arrayExists(`body_promoted.education[].awards[].participated`-> arrayExists(`body_promoted.education[].awards[].participated[].team`-> LOWER(dynamicElement(`body_promoted.education[].awards[].participated[].team`.`branch`, 'String')) LIKE LOWER(?), dynamicElement(`body_promoted.education[].awards[].participated`.`team`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))')), arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_promoted.education[].awards`.`participated`, 'Array(Dynamic)'))))), dynamicElement(`body_promoted.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=64))')) OR arrayExists(`body_promoted.education[].awards`-> (arrayExists(`body_promoted.education[].awards[].participated`-> arrayExists(`body_promoted.education[].awards[].participated[].team`-> LOWER(dynamicElement(`body_promoted.education[].awards[].participated[].team`.`branch`, 'String')) LIKE LOWER(?), dynamicElement(`body_promoted.education[].awards[].participated`.`team`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=64))')), dynamicElement(`body_promoted.education[].awards`.`participated`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))')) OR arrayExists(`body_promoted.education[].awards[].participated`-> arrayExists(`body_promoted.education[].awards[].participated[].team`-> LOWER(dynamicElement(`body_promoted.education[].awards[].participated[].team`.`branch`, 'String')) LIKE LOWER(?), dynamicElement(`body_promoted.education[].awards[].participated`.`team`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))')), arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_promoted.education[].awards`.`participated`, 'Array(Dynamic)'))))), arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_promoted.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_promoted.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))'))) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "%Civil%", "%Civil%", "%Civil%", "%Civil%", "%Civil%", "%Civil%", "%Civil%", "%Civil%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ {+ name: "Nested array NotExists",+ filter: "body.education[].awards[].name NOT EXISTS",+ expected: TestExpected{+ WhereClause: "(NOT arrayExists(`body_v2.education`-> (arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`name`, 'String') IS NOT NULL, dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards`-> dynamicElement(`body_v2.education[].awards`.`name`, 'String') IS NOT NULL, arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')))",+ Args: []any{uint64(1747945619), uint64(1747983448), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },++ // ── deep multi-hop (x[].y[].z[].w...) ──────────────────────────────────+ {+ name: "Super nested array contains Int64 value",+ filter: "body.interests[].entities[].reviews[].entries[].metadata[].positions[].ratings Contains 4",+ expected: TestExpected{+ WhereClause: "(((arrayExists(`body_v2.interests`-> arrayExists(`body_v2.interests[].entities`-> arrayExists(`body_v2.interests[].entities[].reviews`-> arrayExists(`body_v2.interests[].entities[].reviews[].entries`-> arrayExists(`body_v2.interests[].entities[].reviews[].entries[].metadata`-> arrayExists(`body_v2.interests[].entities[].reviews[].entries[].metadata[].positions`-> (arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), dynamicElement(`body_v2.interests[].entities[].reviews[].entries[].metadata[].positions`.`ratings`, 'Array(Nullable(Int64))')) OR arrayExists(x -> toFloat64(x) = ?, dynamicElement(`body_v2.interests[].entities[].reviews[].entries[].metadata[].positions`.`ratings`, 'Array(Nullable(Int64))'))), dynamicElement(`body_v2.interests[].entities[].reviews[].entries[].metadata`.`positions`, 'Array(JSON(max_dynamic_types=0, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests[].entities[].reviews[].entries`.`metadata`, 'Array(JSON(max_dynamic_types=1, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests[].entities[].reviews`.`entries`, 'Array(JSON(max_dynamic_types=2, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests[].entities`.`reviews`, 'Array(JSON(max_dynamic_types=4, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests`.`entities`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')), dynamicElement(body_v2.`interests`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'interests')) OR ((arrayExists(`body_v2.interests`-> arrayExists(`body_v2.interests[].entities`-> arrayExists(`body_v2.interests[].entities[].reviews`-> arrayExists(`body_v2.interests[].entities[].reviews[].entries`-> arrayExists(`body_v2.interests[].entities[].reviews[].entries[].metadata`-> arrayExists(`body_v2.interests[].entities[].reviews[].entries[].metadata[].positions`-> (arrayExists(x -> LOWER(x) LIKE LOWER(?), dynamicElement(`body_v2.interests[].entities[].reviews[].entries[].metadata[].positions`.`ratings`, 'Array(Nullable(String))')) OR arrayExists(x -> toFloat64OrNull(x) = ?, dynamicElement(`body_v2.interests[].entities[].reviews[].entries[].metadata[].positions`.`ratings`, 'Array(Nullable(String))'))), dynamicElement(`body_v2.interests[].entities[].reviews[].entries[].metadata`.`positions`, 'Array(JSON(max_dynamic_types=0, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests[].entities[].reviews[].entries`.`metadata`, 'Array(JSON(max_dynamic_types=1, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests[].entities[].reviews`.`entries`, 'Array(JSON(max_dynamic_types=2, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests[].entities`.`reviews`, 'Array(JSON(max_dynamic_types=4, max_dynamic_paths=0))')), dynamicElement(`body_v2.interests`.`entities`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')), dynamicElement(body_v2.`interests`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'interests')))",+ Args: []any{uint64(1747945619), uint64(1747983448), "%4%", float64(4), "%4%", float64(4), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ Warnings: []string{"Key `interests[].entities[].reviews[].entries[].metadata[].positions[].ratings` is ambiguous, found 2 different combinations of field context / data type: [name=interests[].entities[].reviews[].entries[].metadata[].positions[].ratings,context=body,datatype=[]int64,jsondatatype=Array(Nullable(Int64)) name=interests[].entities[].reviews[].entries[].metadata[].positions[].ratings,context=body,datatype=[]string,jsondatatype=Array(Nullable(String))]."},+ },+ },+ {+ name: "Multi nested Array(Dynamic) + Array(JSON) both can contain a value",+ filter: "body.education[].awards[].participated[].team[].branch Contains 'Civil'",+ expected: TestExpected{+ WhereClause: "((arrayExists(`body_v2.education`-> (arrayExists(`body_v2.education[].awards`-> (arrayExists(`body_v2.education[].awards[].participated`-> arrayExists(`body_v2.education[].awards[].participated[].team`-> LOWER(dynamicElement(`body_v2.education[].awards[].participated[].team`.`branch`, 'String')) LIKE LOWER(?), dynamicElement(`body_v2.education[].awards[].participated`.`team`, 'Array(JSON(max_dynamic_types=2, max_dynamic_paths=0))')), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(JSON(max_dynamic_types=4, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards[].participated`-> arrayExists(`body_v2.education[].awards[].participated[].team`-> LOWER(dynamicElement(`body_v2.education[].awards[].participated[].team`.`branch`, 'String')) LIKE LOWER(?), dynamicElement(`body_v2.education[].awards[].participated`.`team`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))')), arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(Dynamic)'))))), dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')) OR arrayExists(`body_v2.education[].awards`-> (arrayExists(`body_v2.education[].awards[].participated`-> arrayExists(`body_v2.education[].awards[].participated[].team`-> LOWER(dynamicElement(`body_v2.education[].awards[].participated[].team`.`branch`, 'String')) LIKE LOWER(?), dynamicElement(`body_v2.education[].awards[].participated`.`team`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=64))')), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))')) OR arrayExists(`body_v2.education[].awards[].participated`-> arrayExists(`body_v2.education[].awards[].participated[].team`-> LOWER(dynamicElement(`body_v2.education[].awards[].participated[].team`.`branch`, 'String')) LIKE LOWER(?), dynamicElement(`body_v2.education[].awards[].participated`.`team`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))')), arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(Dynamic)'))))), arrayMap(x->dynamicElement(x, 'JSON'), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education'))",+ Args: []any{uint64(1747945619), uint64(1747983448), "%Civil%", "%Civil%", "%Civil%", "%Civil%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ {+ // IN on a single-type Int64 array terminal: any element of scores IN {90, 95}+ name: "Terminal Int64 array IN operator",+ filter: "body.education[].scores IN [90, 95]",+ expected: TestExpected{+ WhereClause: "((arrayExists(`body_v2.education`-> arrayExists(x -> toFloat64(x) IN (?, ?), dynamicElement(`body_v2.education`.`scores`, 'Array(Nullable(Int64))')), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education'))",+ Args: []any{uint64(1747945619), uint64(1747983448), float64(90), float64(95), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ {+ // NOT IN on a single-type Int64 array terminal: no element of scores IN {90, 95}.+ // Negative operator → NOT wraps outer arrayExists; no path-index guard added.+ name: "Terminal Int64 array NOT IN operator",+ filter: "body.education[].scores NOT IN [90, 95]",+ expected: TestExpected{+ WhereClause: "(NOT arrayExists(`body_v2.education`-> arrayExists(x -> toFloat64(x) IN (?, ?), dynamicElement(`body_v2.education`.`scores`, 'Array(Nullable(Int64))')), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')))",+ Args: []any{uint64(1747945619), uint64(1747983448), float64(90), float64(95), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ {+ // BETWEEN on a single-type Int64 array terminal: any element of scores BETWEEN 80 AND 95.+ // BETWEEN is an IsArrayOperator → value arrives as []any{80,95} → c.valueType.IsArray=true.+ name: "Terminal Int64 array BETWEEN operator",+ filter: "body.education[].scores BETWEEN 80 AND 95",+ expected: TestExpected{+ WhereClause: "((arrayExists(`body_v2.education`-> arrayExists(x -> toFloat64(x) BETWEEN ? AND ?, dynamicElement(`body_v2.education`.`scores`, 'Array(Nullable(Int64))')), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))'))) AND has(JSONAllPaths(body_v2), 'education'))",+ Args: []any{uint64(1747945619), uint64(1747983448), float64(80), float64(95), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ {+ // NOT BETWEEN on a single-type Int64 array terminal: no element BETWEEN 80 AND 95.+ // Negative → NOT wraps outer arrayExists; no path-index guard.+ name: "Terminal Int64 array NOT BETWEEN operator",+ filter: "body.education[].scores NOT BETWEEN 80 AND 95",+ expected: TestExpected{+ WhereClause: "(NOT arrayExists(`body_v2.education`-> arrayExists(x -> toFloat64(x) BETWEEN ? AND ?, dynamicElement(`body_v2.education`.`scores`, 'Array(Nullable(Int64))')), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')))",+ Args: []any{uint64(1747945619), uint64(1747983448), float64(80), float64(95), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ {+ name: "Nested path hasAny filter",+ filter: "hasAny(education[].awards[].participated[].members, ['Piyush', 'Tushar'])",+ expected: TestExpected{+ WhereClause: "hasAny(arrayFlatten(arrayConcat(arrayMap(`body_v2.education`->arrayConcat(arrayMap(`body_v2.education[].awards`->arrayConcat(arrayMap(`body_v2.education[].awards[].participated`->dynamicElement(`body_v2.education[].awards[].participated`.`members`, 'Array(Nullable(String))'), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(JSON(max_dynamic_types=4, max_dynamic_paths=0))')), arrayMap(`body_v2.education[].awards[].participated`->dynamicElement(`body_v2.education[].awards[].participated`.`members`, 'Array(Nullable(String))'), arrayMap(x->assumeNotNull(dynamicElement(x, 'JSON')), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(Dynamic)'))))), dynamicElement(`body_v2.education`.`awards`, 'Array(JSON(max_dynamic_types=8, max_dynamic_paths=0))')), arrayMap(`body_v2.education[].awards`->arrayConcat(arrayMap(`body_v2.education[].awards[].participated`->dynamicElement(`body_v2.education[].awards[].participated`.`members`, 'Array(Nullable(String))'), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))')), arrayMap(`body_v2.education[].awards[].participated`->dynamicElement(`body_v2.education[].awards[].participated`.`members`, 'Array(Nullable(String))'), arrayMap(x->assumeNotNull(dynamicElement(x, 'JSON')), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education[].awards`.`participated`, 'Array(Dynamic)'))))), arrayMap(x->assumeNotNull(dynamicElement(x, 'JSON')), arrayFilter(x->(dynamicType(x) = 'JSON'), dynamicElement(`body_v2.education`.`awards`, 'Array(Dynamic)'))))), dynamicElement(body_v2.`education`, 'Array(JSON(max_dynamic_types=16, max_dynamic_paths=0))')))), ?)",+ Args: []any{uint64(1747945619), uint64(1747983448), []any{[]any{"Piyush", "Tushar"}}, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ {+ name: "dynamic array element comparison",+ filter: "ids Contains 1",+ expected: TestExpected{+ WhereClause: "(((arrayExists(x -> LOWER(toString(x)) LIKE LOWER(?), arrayFilter(x->(dynamicType(x) IN ('String', 'Int64', 'Float64', 'Bool')), dynamicElement(body_v2.`ids`, 'Array(Dynamic)'))) OR arrayExists(x -> accurateCastOrNull(x, 'Float64') = ?, arrayFilter(x->(dynamicType(x) IN ('String', 'Int64', 'Float64', 'Bool')), dynamicElement(body_v2.`ids`, 'Array(Dynamic)'))))) AND has(JSONAllPaths(body_v2), 'ids'))",+ Args: []any{uint64(1747945619), uint64(1747983448), "%1%", float64(1), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ {+ name: "dynamic array element comparison",+ filter: "ids != '1'",+ expected: TestExpected{+ WhereClause: "(NOT arrayExists(x -> accurateCastOrNull(x, 'Float64') = ?, arrayFilter(x->(dynamicType(x) IN ('String', 'Int64', 'Float64', 'Bool')), dynamicElement(body_v2.`ids`, 'Array(Dynamic)'))))",+ Args: []any{uint64(1747945619), uint64(1747983448), int64(1), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ {+ name: "dynamic array element comparison boolean",+ filter: "ids = true",+ expected: TestExpected{+ WhereClause: "((arrayExists(x -> accurateCastOrNull(x, 'Bool') = ?, arrayFilter(x->(dynamicType(x) IN ('String', 'Int64', 'Float64', 'Bool')), dynamicElement(body_v2.`ids`, 'Array(Dynamic)')))) AND has(JSONAllPaths(body_v2), 'ids'))",+ Args: []any{uint64(1747945619), uint64(1747983448), true, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expectedErr: nil,},}for _, c := range cases {t.Run(c.name, func(t *testing.T) {-- q, err := statementBuilder.Build(context.Background(), 1747947419000, 1747983448000, c.requestType, c.query, nil)-+ q, err := statementBuilder.Build(context.Background(), 1747947419000, 1747983448000, qbtypes.RequestTypeRaw,+ qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{+ Signal: telemetrytypes.SignalLogs,+ Filter: &qbtypes.Filter{Expression: c.filter},+ Limit: 10,+ }, nil)if c.expectedErr != nil {require.Error(t, err)require.Contains(t, err.Error(), c.expectedErr.Error())- } else {- require.NoError(t, err)- require.Equal(t, c.expected.Query, q.Query)- require.Equal(t, c.expected.Args, q.Args)- require.Equal(t, c.expected.Warnings, q.Warnings)+ return}+ require.NoError(t, err)+ require.Equal(t, c.expected.GetQuery(), q.Query)+ require.Equal(t, c.expected.Args, q.Args)+ require.Equal(t, c.expected.Warnings, q.Warnings)})}}-*/-func TestStatementBuilderListQueryBodyMessage(t *testing.T) {+func TestJSONStmtBuilder_IndexedPaths(t *testing.T) {enable, disable := jsonQueryTestUtil(t)enable()defer disable()- statementBuilder := buildJSONTestStatementBuilder(t)+ statementBuilder := buildJSONTestStatementBuilder(t, true)cases := []struct {name string- requestType qbtypes.RequestTypequery qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]- expected qbtypes.Statement+ expected TestExpectedexpectedErr error}{+ // ── indexed equal: emits assumeNotNull(dynamicElement) = ? ───────────{- name: "message Exists",- requestType: qbtypes.RequestTypeRaw,+ name: "Indexed String Equal",query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "message Exists"},+ Filter: &qbtypes.Filter{Expression: "body.user.name = 'alice'"},Limit: 10,},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND body_v2.message <> ? AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ expected: TestExpected{+ WhereClause: "((assumeNotNull(dynamicElement(body_v2.`user.name`, 'String')) = ?) AND has(JSONAllPaths(body_v2), 'user.name'))",+ Args: []any{uint64(1747945619), uint64(1747983448), "alice", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expectedErr: nil,},{- name: "body.message equals to empty string",- requestType: qbtypes.RequestTypeRaw,+ name: "Indexed Int64 Equal",query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "body.message = ''"},+ Filter: &qbtypes.Filter{Expression: "body.user.address.zip = 110001"},Limit: 10,},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND body_v2.message = ? AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ expected: TestExpected{+ WhereClause: "((toFloat64(assumeNotNull(dynamicElement(body_v2.`user.address.zip`, 'Int64'))) = ?) AND has(JSONAllPaths(body_v2), 'user.address.zip'))",+ Args: []any{uint64(1747945619), uint64(1747983448), float64(110001), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expectedErr: nil,},+ // ── indexed exists: emits assumeNotNull != nil AND dynamicElement IS NOT NULL ─{- name: "body.message equals to 'Iron Award'",- requestType: qbtypes.RequestTypeRaw,+ name: "Indexed String Exists",query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "body.message = 'Iron Award'"},+ Filter: &qbtypes.Filter{Expression: "body.user.name Exists"},Limit: 10,},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND body_v2.message = ? AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "Iron Award", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ expected: TestExpected{+ WhereClause: "((assumeNotNull(dynamicElement(body_v2.`user.name`, 'String')) <> ? AND dynamicElement(body_v2.`user.name`, 'String') IS NOT NULL))",+ Args: []any{uint64(1747945619), uint64(1747983448), "", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expectedErr: nil,},+ // ── indexed not-equal: assumeNotNull wrapping + no path index ─────────{- name: "message contains 'Iron Award'",- requestType: qbtypes.RequestTypeRaw,+ name: "Indexed String NotEqual",query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{Signal: telemetrytypes.SignalLogs,- Filter: &qbtypes.Filter{Expression: "message Contains 'Iron Award'"},+ Filter: &qbtypes.Filter{Expression: "body.user.name != 'alice'"},Limit: 10,},- expected: qbtypes.Statement{- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body_v2 as body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND LOWER(body_v2.message) LIKE LOWER(?) AND timestamp >= ? AND ts_bucket_start >= ? AND timestamp < ? AND ts_bucket_start <= ? LIMIT ?",- Args: []any{uint64(1747945619), uint64(1747983448), "%Iron Award%", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ expected: TestExpected{+ WhereClause: "(assumeNotNull(dynamicElement(body_v2.`user.name`, 'String')) <> ?)",+ Args: []any{uint64(1747945619), uint64(1747983448), "alice", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ // ── indexed not-exists: assumeNotNull = "" AND assumeNotNull IS NOT NULL ─+ // FilterOperatorNotExists → Equal + emptyValue("") in the indexed branch,+ // then a second condition flipped to Exists (IS NOT NULL) on the same+ // assumeNotNull expr, producing AND(= "", IS NOT NULL).+ {+ name: "Indexed String NotExists",+ query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{+ Signal: telemetrytypes.SignalLogs,+ Filter: &qbtypes.Filter{Expression: "body.user.name NOT EXISTS"},+ Limit: 10,+ },+ expected: TestExpected{+ WhereClause: "((assumeNotNull(dynamicElement(body_v2.`user.name`, 'String')) = ? AND dynamicElement(body_v2.`user.name`, 'String') IS NULL))",+ Args: []any{uint64(1747945619), uint64(1747983448), "", "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },++ // ── special-character indexed paths ───────────────────────────────────+ {+ name: "Indexed hyphen key Equal",+ query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{+ Signal: telemetrytypes.SignalLogs,+ Filter: &qbtypes.Filter{Expression: "body.http-status = 200"},+ Limit: 10,+ },+ expected: TestExpected{+ WhereClause: "(((toFloat64(assumeNotNull(dynamicElement(body_v2.`http-status`, 'Int64'))) = ?) AND has(JSONAllPaths(body_v2), 'http-status')) OR ((toFloat64OrNull(assumeNotNull(dynamicElement(body_v2.`http-status`, 'String'))) = ?) AND has(JSONAllPaths(body_v2), 'http-status')))",+ Args: []any{uint64(1747945619), uint64(1747983448), float64(200), float64(200), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ {+ name: "Indexed nested hyphen key Equal",+ query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{+ Signal: telemetrytypes.SignalLogs,+ Filter: &qbtypes.Filter{Expression: "body.response.time-taken > 1.5"},+ Limit: 10,+ },+ expected: TestExpected{+ WhereClause: "((toFloat64(assumeNotNull(dynamicElement(body_v2.`response.time-taken`, 'Float64'))) > ?) AND has(JSONAllPaths(body_v2), 'response.time-taken'))",+ Args: []any{uint64(1747945619), uint64(1747983448), float64(1.5), "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},+ },+ },+ // ── Bool is NOT IndexSupported — index branch must be skipped ─────────+ // user.active is Bool; even with indexed builder it must not use the index.+ {+ name: "Bool skips index — Equal",+ query: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{+ Signal: telemetrytypes.SignalLogs,+ Filter: &qbtypes.Filter{Expression: "body.user.active = true"},+ Limit: 10,+ },+ expected: TestExpected{+ WhereClause: "((dynamicElement(body_v2.`user.active`, 'Bool') = ?) AND has(JSONAllPaths(body_v2), 'user.active'))",+ Args: []any{uint64(1747945619), uint64(1747983448), true, "1747947419000000000", uint64(1747945619), "1747983448000000000", uint64(1747983448), 10},},- expectedErr: nil,},}for _, c := range cases {t.Run(c.name, func(t *testing.T) {- q, err := statementBuilder.Build(context.Background(), 1747947419000, 1747983448000, c.requestType, c.query, nil)+ q, err := statementBuilder.Build(context.Background(), 1747947419000, 1747983448000, qbtypes.RequestTypeRaw, c.query, nil)if c.expectedErr != nil {require.Error(t, err)require.Contains(t, err.Error(), c.expectedErr.Error())- } else {- require.NoError(t, err)- require.Equal(t, c.expected.Query, q.Query)- require.Equal(t, c.expected.Args, q.Args)- require.Equal(t, c.expected.Warnings, q.Warnings)+ return}+ require.NoError(t, err)+ require.Equal(t, c.expected.GetQuery(), q.Query)+ require.Equal(t, c.expected.Args, q.Args)})}}--func buildTestTelemetryMetadataStore(t *testing.T) *telemetrytypestest.MockMetadataStore {+func buildTestTelemetryMetadataStore(t *testing.T, addIndexes bool) *telemetrytypestest.MockMetadataStore {mockMetadataStore := telemetrytypestest.NewMockMetadataStore()mockMetadataStore.SetStaticFields(IntrinsicFields)types, _ := telemetrytypes.TestJSONTypeSet()for path, jsonTypes := range types {- // promoted := false-- // split := strings.Split(path, telemetrytypes.ArraySep)- // if slices.Contains(promotedPaths, split[0]) {- // promoted = true- // }- // Create a TelemetryFieldKey for each JSONDataType for this path- // Since a path can have multiple types, we create one key per typefor _, jsonType := range jsonTypes {key := &telemetrytypes.TelemetryFieldKey{Name: path,@@ -813,13 +954,25 @@ func buildTestTelemetryMetadataStore(t *testing.T) *telemetrytypestest.MockMetadFieldContext: telemetrytypes.FieldContextBody,FieldDataType: telemetrytypes.MappingJSONDataTypeToFieldDataType[jsonType],JSONDataType: &jsonType,- // Materialized: promoted,}+ if addIndexes {+ idx := slices.IndexFunc(telemetrytypes.TestIndexedPaths, func(entry telemetrytypes.TestIndexedPathEntry) bool {+ return entry.Path == path && entry.Type == jsonType+ })+ if idx >= 0 {+ key.Indexes = append(key.Indexes, telemetrytypes.JSONDataTypeIndex{+ Type: jsonType,+ ColumnExpression: schemamigrator.JSONSubColumnIndexExpr(LogsV2BodyV2Column, path, jsonType.StringValue()),+ })+ }+ }+err := key.SetJSONAccessPlan(telemetrytypes.JSONColumnMetadata{BaseColumn: LogsV2BodyV2Column,PromotedColumn: LogsV2BodyPromotedColumn,}, types)require.NoError(t, err)+mockMetadataStore.SetKey(key)}}@@ -827,8 +980,8 @@ func buildTestTelemetryMetadataStore(t *testing.T) *telemetrytypestest.MockMetadreturn mockMetadataStore}-func buildJSONTestStatementBuilder(t *testing.T) *logQueryStatementBuilder {- mockMetadataStore := buildTestTelemetryMetadataStore(t)+func buildJSONTestStatementBuilder(t *testing.T, addIndexes bool) *logQueryStatementBuilder {+ mockMetadataStore := buildTestTelemetryMetadataStore(t, addIndexes)fm := NewFieldMapper()cb := NewConditionBuilder(fm)diff --git a/pkg/types/querybuildertypes/querybuildertypesv5/builder_elements.go b/pkg/types/querybuildertypes/querybuildertypesv5/builder_elements.goindex 9e7be9c2ed..cd80356b3d 100644--- a/pkg/types/querybuildertypes/querybuildertypesv5/builder_elements.go+++ b/pkg/types/querybuildertypes/querybuildertypesv5/builder_elements.go@@ -113,6 +113,29 @@ const (FilterOperatorNotContains)+var operatorInverseMapping = map[FilterOperator]FilterOperator{+ FilterOperatorEqual: FilterOperatorNotEqual,+ FilterOperatorNotEqual: FilterOperatorEqual,+ FilterOperatorGreaterThan: FilterOperatorLessThanOrEq,+ FilterOperatorGreaterThanOrEq: FilterOperatorLessThan,+ FilterOperatorLessThan: FilterOperatorGreaterThanOrEq,+ FilterOperatorLessThanOrEq: FilterOperatorGreaterThan,+ FilterOperatorLike: FilterOperatorNotLike,+ FilterOperatorNotLike: FilterOperatorLike,+ FilterOperatorILike: FilterOperatorNotILike,+ FilterOperatorNotILike: FilterOperatorILike,+ FilterOperatorBetween: FilterOperatorNotBetween,+ FilterOperatorNotBetween: FilterOperatorBetween,+ FilterOperatorIn: FilterOperatorNotIn,+ FilterOperatorNotIn: FilterOperatorIn,+ FilterOperatorExists: FilterOperatorNotExists,+ FilterOperatorNotExists: FilterOperatorExists,+ FilterOperatorRegexp: FilterOperatorNotRegexp,+ FilterOperatorNotRegexp: FilterOperatorRegexp,+ FilterOperatorContains: FilterOperatorNotContains,+ FilterOperatorNotContains: FilterOperatorContains,+}+// AddDefaultExistsFilter returns true if addl exists filter should be added to the query// For the negative predicates, we don't want to add the exists filter. Why?// Say for example, user adds a filter `service.name != "redis"`, we can't interpret it@@ -162,6 +185,10 @@ func (f FilterOperator) IsNegativeOperator() bool {return true}+func (f FilterOperator) Inverse() FilterOperator {+ return operatorInverseMapping[f]+}+func (f FilterOperator) IsComparisonOperator() bool {switch f {case FilterOperatorGreaterThan, FilterOperatorGreaterThanOrEq, FilterOperatorLessThan, FilterOperatorLessThanOrEq:diff --git a/pkg/types/telemetrytypes/json_access_plan.go b/pkg/types/telemetrytypes/json_access_plan.goindex e403645090..ee78546846 100644--- a/pkg/types/telemetrytypes/json_access_plan.go+++ b/pkg/types/telemetrytypes/json_access_plan.go@@ -90,6 +90,11 @@ func (n *JSONAccessNode) FieldPath() string {return n.Parent.Alias() + "." + key}+// Returns true if the current node is a non-nested path.+func (n *JSONAccessNode) IsNonNestedPath() bool {+ return !strings.Contains(n.FieldPath(), ArraySep)+}+func (n *JSONAccessNode) BranchesInOrder() []JSONAccessBranchType {return slices.SortedFunc(maps.Keys(n.Branches), func(a, b JSONAccessBranchType) int {return strings.Compare(b.StringValue(), a.StringValue())diff --git a/pkg/types/telemetrytypes/test_data.go b/pkg/types/telemetrytypes/test_data.goindex ef4c96f36d..e229ce6123 100644--- a/pkg/types/telemetrytypes/test_data.go+++ b/pkg/types/telemetrytypes/test_data.go@@ -8,65 +8,101 @@ package telemetrytypes// This represents the type information available in the test JSON structure.func TestJSONTypeSet() (map[string][]JSONDataType, MetadataStore) {types := map[string][]JSONDataType{- "user.name": {String},- "user.permissions": {ArrayString},- "user.age": {Int64, String},- "user.height": {Float64},- "education": {ArrayJSON},- "education[].name": {String},- "education[].type": {String, Int64},- "education[].internal_type": {String},- "education[].metadata.location": {String},- "education[].parameters": {ArrayFloat64, ArrayDynamic},- "education[].duration": {String},- "education[].mode": {String},- "education[].year": {Int64},- "education[].field": {String},- "education[].awards": {ArrayDynamic, ArrayJSON},- "education[].awards[].name": {String},- "education[].awards[].rank": {Int64},- "education[].awards[].medal": {String},- "education[].awards[].type": {String},- "education[].awards[].semester": {Int64},- "education[].awards[].participated": {ArrayDynamic, ArrayJSON},- "education[].awards[].participated[].type": {String},- "education[].awards[].participated[].field": {String},- "education[].awards[].participated[].project_type": {String},- "education[].awards[].participated[].project_name": {String},- "education[].awards[].participated[].race_type": {String},- "education[].awards[].participated[].team_based": {Bool},- "education[].awards[].participated[].team_name": {String},- "education[].awards[].participated[].team": {ArrayJSON},- "education[].awards[].participated[].members": {ArrayString},- "education[].awards[].participated[].team[].name": {String},- "education[].awards[].participated[].team[].branch": {String},- "education[].awards[].participated[].team[].semester": {Int64},- "interests": {ArrayJSON},- "interests[].type": {String},- "interests[].entities": {ArrayJSON},- "interests[].entities.application_date": {String},- "interests[].entities[].reviews": {ArrayJSON},- "interests[].entities[].reviews[].given_by": {String},- "interests[].entities[].reviews[].remarks": {String},- "interests[].entities[].reviews[].weight": {Float64},- "interests[].entities[].reviews[].passed": {Bool},- "interests[].entities[].reviews[].type": {String},- "interests[].entities[].reviews[].analysis_type": {Int64},- "interests[].entities[].reviews[].entries": {ArrayJSON},- "interests[].entities[].reviews[].entries[].subject": {String},- "interests[].entities[].reviews[].entries[].status": {String},- "interests[].entities[].reviews[].entries[].metadata": {ArrayJSON},- "interests[].entities[].reviews[].entries[].metadata[].company": {String},- "interests[].entities[].reviews[].entries[].metadata[].experience": {Int64},- "interests[].entities[].reviews[].entries[].metadata[].unit": {String},- "interests[].entities[].reviews[].entries[].metadata[].positions": {ArrayJSON},- "interests[].entities[].reviews[].entries[].metadata[].positions[].name": {String},- "interests[].entities[].reviews[].entries[].metadata[].positions[].duration": {Int64, Float64},- "interests[].entities[].reviews[].entries[].metadata[].positions[].unit": {String},- "interests[].entities[].reviews[].entries[].metadata[].positions[].ratings": {ArrayInt64, ArrayString},- "message": {String},- "tags": {ArrayString},++ // ── user (primitives) ─────────────────────────────────────────────+ "user.name": {String},+ "user.permissions": {ArrayString},+ "user.age": {Int64, String}, // Int64/String ambiguity+ "user.height": {Float64},+ "user.active": {Bool}, // Bool — not IndexSupported++ // Deeper non-array nesting (a.b.c — no array hops)+ "user.address.zip": {Int64},++ // ── education[] ───────────────────────────────────────────────────+ // Pattern: x[].y+ "education": {ArrayJSON},+ "education[].name": {String},+ "education[].type": {String, Int64},+ "education[].year": {Int64},+ "education[].scores": {ArrayInt64},+ "education[].parameters": {ArrayFloat64, ArrayDynamic},++ // Pattern: x[].y[]+ "education[].awards": {ArrayDynamic, ArrayJSON},++ // Pattern: x[].y[].z+ "education[].awards[].name": {String},+ "education[].awards[].type": {String},+ "education[].awards[].semester": {Int64},++ // Pattern: x[].y[].z[]+ "education[].awards[].participated": {ArrayDynamic, ArrayJSON},++ // Pattern: x[].y[].z[].w+ "education[].awards[].participated[].members": {ArrayString},++ // Pattern: x[].y[].z[].w[]+ "education[].awards[].participated[].team": {ArrayJSON},++ // Pattern: x[].y[].z[].w[].v+ "education[].awards[].participated[].team[].branch": {String},++ // ── interests[] ───────────────────────────────────────────────────+ "interests": {ArrayJSON},+ "interests[].entities": {ArrayJSON},+ "interests[].entities[].reviews": {ArrayJSON},+ "interests[].entities[].reviews[].entries": {ArrayJSON},+ "interests[].entities[].reviews[].entries[].metadata": {ArrayJSON},+ "interests[].entities[].reviews[].entries[].metadata[].positions": {ArrayJSON},+ "interests[].entities[].reviews[].entries[].metadata[].positions[].name": {String},+ "interests[].entities[].reviews[].entries[].metadata[].positions[].ratings": {ArrayInt64, ArrayString},+ "http-events": {ArrayJSON},+ "http-events[].request-info.host": {String},+ "ids": {ArrayDynamic},++ // ── top-level primitives ──────────────────────────────────────────+ "message": {String},+ "http-status": {Int64, String}, // hyphen in root key, ambiguous++ // ── top-level nested objects (no array hops) ───────────────────────+ "response.time-taken": {Float64}, // hyphen inside nested key}return types, nil}++// TestIndexedPathEntry is a path + JSON type pair representing a field+// backed by a ClickHouse skip index in the test data.+//+// Only non-array paths with IndexSupported types (String, Int64, Float64)+// are valid entries — arrays and Bool cannot carry a skip index.+//+// The ColumnExpression for each entry is computed at test-setup time from+// the access plan, since it depends on the column name (e.g. body_v2)+// which is unknown to this package.+type TestIndexedPathEntry struct {+ Path string+ Type JSONDataType+}++// TestIndexedPaths lists path+type pairs from TestJSONTypeSet that are+// backed by a JSON data type index. Test setup uses this to populate+// key.Indexes after calling SetJSONAccessPlan.+//+// Intentionally excluded:+// - user.active → Bool, IndexSupported=false+var TestIndexedPaths = []TestIndexedPathEntry{+ // user primitives+ {Path: "user.name", Type: String},++ // user.address — deeper non-array nesting+ {Path: "user.address.zip", Type: Int64},++ // root-level with special characters+ {Path: "http-status", Type: Int64},+ {Path: "http-status", Type: String},++ // root-level nested objects (no array hops)+ {Path: "response.time-taken", Type: Float64},+}