Skip to content

fix: add canonical name aliasing for select fields#10860

Open
tushar-signoz wants to merge 3 commits intomainfrom
tvats-alias-select-columns
Open

fix: add canonical name aliasing for select fields#10860
tushar-signoz wants to merge 3 commits intomainfrom
tvats-alias-select-columns

Conversation

@tushar-signoz
Copy link
Copy Markdown
Contributor

@tushar-signoz tushar-signoz commented Apr 7, 2026

Summary

  • Alias SELECT columns using canonical names (context;name;datatype) so the querier can correctly map result columns back to their telemetry field keys, even when multiple fields share the same short name.
  • Handle column-name collisions in raw queries by falling back to key.Text() when two columns resolve to the same simple name.
  • Add MaybeAddDefaultSelectFields helper to prepend default fields (id, timestamp) to list queries only when not already present.
  • Propagate non-ErrColumnNotFound errors from FieldFor in CollisionHandledFinalExpr instead of silently swallowing them.

Test plan

  • Updated existing unit tests in json_stmt_builder_test.go and stmt_builder_test.go to match new aliased column names
  • Verify logs list view, time-series, and scalar queries return correct column names end-to-end

🤖 Generated with Claude Code

@github-actions github-actions Bot added the bug Something isn't working label Apr 7, 2026
@tushar-signoz tushar-signoz changed the title fix: alias select columns fix: add canonical name aliasing for select fields in query results Apr 7, 2026
@tushar-signoz tushar-signoz changed the title fix: add canonical name aliasing for select fields in query results fix: add canonical name aliasing for select fields Apr 7, 2026
@tushar-signoz tushar-signoz force-pushed the tvats-alias-select-columns branch from 8bd696d to f1cbc80 Compare April 7, 2026 00:45
Copy link
Copy Markdown
Member

@nityanandagohain nityanandagohain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, have some comments and we should definately add integration test in this PR

Comment thread pkg/querier/consume.go

for idx, ptr := range slots {
name := colNames[idx]
key := telemetrytypes.GetFieldKeyFromCanonicalName(colNames[idx])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is running (rows * column) number of times we should move it out and make it run just column number of times.

// 3 cases:
// 1. log.timestamp:number in select fields; we skip
// 2. timestamp is present in select fields; we skip
// 3. attribute.timestamp in select fields; we add it.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but in the UI we don't have support for this right as of now? so with this change it will return timestamp as well as timestamp in attributes. Did you check if the existing UI breaks and needs some handling before we merge this ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is specifically for api users. signoz UI doesn't specify selectFields

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In trace ui it does specify select fields right ?

) {
var toAdd []telemetrytypes.TelemetryFieldKey
for i := range defaultSelectFields {
if !isDefaultSelectFieldCovered(&defaultSelectFields[i], query.SelectFields) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: create a selectFields map will be better ?


fieldExpression, fieldForErr := fm.FieldFor(ctx, startNs, endNs, field)
if errors.Is(fieldForErr, qbtypes.ErrColumnNotFound) {
if fieldForErr != nil {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the previous change of running the else case if there was any other error was incorrect ?

sb.SelectMore(fmt.Sprintf("`%s` AS `;%s;`", LogsV2ScopeNameColumn, LogsV2ScopeNameColumn))
sb.SelectMore(fmt.Sprintf("`%s` AS `;%s;`", LogsV2ScopeVersionColumn, LogsV2ScopeVersionColumn))
sb.SelectMore(fmt.Sprintf("`%s` AS `;%s;`", LogsV2BodyColumn, LogsV2BodyColumn))
if querybuilder.BodyJSONQueryEnabled {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case I don't think we should select both, we should select old or new. Else handling might be required somewhere else ?

Copy link
Copy Markdown
Member

@nityanandagohain nityanandagohain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • What happens if there is a field field;name . Didn't see a testcase for that

// A select field covers a default field when the names match and the select field's
// context is either unspecified or equal to the default field's context.
// 3 cases:
// 1. log.timestamp:number in select fields; we skip
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If by mistake someone add log.timestamp:string it will be converted to number right, can you add that we dont consider the type and why.

Also add 1/2 unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants