New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'unique' option to history_request messaging protocol #2609
Conversation
@@ -70,35 +73,53 @@ def test_history(): | |||
gothist = ip.history_manager.get_range(-1, 1, 4) | |||
nt.assert_equal(list(gothist), zip([1,1,1],[1,2,3], hist)) | |||
|
|||
newhist = [(2, i + 1, c) for (i, c) in enumerate(newcmds)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you call enumerate with start=1
, we shouldn't need i+1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know that enumerate can take "start" argument!
I can see the use of adding an option to the |
Well, I need it, because Emacs client has interactive history search UI which shows search results as you type ("QuickSilver style"). For such kind of UI speed is critical. That's why it is preferred to drop duplicated entries on kernel side rather than client side. But I understand that you don't want to extend the protocol in such a way that none of official clients benefit. If you decide not to extend the protocol at this point, I will remove the commit for the protocol. |
Let's do a Protocol Extension Proposal. It is unwise to extend the protocol I think protocol will need extension at some point in the futur. Then we Then we'll bump the version number, implement what need to be done. Does this seem like a good plan?
|
Sorry, could you elaborate more? I understand that it is better to have IPEP before extending messaging protocol. But the rest of the part is unclear.
Do you mean we need IPEP for (1) protocol extension system, (2) Also, for history search request, I don't think we need protocol extension system (1), because if a specific client needs a specific history request mechanism, that client can load its own Python module in the kernel and then send the request back to the client via JSON repr. But that means IPython should provide
What version number? IPython? Or are we going to have a protocol version number? |
I think @Carreau is talking about a versioned protocol, and suggesting that we have an IPEP for 'kernel messaging protocol 1.1' (or 2, or whatever it gets called). By rough analogy, [Python] PEP 3154 is for 'pickle protocol version 4'. I can see the sense behind that - a third party client like EIN will clearly need to know whether the kernel supports the fields it wants to use. But I think we should start with a thread on the ipython-dev mailing list about how we should evolve the messaging protocol. |
I see. I will post some idea to the ML later. But please start the discussion if you want. |
Probably it's better to remove the commit for messaging protocol from this PR, so that you can merge this PR? The commit for messaging protocol is completely independent. |
That sounds like a plan - we can review the simple change to the %hist On 22 November 2012 14:15, Takafumi Arakaki notifications@github.comwrote:
|
I removed the commits related to the messaging protocol (b9f1b2e65ae5dbd4e7b4c77e0f95c4ddc0539b51 and a2f98b734a8930b4ffd14f9db63758a9be363833) and applied the suggestion by @takluyver. |
@argument( | ||
'-u', dest='unique', action='store_true', | ||
help=""" | ||
when searching history using `-g`, show only unique history. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More specifically, how does this work with the numbering? Will it show the line number of the first identical entry, the last one, or is it arbitrary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't now sql well, but looking for the answer to this question, DISTINCT
seem a more appropriate way than GROUP BY
.
Am I missing something ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried DISTINCT
first, but it turned out that it compares whole row (i.e., including session
and line
). I am not SQL expert and there is many option for constructing SQL code so I am not 100% sure, but I think it picks up the latest entry. I think this choice makes sense. We can have more precise control by doing SELECT MAX(session) MAX(line) ...
or SELECT MIN(session) MIN(line) ...
but I think it over complicates the history class. You will need to add MAX/MIN in _run_sql
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, it looks like we need MAX or MIN if we want predictable numbers for session
and line
.
If the SELECT statement is an aggregate query with a GROUP BY clause, then each of the expressions specified as part of the GROUP BY clause is evaluated for each row of the dataset.
[...]
Each expression in the result-set is then evaluated once for each group of rows. If the expression is an aggregate expression, it is evaluated across all rows in the group. Otherwise, it is evaluated against a single arbitrarily chosen row from within the group. If there is more than one non-aggregate expression in the result-set, then all such expressions are evaluated for the same row.
Isn't it good to go? |
I will let @takluyver decide about this one. |
I think it's OK. Thanks, @tkf, I'll merge this now. |
Add 'unique' option to history_request messaging protocol
Thanks :) |
Add 'unique' option to history_request messaging protocol
I added boolean 'unique' option to history_request messaging protocol, to show only unique history entries. This option is false by default so that the default behavior is not changed. Currently this option has effect only on 'search' request. Magic command
%history
can take-u
option to specify this option.