Hello InfluxDB Community,
I hope this message finds you well. I’m new to InfluxDB 2 and the FLUX language, and I have encountered a challenge that I would greatly appreciate your expertise and guidance with.
Context: Tracking Sales and Shipping Data
In my project, I have two buckets:
- Database 1 (db1): Contains quantity data, which represents the total quantity of products available for sale at specific timestamps. Each timestamp has a corresponding quantity value.
- Database 2 (db2): Contains transfers data, which represents the amount of product units transferred from one location to another. Each transfer has a timestamp associated with it.
Objective: I would like to create a final table that combines the data from db1 and db2 to provide a comprehensive view of quantity and transfers. The resulting table should have the following structure:
- Row: Each unique timestamp across both databases.
- Columns:
- “quantity”: Represents the total stock quantity available at each timestamp.
- “first_quantity”: Represents the initial stock quantity at the first available timestamp.
- “transfer_amount”: Represents the number of product units transferred at each timestamp.
- “cumulative_transfer_amount”: Represents the cumulative total of product units transferred up to each timestamp.
- “change_pct”: Represents quantity/(first_quantity + cumulative_transfer_amount) - 1 for each timestamp.
To illustrate with an example, let’s consider the following sample data:
Database 1 (db1):
Timestamp | Quantity |
---|---|
2023-06-01T08:00Z | 100 |
2023-06-01T10:00Z | 80 |
2023-06-01T12:00Z | 120 |
Database 2 (db2):
Timestamp | Transfer Amount |
---|---|
2023-06-01T10:00Z | 5 |
2023-06-01T12:00Z | 8 |
Desired Result:
Timestamp | Quantity | First_Quantity | Transfer Amount | Cumulative Transfer Amount | change_pct |
---|---|---|---|---|---|
2023-06-01T08:00Z | 100 | 100 | 0 | 0 | 0.00 |
2023-06-02T10:00Z | 80 | 100 | 5 | 5 | -0.24 |
2023-06-03T12:00Z | 120 | 100 | 8 | 13 | 0.06 |
My Question:
Given the scenario described above and the desired final table structure, how can I efficiently combine the quantity data from db1 and the transfers data from db2 in InfluxDB 2 using the FLUX language? Specifically, what FLUX queries or techniques should I employ to achieve the desired result?
I would greatly appreciate any insights, guidance, or sample FLUX code snippets that you can provide to help me accomplish this task.