Comments (4)
I will add a feature that allows you to change the prefix of field and tag key/values from the defaults of _field_
and _tag_
here shortly. Might take a couple of days.
from tinyflux.
no rush we have actually modified directly on the point module, it's just a suggestion to make the storage object more portable
from tinyflux.
do you have a fork on github? id be interested to see how you implemented it as i work on this feature
from tinyflux.
Okay I've added a feature to 0.3 where you can specify to use a compact key prefix for tags and fields upon insertion. I didn't implement custom prefixes because the prefixes are necessary for deserialization, and I don't expect users to understand the reasoning behind this- specifically the requirement that a prefix for a tag key and field key must be different. I also wanted to keep the prefix somewhat human-readable in the CSV so users aren't terribly confused so I kept the trailing underscore in the prefix. So now when you specify the compact_key_prefixes=True
option, you will get t_myTagKey
for tag keys, and f_myFieldKey
for field keys, instead of _tags_myTagKey
and _fields_myFieldKey
respectively. You can also insert points with compact key prefixes into a database that already has the longer, default prefixes.
Make sure to update tinyflux
:
$ pip install --upgrade tinyflux
To use in your python interpreter:
>>> from tinyflux import Point, TinyFlux
>>> my_db = TinyFlux("test.tinyflux")
>>> p = Point(tags={"myTagKey": "foo"}, fields={"myFieldKey": 0.0})
>>> my_db.insert(p, compact_key_prefixes=True)
1
>>> # Inspect the CSV data for the compact key prefixes.
>>> import csv
>>> with open("test.tinyflux") as f:
... data = list(csv.reader(f))
>>> data # t_ and f_ prefixes
[['2023-03-21T22:50:02.313069', '_default', 't_myTagKey', 'foo', 'f_myFieldKey', '0.0']]
Again, this will also work with a mix of compact and non-compact (default) key prefixes, which may be the case if you now use tinyflux v0.3 on a database that was built with <0.3:
>>> from tinyflux import Point, TinyFlux
>>> my_db = TinyFlux("test.tinyflux")
>>> p1 = Point(tags={"myTagKey": "foo"})
>>> my_db.insert(p1) # compact_key_prefixes is False by default
1
>>> p2 = Point(tags={"myTagKey": "bar"})
>>> my_db.insert(p2, compact_key_prefixes=True)
1
>>> # Inspect the CSV data for compact and default key prefixes.
>>> import csv
>>> with open("test.tinyflux") as f:
... data = list(csv.reader(f))
>>> data[0] # _tag_ prefix
['2023-03-21T22:54:35.202775', '_default', '_tag_myTagKey', 'foo']
>>> data[1] # t_ prefix
['2023-03-21T22:55:03.869054', '_default', 't_myTagKey', 'bar']
>>> my_db.all()[0].tags # default tag key prefix is parsed normally
{'myTagKey': 'foo'}
>>> my_db.all()[1].tags # compact tag key prefix is parsed normally
{'myTagKey': 'bar'}
This option also works with the .insert_multiple()
method. Read the documentation on inserting points for more.
Finally, to update all key prefixes to the compact version, you can cntl-f and replace, but it might hang your text editor if its a regular GUI application. I would use sed
in bash. Make a backup of the file, and hopefully your database has no instances of _tag_
or _field_
besides in the tag and field keys:
$ # Replaces all instances of _tag_ with t_.
$ sed -i '' 's/_tag_/t_/g' /path/to/your/file.csv
$ # Replaces all instances of _field_ with f_.
$ sed -i '' 's/_field_/f_/g' /path/to/your/file.csv
This could take several seconds but your database will be good to go upon update.
There are some other considerations you can make for saving space in your files in the documentation here, including keeping tag and field keys short and concise.
from tinyflux.
Related Issues (15)
- "Line contains NUL" Exception after editing and saving a TinyFlux CSV in Excel HOT 5
- CSVStorage append blank lines on Windows HOT 1
- Field values of 0.0 are serialized to the DB as "_none" HOT 1
- Improve typing using mypy strict mode HOT 1
- Add ability to remove individual tags and fields from Points HOT 5
- Updating a Point with CSVStorage throws a TypeError
- Make package PEP 561 compliant HOT 1
- Empty string tag values are read from storage as "_none" HOT 1
- Tag and Field keys should not be able to be removed in update callables
- Modifying the reference of a Point's tags or fields when using MemoryStorage HOT 2
- Data synchronisation from TinyFlux to InfluxDB or other HOT 1
- Python 3.12 support
- Retrieving Points with the max timestamp from the db HOT 3
- Documentation typos, taking `tinydb` as `tinyflux` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinyflux.