influxdata / flux

Flux is a lightweight scripting language for querying databases (like InfluxDB) and working with data. It's part of InfluxDB 1.7 and 2.0, but can be run independently of those.
https://influxdata.com
MIT License
769 stars 153 forks source link

Accumulate all type inference errors when compiling #248

Open mark-rushakoff opened 5 years ago

mark-rushakoff commented 5 years ago

I'm trying to run a script that used to compile and run. Here's the feedback cycle:

1: Original query:

supl = from(bucketID: "000000000000000a")
  |> range(start: -24h)
  |> filter(fn: (r) => r._measurement == "records")
  |> pivot(rowKey:["_time"], colKey: ["_field"], valueCol: "_value")
  |> filter(fn: (r) => r.runID == "2c20766972747573")
  |> group(by: ["scheduledFor"])
  |> sort(desc: true, cols: ["_start"]) |> limit(n: 1)

main = from(bucketID: "000000000000000a")
  |> range(start: -24h)
  |> filter(fn: (r) => r._measurement == "records")
  |> pivot(rowKey:["_time"], colKey: ["_field"], valueCol: "_value")
  |> filter(fn: (r) => r.runID == "2c20766972747573")
  |> pivot(rowKey:["runID"], colKey: ["status"], valueCol: "_time")

join(tables: {main: main, supl: supl}, on: ["_start", "_stop", "orgID", "taskID", "runID", "_measurement"]) |> yield(name: "result")

failed to compile query: type error 4:6-4:69: missing required parameter "columnKey"

2: Okay, the colKey parameter must have been renamed to columnKey:

supl = from(bucketID: "000000000000000a")
  |> range(start: -24h)
  |> filter(fn: (r) => r._measurement == "records")
  |> pivot(rowKey:["_time"], columnKey: ["_field"], valueCol: "_value")
  |> filter(fn: (r) => r.runID == "2c20766972747573")
  |> group(by: ["scheduledFor"])
  |> sort(desc: true, cols: ["_start"]) |> limit(n: 1)

main = from(bucketID: "000000000000000a")
  |> range(start: -24h)
  |> filter(fn: (r) => r._measurement == "records")
  |> pivot(rowKey:["_time"], colKey: ["_field"], valueCol: "_value")
  |> filter(fn: (r) => r.runID == "2c20766972747573")
  |> pivot(rowKey:["runID"], colKey: ["status"], valueCol: "_time")

join(tables: {main: main, supl: supl}, on: ["_start", "_stop", "orgID", "taskID", "runID", "_measurement"]) |> yield(name: "result")

failed to compile query: type error 4:6-4:72: missing required parameter "valueColumn"

3: Okay, valueCol -> valueColumn too:

supl = from(bucketID: "000000000000000a")
  |> range(start: -24h)
  |> filter(fn: (r) => r._measurement == "records")
  |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
  |> filter(fn: (r) => r.runID == "2c20766972747573")
  |> group(by: ["scheduledFor"])
  |> sort(desc: true, cols: ["_start"]) |> limit(n: 1)

main = from(bucketID: "000000000000000a")
  |> range(start: -24h)
  |> filter(fn: (r) => r._measurement == "records")
  |> pivot(rowKey:["_time"], colKey: ["_field"], valueCol: "_value")
  |> filter(fn: (r) => r.runID == "2c20766972747573")
  |> pivot(rowKey:["runID"], colKey: ["status"], valueCol: "_time")

join(tables: {main: main, supl: supl}, on: ["_start", "_stop", "orgID", "taskID", "runID", "_measurement"]) |> yield(name: "result")

failed to compile query: type error 12:6-12:69: missing required parameter "columnKey"

4: Oops, other pivot references need parameter name updates too:

supl = from(bucketID: "000000000000000a")
  |> range(start: -24h)
  |> filter(fn: (r) => r._measurement == "records")
  |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
  |> filter(fn: (r) => r.runID == "2c20766972747573")
  |> group(by: ["scheduledFor"])
  |> sort(desc: true, cols: ["_start"]) |> limit(n: 1)

main = from(bucketID: "000000000000000a")
  |> range(start: -24h)
  |> filter(fn: (r) => r._measurement == "records")
  |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
  |> filter(fn: (r) => r.runID == "2c20766972747573")
  |> pivot(rowKey:["runID"], columnKey: ["status"], valueColumn: "_time")

join(tables: {main: main, supl: supl}, on: ["_start", "_stop", "orgID", "taskID", "runID", "_measurement"]) |> yield(name: "result")

failed to compile query: error calling function "limit": error calling function "sort": unused arguments [cols]

5: Huh? I had to read the query closely to find limit, since there was no positional information this time. Grepped the flux codebase for limit. Parameters look right. Grepped the flux codebase for sort. Looks like it takes columns now. Why was this error different?

supl = from(bucketID: "000000000000000a")
  |> range(start: -24h)
  |> filter(fn: (r) => r._measurement == "records")
  |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
  |> filter(fn: (r) => r.runID == "2c20766972747573")
  |> group(by: ["scheduledFor"])
  |> sort(desc: true, columns: ["_start"]) |> limit(n: 1)

main = from(bucketID: "000000000000000a")
  |> range(start: -24h)
  |> filter(fn: (r) => r._measurement == "records")
  |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
  |> filter(fn: (r) => r.runID == "2c20766972747573")
  |> pivot(rowKey:["runID"], columnKey: ["status"], valueColumn: "_time")

join(tables: {main: main, supl: supl}, on: ["_start", "_stop", "orgID", "taskID", "runID", "_measurement"]) |> yield(name: "result")

Query compiled successfully now.

All of the feedback should have been condensible to a single error message. Returning only the first type inference error unnecessarily drew out 4 extra feedback cycles.

github-actions[bot] commented 3 days ago

This issue has had no recent activity and will be closed soon.