Comments (7)
Hi, thanks a lot for opening a discussion on this.
I thought about it too. Using the long form should be always safe (in case the key is literally {:xyz, :excluded}
the long form would be {{:xyz, :excluded}, :included}
), but I agree itโs not ideal. Also, yes, misspellings should cause explicit errors.
Your idea to use min_key_exclusive:
sounds good. I just wonder if min_key:
should be inclusive by default, or if itโs better to be explicit and only accept either min_key_inclusive
or min_key_exclusive
. I slightly lean for the first option (min_key
or min_key_exclusive
), because I suspect that the inclusive case is the most common and a reasonable default.
Whatโs your opinion?
from cubdb.
After (a lot of) thinking, I feel that your proposal is the clearest and simplest:
# Boundaries are inclusive by default
{:ok, result} = CubDB.select(db, [
min_key: {:foo, 123},
max_key: {:bar, 321}
]))
# Setting min/max key to nil means literal nil
{:ok, result} = CubDB.select(db, [
min_key: nil,
max_key: {:bar, 321}
]))
# To leave the range open, omit min/max key
{:ok, result} = CubDB.select(db, [
max_key: {:bar, 321}
]))
# Make boundaries exclusive by setting min/max_key_inclusive to false
{:ok, result} = CubDB.select(db, [
min_key: {:foo, 123},
max_key: {:bar, 321},
max_key_inclusive: false
]))
I will soon implement this. It will be a breaking change, but it's good to improve this part of the API before version 1.
Thanks a lot for the feedback!
from cubdb.
I agree. Half-open ranges (so inclusive min-key and exclusive max-key) are, as far as I am aware, the most wide-spread and commonly used ranges in computing science and software engineering.
from cubdb.
What I mean, is something like this:
CubDB.select(db, [
min_key: :foo,
max_key_exclusive: :bar
])
from cubdb.
Ah!
I had a slightly different idea in mind, namely:
CubDB.select(db, [
min_key: {:foo, 42},
min_key_exclusive: true,
max_key: {:foo, 1234},
max_key_exclusive: false
])
or possibly:
CubDB.select(db, [
min_key: {:foo, 42},
min_key_settings: [exclusive: true],
max_key: {:foo, 1234},
max_key_settings: [exclusive: false]
])
What do you think?
from cubdb.
Adding to this discussion, right now there is another issue related with the min_key
and max_key
options. The problem is that min_key: nil
currently means no minimum key, while if one wants a minimum key which is literally nil
, the long form must be used: min_key: {nil, :included}
. This is a bit confusing, and one more reason for a refactoring of the select/3
options before v1.0
.
The ideal solution would be both intuitive and free of corner cases.
The best possibilities, in my view, are the following:
- Forcing always the long form,
min_key: {key, :included}
. The advantages would be no corner cases (botnil
and{:abc, :excluded}
would be valid values forkey
), and errors could be thrown if the option format is invalid (e.g. if misspelling:included
or:excluded
, or if using anything else than a 2-elements tuple). The disadvantage is a slightly more cumbersome (but explicit) syntax.
# Option 1:
{:ok, result} = CubDB.select(db, [
min_key: {:foo, :included},
max_key: {:bar, :excluded}
]))
- Only allowing the short form, but making it possible to use
min_key: key
/max_key: key
for the inclusive case, andmin_key_exclusive: key
/max_key_exclusive: key
for the exclusive case. Settingmin_key: nil
would mean a literalnil
value for the minimum key, and for open ranges one would have to omitmin_key
/max_key
. The advantage would be no corner cases (again,key
could be any term, includingnil
and{:something, :included}
), and a somehow simple syntax. The disadvantage would be the need of two different option names for inclusive or exclusive cases, plus the need to handle the error case when bothmin_key
andmin_key_exclusive
are passed.
# Option 2:
{:ok, result} = CubDB.select(db, [
min_key: :foo,
max_key_exclusive: :bar
]))
Adding more options is also a possibility, but I would prefer to keep it simpler.
I am undecided on the options above, happy to take feedback, and I will need to sleep on it in order to come to a decision ๐
from cubdb.
The new version v0.13.0 is published on Hex, introducing the improved API.
from cubdb.
Related Issues (20)
- CubDB crash with :error, :emfile HOT 8
- cubdb crashes during update HOT 8
- CubDB 0.17.0 crash under load {:error, :enoent} HOT 4
- Errant files in db folder crash application permanently HOT 2
- Allow different serialization mechanisms via plug-ins
- Export/Import HOT 3
- Sort order for select? HOT 4
- How to remove all records in a database? HOT 4
- Compacting DB hangs indefinitely when done manually HOT 7
- Feature Request: `CubDB.number_of_writes/1` HOT 4
- A small doc spell mistake HOT 2
- Running out of disk space HOT 2
- Re-opening a file fails when it was closed during compaction HOT 2
- Support wildcard matching HOT 4
- Better error messages HOT 1
- Disk usage increase after moving data HOT 9
- How to select only keys without values? HOT 5
- last entry select doesn't working HOT 1
- Bug: Error on CubDB startup HOT 1
- How to sort uuid or string? HOT 8
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 cubdb.