Implementing a translation table in InfluxDB

Hello,
I’d like to localize the names of my InfluxDB measures (now I’m using Grafana to display them)
I need some place to put the localization strings then I’m doing the the right replacements in Grafana.

How should I to organize the localization data in InfluxDB?
I have a simple InfluxDB bucket with some _measures like this:

--------------------------------------------
_measurement1
--------------------------------------------
   _time           _field    _value     tag1       
--------------------------------------------
   time1    VariableNameA    value1     ....
   time2    VariableNameA    value2     ....
   time3    VariableNameB    value3     ....
   time4    VariableNameB    value4     ....
--------------------------------------------

My translation table is keyed by the variableName in the _field column and is something like this:

--------------------------------------------------------------
  localizationTable
--------------------------------------------------------------
Variable            Language1               language2
--------------------------------------------------------------
VariableNameA       VariableALanguage1      VariableALanguage2
VariableNameB       VariableBLanguage1      VariableBLanguage2
--------------------------------------------------------------

What is the best way to add this localization data in InfluxDB?

Should I consifer adding some tags with the languages (for a single _field the tag will be always the same for every tag column) like this?

--------------------------------------------------------------------------------
_measurement1
--------------------------------------------------------------------------------
_time   _field           _value         tagLanguage1         tagLanguage2   tag1
--------------------------------------------------------------------------------
time1    VariableNameA    value1  VariableALanguage1   VariableALanguage2   ....
....
--------------------------------------------------------------------------------

Or it is better to use some external data source like a CSV file or a DB with localization data?

Thanks

@Matteo.dt Where the localization data isn’t time series data, I don’t know that InfluxDB is the best storage solution for it. Storing in in CSV or an a relational db may be the better way to go. If you’re using Flux, you can query external CSV and SQL data sources.

The following example shows the CSV inline, but you could certainly pull the CSV from an external source or query a SQL database.

import "csv"

localizationCSV = "Variable,Language1,Language2
VariableA,VariableALang1,VariableALang2
VariableB,VariableBLang1,VariableBLang2
"

localizations = csv.from(csv: localizationCSV, mode: "raw")

localize = (variable, lang) => {
    localization = localizations
        |> filter(fn: (r) => r.Variable == variable)
        |> findColumn(fn: (key) => true, column: lang)

    return localization[0]
}

from(bucket: "example-bucket")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r._measurement == "_measurement1")
    |> map(fn: (r) => ({r with _field: localize(variable: r._field, lang: "Language1")}))

For the sake of demonstration, here’s the same example, but with the sample data you provided above in an ad hoc table (you should be able to run this query in InfluxDB 2.0+):

import "array"
import "csv"

localizationCSV = "Variable,Language1,Language2
VariableA,VariableALang1,VariableALang2
VariableB,VariableBLang1,VariableBLang2
"

localizations = csv.from(csv: localizationCSV, mode: "raw")

localize = (variable, lang) => {
    localization = localizations
        |> filter(fn: (r) => r.Variable == variable)
        |> findColumn(fn: (key) => true, column: lang)

    return localization[0]
}

array.from(
    rows: [
        {_time: 2022-01-01, _field: "VariableA", _value: "value1"},
        {_time: 2022-01-01, _field: "VariableB", _value: "value2"},
    ])
    |> map(fn: (r) => ({r with _field: localize(variable: r._field, lang: "Language1")}))

This returns:

_time _field _value
2022-01-01T00:00:00Z VariableALang1 value1
2022-01-01T00:00:00Z VariableBLang1 value2
1 Like