Skip to content

[LIVY-527] added autocompletion api and implementation for ipython#119

Open
wangqiaoshi wants to merge 5 commits into
apache:masterfrom
wangqiaoshi:master
Open

[LIVY-527] added autocompletion api and implementation for ipython#119
wangqiaoshi wants to merge 5 commits into
apache:masterfrom
wangqiaoshi:master

Conversation

@wangqiaoshi

@wangqiaoshi wangqiaoshi commented Oct 8, 2018

Copy link
Copy Markdown

What changes were proposed in this pull request?

add complete function in PySparkJobProcessor interface, so ReplDriver can get completion message from python

How was this patch tested?

post /sessions/{sessionId}/completion
set kind=pyspark

@wangqiaoshi

Copy link
Copy Markdown
Author

should set
spark.pyspark.python ${ipython-path}

@codecov-io

codecov-io commented Oct 8, 2018

Copy link
Copy Markdown

Codecov Report

Merging #119 into master will decrease coverage by 2.44%.
The diff coverage is 0%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #119      +/-   ##
============================================
- Coverage     70.94%   68.49%   -2.45%     
+ Complexity      922      893      -29     
============================================
  Files           100      100              
  Lines          5500     5606     +106     
  Branches        828      840      +12     
============================================
- Hits           3902     3840      -62     
- Misses         1062     1214     +152     
- Partials        536      552      +16
Impacted Files Coverage Δ Complexity Δ
...scala/org/apache/livy/repl/PythonInterpreter.scala 47.53% <0%> (-0.6%) 9 <0> (ø)
.../main/java/org/apache/livy/rsc/ReplJobResults.java 0% <0%> (-100%) 0% <0%> (-2%)
...ain/java/org/apache/livy/rsc/driver/Statement.java 0% <0%> (-100%) 0% <0%> (-6%)
...in/java/org/apache/livy/rsc/driver/AddFileJob.java 0% <0%> (-100%) 0% <0%> (-3%)
...ava/org/apache/livy/rsc/driver/StatementState.java 0% <0%> (-93.34%) 0% <0%> (-9%)
...rc/main/java/org/apache/livy/rsc/BaseProtocol.java 52.12% <0%> (-22.35%) 1% <0%> (ø)
.../java/org/apache/livy/rsc/driver/SparkEntries.java 46.87% <0%> (-17.19%) 7% <0%> (-3%)
...main/java/org/apache/livy/rsc/ContextLauncher.java 66.01% <0%> (-15.62%) 13% <0%> (-5%)
...c/src/main/java/org/apache/livy/rsc/RSCClient.java 75.15% <0%> (-8.7%) 20% <0%> (-6%)
...ain/scala/org/apache/livy/utils/SparkYarnApp.scala 73.23% <0%> (-6.34%) 33% <0%> (ø)
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d87a348...1cd30e1. Read the comment docs.

@vanzin

vanzin commented Oct 8, 2018

Copy link
Copy Markdown

Please follow the guidelines in the contribution guide (linked in the PR template). Mainly:

  • file a bug with a description of the problem / feature
  • provide a proper description of your PR (which will be the commit message when merged).

@wangqiaoshi

Copy link
Copy Markdown
Author

Fix the bug : The completion function doesn't work in pyspark kind.

description:
when pyspark run in ipython environment , kind pyspark completion work.
this pr add complete function in PySparkJobProcessor interface, so ReplDriver can get completion message from python

How was this patch tested?

  1. post /sessions/{sessionId}/completion
    set kind=pyspark

@vanzin

vanzin commented Oct 9, 2018

Copy link
Copy Markdown

Please follow the contribution guide. It's linked in the PR template. In case you missed it:
https://livy.incubator.apache.org/community/

You're supposed to replace the PR template with your description of the changes. And file a bug.

@wangqiaoshi wangqiaoshi changed the title added autocompletion api and implementation for ipython [LIVY-527] added autocompletion api and implementation for ipython Oct 12, 2018

@vanzin vanzin left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some style issues, otherwise looks ok.

Can a test be written for this (e.g. in InteractiveIT)? Not sure how easy it is to hit the completion API from tests.

Comment thread repl/src/main/resources/fake_shell.py Outdated
def addFile(self, uri_path):
job_context.sc.addFile(uri_path)


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a lot of blank lines. Surprising the style checker didn't complain. Should be one line between methods.

Comment thread repl/src/main/resources/fake_shell.py Outdated

def complete(self,code,cursor_pos=None):
results = []
ip_completer =global_dict.get('ip_completer')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after =

