1

I'm looking to join two data streams together but receive the following error from Influx:

error preparing right side of join: cannot join on an empty table

I'm trying to build a query which compares the total sales by a store this month compared to last month. If the store has no sales this month then I don't want it to show. Below is a basic example of my current query.

import "join"

lastMonth = from(bucket: "my-bucket")
    |> range(start: 2022-10-01, stop: 2022-11-01)
    |> filter(fn: (r) => r._measurement == "transaction")
    |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
    |> group(columns: ["storeId"], mode: "by")
    |> reduce(
        fn: (r, accumulator) => ({
            storeId: r.storeId,
            amount: accumulator.amount + (r.totalAmount - r.refundAmount)
        }),
        identity: {
            storeId: "",
            amount: 0.0
        }
    )

from(bucket: "my-bucket")
    |> range(start: 2022-11-01, stop: 2022-12-01)
    |> filter(fn: (r) => r._measurement == "transaction")
    |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
    |> group(columns: ["storeId"], mode: "by")
    |> reduce(
        fn: (r, accumulator) => ({
            storeId: r.storeId,
            amount: accumulator.amount + (r.totalAmount - r.refundAmount)
        }),
        identity: {
            storeId: "",
            amount: 0.0
        }
    )
    |> join.left(
        right: lastMonth,
        on: (l, r) => l.storeId == r.storeId,
        as: (l, r) => ({
            storeId: l.storeId,
            thisMonthAmount: l.amount,
            lastMonthAmount: r.amount
        })
    )

How can I achieve this in Flux without encountering this issue?

  • Facing the same issue. I feel like influx is such a pain... Did you find a solution ? – jodoox Nov 29 '22 at 14:52
  • @jodoox unfortunately not, I've had to rework all my queries in the meantime to not use any joins. Some in very hacky ways, I don't understand why joining on an empty table would not be supported? – George Davies Nov 30 '22 at 09:53
  • 2
    I've solved it by "unioning" dummy rows to my potentially empty table. Feels hacky for sure but it works... https://community.influxdata.com/t/join-with-empty-data/26636/2 – jodoox Nov 30 '22 at 13:24
  • Agreed this looks like such a basic feature, it's weird – jodoox Nov 30 '22 at 13:24

0 Answers0