Transformations: Fix true inner join in joinByField transformation (#87409)

* baldm0mma/inner_join_fix/ init commit

* baldm0mma/inner_join_fix/ first attempt at an tabular inner join

* baldm0mma/inner_join_fix/ add innerTabular

* baldm0mma/inner_join_fix/ add innerJoin option to editor

* baldm0mma/inner_join_fix/ add editor option

* baldm0mma/inner_join_fix/ update joinInnerTabular function behavior

* baldm0mma/inner_join_fix/ add js docs

* baldm0mma/inner_join_fix/ update jsdocs

* baldm0mma/inner_join_fix/ update docs

* baldm0mma/inner_join_fix/ remove unused console.logs

* baldm0mma/inner_join_fix/ update tests

* baldm0mma/inner_join_fix/ simplify getValue

* baldm0mma/inner_join_fix/ update tests

* baldm0mma/inner_join_fix/ update docs builder

* baldm0mma/inner_join_fix/ add tables to Outer join (for tabular data)

* baldm0mma/inner_join_fix/ update docs

* baldm0mma/inner_join_fix/ build docs

* baldm0mma/inner_join_fix/ remove innertab for inner

* baldm0mma/inner_join_fix/ rename innertab

* baldm0mma/inner_join_fix/ update tests

* baldm0mma/inner_join_fix/ rem con logs

* baldm0mma/inner_join_fix/ rem comment

* baldm0mma/inner_join_fix/ rem sample data

* baldm0mma/inner_join_fix/ remove irrelevant test

* baldm0mma/inner_join_fix/ update docs

* Update packages/grafana-data/src/transformations/transformers/joinDataFrames.test.ts

Co-authored-by: Nathan Marrs  <nathanielmarrs@gmail.com>

* baldm0mma/inner_join_fix/ update test description

---------

Co-authored-by: nmarrs <nathanielmarrs@gmail.com>
This commit is contained in:
Jev Forsberg
2024-05-09 11:00:59 -06:00
committed by GitHub
parent 06a27911a4
commit 9bd44aed2e
7 changed files with 298 additions and 127 deletions

View File

@ -39,7 +39,7 @@ labels:
- enterprise
- oss
title: Transform data
description: Use transformations to rename fields, join series data, apply mathematical operations, and more
description: Use transformations to rename fields, join time series/SQL-like data, apply mathematical operations, and more
weight: 100
---
@ -48,7 +48,7 @@ weight: 100
Transformations are a powerful way to manipulate data returned by a query before the system applies a visualization. Using transformations, you can:
- Rename fields
- Join time series data
- Join time series/SQL-like data
- Perform mathematical operations across queries
- Use the output of one transformation as the input to another transformation
@ -761,13 +761,13 @@ Use this transformation to merge multiple results into a single table, enabling
This is especially useful for converting multiple time series results into a single wide table with a shared time field.
#### Inner join
#### Inner join (for Time Series or SQL-like data)
An inner join merges data from multiple tables where all tables share the same value from the selected field. This type of join excludes data where values do not match in every result.
Use this transformation to combine the results from multiple queries (combining on a passed join field or the first time column) into one result, and drop rows where a successful join cannot occur.
Use this transformation to combine the results from multiple queries (combining on a passed join field or the first time column) into one result, and drop rows where a successful join cannot occur. This is not optimized for large Time Series datasets.
In the following example, two queries return table data. It is visualized as two separate tables before applying the inner join transformation.
In the following example, two queries return Time Series data. It is visualized as two separate tables before applying the inner join transformation.
**Query A:**
@ -792,7 +792,39 @@ The result after applying the inner join transformation looks like the following
| 2020-07-07 11:34:20 | node | 25260122 | server 1 | 15 |
| 2020-07-07 11:24:20 | postgre | 123001233 | server 2 | 5 |
#### Outer join
This works in the same way for non-Time Series tabular data as well.
**Students**
| StudentID | Name | Major |
| --------- | -------- | ---------------- |
| 1 | John | Computer Science |
| 2 | Emily | Mathematics |
| 3 | Michael | Physics |
| 4 | Jennifer | Chemistry |
**Enrollments**
| StudentID | CourseID | Grade |
| --------- | -------- | ----- |
| 1 | CS101 | A |
| 1 | CS102 | B |
| 2 | MATH201 | A |
| 3 | PHYS101 | B |
| 5 | HIST101 | B |
The result after applying the inner join transformation looks like the following:
| StudentID | Name | Major | CourseID | Grade |
| --------- | ------- | ---------------- | -------- | ----- |
| 1 | John | Computer Science | CS101 | A |
| 1 | John | Computer Science | CS102 | B |
| 2 | Emily | Mathematics | MATH201 | A |
| 3 | Michael | Physics | PHYS101 | B |
The inner join only includes rows where there is a match between the "StudentID" in both tables. In this case, the result does not include "Jennifer" from the "Students" table because there are no matching enrollments for her in the "Enrollments" table.
#### Outer join (for Time Series data)
An outer join includes all data from an inner join and rows where values do not match in every input. While the inner join joins Query A and Query B on the time field, the outer join includes all rows that don't match on the time field.
@ -831,6 +863,38 @@ I applied a transformation to join the query results using the time field. Now I
{{< figure src="/static/img/docs/transformations/join-fields-after-7-0.png" class="docs-image--no-shadow" max-width= "1100px" alt="A table visualization showing results for multiple servers" >}}
#### Outer join (for SQL-like data)
A tabular outer join combining tables so that the result includes matched and unmatched rows from either or both tables.
| StudentID | Name | Major |
| --------- | -------- | ---------------- |
| 1 | John | Computer Science |
| 2 | Emily | Mathematics |
| 3 | Michael | Physics |
| 4 | Jennifer | Chemistry |
Can now be joined with:
| StudentID | CourseID | Grade |
| --------- | -------- | ----- |
| 1 | CS101 | A |
| 1 | CS102 | B |
| 2 | MATH201 | A |
| 3 | PHYS101 | B |
| 5 | HIST101 | B |
The result after applying the outer join transformation looks like the following:
| StudentID | Name | Major | CourseID | Grade |
| --------- | -------- | ---------------- | -------- | ----- |
| 1 | John | Computer Science | CS101 | A |
| 1 | John | Computer Science | CS102 | B |
| 2 | Emily | Mathematics | MATH201 | A |
| 3 | Michael | Physics | PHYS101 | B |
| 4 | Jennifer | Chemistry | NULL | NULL |
| 5 | NULL | NULL | HIST101 | B |
Combine and analyze data from various queries with table joining for a comprehensive view of your information.
### Join by labels