Comment thread repl/src/main/resources/fake_shell.py Outdated
from IPython.core.completer import IPCompleter
ip = get_ipython()
ip_completer = IPCompleter(ip,global_namespace=global_dict)
global_dict['ip_completer'] = ip_completer

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the completer need to be visible to user statements? Otherwise it seems you can just use a regular global variable (like job_context or local_tmp_dir_path in this file).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completer will be different when python interpreter is different. The number of completer global variable will be two,I don't know if that's appropriate?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean (ip_completer vs. p_completer).

I think it would be better to keep a single variable for the completer, and a boolean that says whether to use the IPython API.

But my main question was: do they need to be stored in global_dict or can they just be a global variable in this module instead?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok,I see what you mean.

Comment thread repl/src/main/resources/fake_shell.py Outdated



def complete(self,code,cursor_pos=None):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after ,

Comment thread repl/src/main/resources/fake_shell.py Outdated
ip_completer =global_dict.get('ip_completer')
p_completer = global_dict.get("p_completer")
if ip_completer is not None:
results = ip_completer.complete(code,cursor_pos=cursor_pos)[1]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after ,

Comment thread repl/src/main/resources/fake_shell.py Outdated
sys.stderr = UnicodeDecodingStringIO()

spark_major_version = os.getenv("LIVY_SPARK_MAJOR_VERSION")
get_completer()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get assumes something is being returned. initialize_completer() is probably a better name.

Comment thread repl/src/main/resources/fake_shell.py Outdated
__IPYTHON__
from IPython.core.completer import IPCompleter
ip = get_ipython()
ip_completer = IPCompleter(ip,global_namespace=global_dict)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after ,

@Tagar

Tagar commented Jan 15, 2019

Copy link
Copy Markdown

ping @wangqiaoshi - that's a great improvement!
do you mind fixing those minor issues after the last review
thank you!

@wangqiaoshi

Copy link
Copy Markdown
Author

ping @wangqiaoshi - that's a great improvement!
do you mind fixing those minor issues after the last review
thank you!

ok

@wangqiaoshi

wangqiaoshi commented Feb 2, 2019

Copy link
Copy Markdown
Author

Some style issues, otherwise looks ok.

Can a test be written for this (e.g. in InteractiveIT)? Not sure how easy it is to hit the completion API from tests.

I have a doubt, InteractiveIT isn't find Kind . Because module livy - integration - the test not introduced livy - core - the parent, but Kind in module livy - core - the parent. I can't run InteractiveIT

@vanzin

vanzin commented Mar 14, 2019

Copy link
Copy Markdown

Sorry, totally missed your question. I'm also not sure I understand the question.

It would be really good to have some test for this. It doesn't need to be an integration tests, but it needs to be tested somehow. Otherwise the changes look good.

@balamuruganvg

Copy link
Copy Markdown

What's the plan to merge this?

@jepma

jepma commented May 20, 2019

Copy link
Copy Markdown

Yes, it would be nice to implement this feature 👍

@Tagar

Tagar commented May 20, 2019

Copy link
Copy Markdown

ping @wangqiaoshi

@cyrilledelabre

Copy link
Copy Markdown

Hi @wangqiaoshi , any plan to merge this ?
is still something missing ?
thanks!

@tsurushun

Copy link
Copy Markdown

Hi @wangqiaoshi, you would be doing a great favor for a lot of people if you could merge this.
Thanks!

@mnoji

mnoji commented Sep 5, 2019

Copy link
Copy Markdown

Hello @wangqiaoshi ,
Please merge your great job!!

@Jassy1994

Copy link
Copy Markdown

Hello @wangqiaoshi
I use jupyter pyspark kernel in livy yarn-cluster mode, and merged this patch in my livy。but jupyter notebook still cannot auto complete. I find jupyter auto completion seems not use livy autocompletion api,May you have some advices about this situation?
Thanks

@rragundez

Copy link
Copy Markdown

Any updates on merging this feature @wangqiaoshi ?

def initialize_completer():
global ip_completer,p_completer
try:
__IPYTHON__

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wangqiaoshi Since fake_shell runs within a standard python process and not within an ipython shell, how will IPCompleter be initialized?

@agsachin

Copy link
Copy Markdown

Any updates on merging this feature @wangqiaoshi @vanzin ?

@aabdullah-getguru

Copy link
Copy Markdown

Anyone?

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has had no activity for at least 3 months. If you are still working on this change or plan to move it forward, please leave a comment or push a new commit so we know to keep it open. Otherwise, this PR will be closed automatically in about one month. Thank you for your contribution to Apache Livy!

@github-actions github-actions Bot added the stale label Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.