influxdata / influxdata/influxdb
JavaScript's Point: using influxdb3 Point object, my field values are array instead of the primitive data types such as number, string, or boolean
- Dominant language
- Rust
- Stars
- 31.7k
- Forks
- 3.7k
- Avg merge
- 13h 37m
- Merged PRs (30d)
- 8
Description
I was doing some data collection pipelines for the company's IoT product, where we gather data from the PLC system. I already acquired data from a third-party library and constructed the finalized input as a JavaScript object, where each element is a key-value pair. The primitive data types were **number**, **boolean**, **string** and I was just using the Point methods `setFloatField()`, `setStringField()`, `setBooleanField()` respectively. However, the returned point was not as expected:
```js
{
'global_variables.adsstate_powerfailure': 9,
'global_variables.adsstate_powergood': 10,
'global_variables.route_flag_temporary': 1,
'main.b2.entrymodule.belttrackingstats_Unit': 'EM',
'main.b2.entrymodule.belttrackingstats_Total_Hrs': 1069.4569091796875,
'main.b2.entrymodule.belttrackingstats_TotalCycles': 637826,
}
```
// Double checking with data types before using appropriate Point methods:
```js
global_variables.adsstate_powerfailure | type: string
9 | type: number
global_variables.adsstate_powergood | type: string
10 | type: number
global_variables.route_flag_temporary | type: string
1 | type: number
main.b2.entrymodule.belttrackingstats_Unit | type: string
EM | type: string
main.b2.entrymodule.belttrackingstats_Total_Hrs | type: string
1069.4569091796875 | type: number
main.b2.entrymodule.belttrackingstats_TotalCycles | type: string
637826 | type: number
```
Returned Point before sending into the database using `console.log()`
```js
r {
_values: r {
_tags: {},
_fields: {
'global_variables.adsstate_powerfailure': [Array],
'global_variables.adsstate_powergood': [Array],
'global_variables.route_flag_temporary': [Array],
'main.b2.entrymodule.belttrackingstats_Unit': [Array],
'main.b2.entrymodule.belttrackingstats_Total_Hrs': [Array],
'main.b2.entrymodule.belttrackingstats_TotalCycles': [Array],
```
__Steps to reproduce:__
List the minimal actions needed to reproduce the behaviour.
1. Create an example JavaScript object of key-value pairs that can be parsed with the InfluxDB3 library's data formatting techniques to be sent to the database
2. Break down each pair of key-value to be set as a field in the data point using the corresponding `setXXXField()` method
3. Print display the values before sending to write in the database
__Expected behaviour:__
Describe what you expected to happen.
Return a Point to be stored in InfluxDB with each field has a key from the PLC data and value corresponding to that key
__Actual behaviour:__
Describe What actually happened.
The Point returned contained fields with [Array] values instead of the desired even though proper methods were invoked.
__Environment info:__
* Please provide the command you used to build the project, including any `RUSTFLAGS`.
* System info: Run `uname -srm` or similar and copy the output here (we want to know your OS, architecture etc). Windows10
* If you're running IOx in a containerised environment then details about that would be helpful.
* Other relevant environment details: disk info, hardware setup etc.
__Config:__
Copy any non-default config values here or attach the full config as a gist or file.
__Logs:__
COde snippet
```js
// Write data into InfluxDB with client libraries
async function writePLCDataToInfluxDB(inputData, additionalTags = {}) {
// DEBUG: unique type of data for bug checking
// const typeSet = new Set();
// Handles multiple features of one iteration and digest them into a datapoint to send to the database
const point = Point.measurement(process.env.INFLUX_MEASUREMENT)
.setTimestamp(new Date().toLocaleString());
// Add fields based on data types
for (const [key, value] of Object.entries(inputData)) {
console.log(key, "| type: ", typeof key);
console.log(value, "| type: ", typeof value);
if (typeof value === 'number') {
point.setFloatField(key, value);
} else if (typeof value === 'boolean') {
point.setBooleanField(key, value);
} else if (typeof value === 'string') {
point.setStringField(key, value);
}
}
// // Add any additional tags
// for (const [k, v] of Object.entries(additionalTags)) {
// point.tag(k, v);
// }
// DEBUG TEST:
console.log("-------------------------------------\n\
DEBUGGING: Data is not yet written\n Final Data point:\n", point);
// console.log("All data types: ", typeSet);
// Asynchronous data write
try{
await influxClient.write(point, {precision: 'ms'});
console.log('Data has been written successfully!\n---------------------------------------');
} catch (error){
console.error(`Error writing data to InfluxDB: ${error.body}`)
}
}
```
Include snippet of errors in logs or stack traces here.
Sometimes you can get useful information by running the program with the `RUST_BACKTRACE=full` environment variable.
Finally, the IOx server has a `-vv` for verbose logging.
Contributor guide
Research direction
Start at the JavaScript Point entry point and the setFloatField(), setStringField(), and setBooleanField() methods used in the provided writePLCDataToInfluxDB snippet. Reproduce the example with the InfluxDB3 client, then inspect how fields are represented before write and compare that with the serialized data sent to InfluxDB. Done means primitive field values are handled as expected or the reported behavior is documented as an internal representation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100