@Yutaka Awesome. I’m glad it works. The timestamps only have to be 1 nanosecond different for InfluxDB to recognize them as distinct points, so you can us 1ns in date.scale():
|> map(fn: (r) => ({r with _time: date.add(d: date.scale(d: 1ns, n: r.index), to: r._time)}))
@scott
Hello again. I’m so happy to using above method.
so now, If I wish to transform one of field to tag(my case “PJ”), is the following flux will be fine?
my result looks ok. I wish to confirm it, if you have any suggestion.
import "date"
import "sql"
sql.from(
driverName: "mysql",
dataSourceName: "usradmin:passwd@tcp(localhost:3306)/prod",
query: "SELECT PJ AS PJ,task AS task FROM prod.linkdata",
)
|> map(fn: (r) => ({r with _time: now(), _measurement: "test"}))
|> group(columns: ["_measurement"])
|> map(fn: (r) => ({r with index: 1}))
|> cumulativeSum(columns: ["index"])
|> map(fn: (r) => ({r with _time: date.add(d: date.scale(d: 1ns, n: r.index), to: r._time)}))
|> to(bucket: "mariadbtest",tagColumns: ["PJ"],fieldFn: (r) => ({"task": r.task,"index": r.index}))
@Yutaka, looks good to me. My only concern would be on subsequent runs of this query, you’d get duplicate index values because it recalculates the index from 1.