Comments (10)
Yeah, I find myself implementing the following pattern quite often, which could be much easier if ORDER BY was used:
result = fetch(rel, '*');
result = dj.struct.order(result, 'foo');
a = [result.a];
b = [result.b];
c = [result.c];
instead of, for example, a simpler [a, b, c] = fetchsorted(rel, 'foo', 'a', 'b', 'c')
.
Sorting should be limited to happen at fetch time. Anything else would probably break (or at least complicate a lot) the relational model.
from datajoint-matlab.
We could use the fact that all attributes in DataJoint are lower case. Upper case strings will be interpreted as parameter names. So Alex's code above will look like:
[a,b,c] = rel.fetchn(rel, 'a', 'b', 'c', 'SORT BY', {'foo'})
Or we could use a structure to pass parameters into fetch:
opt.sortby = {'foo'}
[a,b,c] = rel.fetchn(rel, 'a', 'b', 'c', opt)
Preferences? I think the second way looks more graceful.
from datajoint-matlab.
okay, this will let us to implement limits more gracefully too:
clear opt
opt.sortby = {'foo'};
opt.start = 1000;
opt.limit = 100;
[a,b,c] = rel.fetchn('a','b','c', opt)
from datajoint-matlab.
I prefer you last suggestion. If sortby could also be a string in case of a single attribute that would be even better :-)
And please let's keep the old way of doing limits for a while before throwing it out.
from datajoint-matlab.
Wouldn't the first suggestion be better? Aas the string we specify is appened at the end were passed we could easily write our own:
[a,b,c] = rel.fetchn(rel, 'a', 'b', 'c', 'SORT BY "a" LIMIT 500')
from datajoint-matlab.
All fetch operators now handle the last argument differently if it begins with "ORDER BY" or "LIMIT ". In both cases, it is simply appended to the SELECT statement.
Examples:
[a,b,c] = rel.fetchn('a','b','c', 'ORDER BY a*b DESC LIMIT 3 OFFSET 5')
[a,b,c] = rel.fetchn('a','b','c', 'LIMIT 3 OFFSET 5')
I will update the documentation after a bit of testing.
from datajoint-matlab.
The old fetch*(..., 1) syntax for limits is broken now...
from datajoint-matlab.
I wasn't familiar with that syntax. That just limits the length by one without ordering? That seems like it's essentially "return a random key" given we aren't meant to make assumptions about ordering.
from datajoint-matlab.
Yes, but often a random key is just fine (e.g. if you know that a bunch of rows all have the same value) and I'm using it at several places and don't feel like refactoring all my code again. That's why I specifically asked to not break that syntax in the comment above :(
from datajoint-matlab.
I just enabled the old syntax for backward compatibility. I only did it for limits, not offsets. So fetch(..., 10, 10)
will not work, but fetch (...., 10)
will work.
I would argue that it makes more sense to go back and replace all instances of fetch(....., 1) with fetch(....., 'LIMIT 1')
for better readability anyway.
Relevant http://xkcd.com/1172/
from datajoint-matlab.
Related Issues (20)
- Markdown not properly rendered in FEX Toolbox description
- fetchn(tableA * tableB, 'field') does not work in 3.4.2
- del deletes some incorrect entries from downstream tables with renamed foreign keys HOT 1
- table classes on path was not recognized when deleting or populating
- error with fetchn DataJoint version 3.4.2 HOT 1
- `{}` is not supported in attribute comments HOT 1
- bool and boolean is not supported in 3.4.1 HOT 1
- Parallelize file transfer for external blobs HOT 1
- bug with del() HOT 6
- Occasional fwrite errors using file-based stores
- fetching 'KEY' error HOT 2
- discovering existing tables across python/matlab HOT 5
- Empty matrices are converted to NULL HOT 2
- syncDef missing [nullable] & comment properties HOT 2
- Officially use the `+` operator for unions
- SSL Connection error HOT 3
- Schema name must start with lower case HOT 2
- Allow strings as well as char HOT 2
- MATLAB hangs and ramps up CPU usage if user closes the password Diagloue Box
- Allow pasting when logging into a database
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 datajoint-matlab.