influxdata / influxdata/influxdb-client-python
ask question about field and value separate
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 793
- Forks
- 186
- Avg merge
- 3h 2m
- Merged PRs (30d)
- 1
Description
version: influxdb v2.4
i have a question about ETL when i use ui filter search my data
I expected my result like this
filed,value
voltage:20
current:30
but result is
_filed,_value
_filed,voltage
_filed,_value
_value,20
How do I fix it
part of Code:
column_list=["Location","Service","RackName","PduSide"]
ip_to_mapping = {
'192.168.20.100': ["room1","storage","A01","R"],
'192.168.20.101': ["room2","CRM","A02","L"]
}
drop_colummns=['table','_measurement','_start','_stop','_time','result']
#mapping
def mapping_function(num):
feeback_dict={}
for x in range(len(empty)):
feeback_dict[f'{empty[x]}']=ip_to_mapping[empty[x]][num]
return(feeback_dict)
#instance
client = InfluxDBClient(url=url, token=token, org=org)
write_api = client.write_api(write_options=SYNCHRONOUS)
query_api = client.query_api()
#query
query = ''' from(bucket: "delta_pdu")
|> range(start:-1m)
|> filter(fn: (r) => r["_measurement"] == "snmp") '''
result = query_api.query_data_frame(org=org, query=query)
# for x in result:
# print(x.columns)
#ETL
empty=[]
for table in result:
a=list(set(table['agent_host']))
for x in a:
empty.append(x)
for x in range(len(column_list)):
table[f'{column_list[x]}']=table['agent_host'].map(mapping_function(x))
table.set_index(table['_time'], inplace=True)
# print(table)
clear_data=table.drop(columns=drop_colummns)
clear_data_columns=list(clear_data.columns)
print(clear_data)
print(clear_data_columns)
print('=----')
# print(clear_data_columns)
for x in clear_data_columns:
if x[0]=='_':
clear_data_columns.remove(x)
print(clear_data_columns)
write_api.write(bucket=bucket2, org=org, record=clear_data,
data_frame_measurement_name='SNMP',
data_frame_tag_columns=clear_data_columns,
data_frame_field_columns=["_filed","_value"])
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Python client code using query_api.query_data_frame and write_api.write, and reproduce the transformation against InfluxDB v2.4. Inspect the dataframe columns before the write and compare them with the supplied field and value expectations. Done means the cause of the separate _field and _value output is identified and a clear correction or documented limitation is established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100