-
Notifications
You must be signed in to change notification settings - Fork 2.8k
ZEPPELIN-497 ] pyspark completion #530
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ab05f86
implement pyspark completion
cloverhearts f4dc487
Pyspark completion __ filtering
cloverhearts 1f82825
remove variable resultComplaetion
cloverhearts d7efe88
change filter regex character
cloverhearts 6832409
Changed PySpark Completion Filter regex
cloverhearts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |
| # limitations under the License. | ||
| # | ||
|
|
||
| import sys, getopt, traceback | ||
| import sys, getopt, traceback, json, re | ||
|
|
||
| from py4j.java_gateway import java_import, JavaGateway, GatewayClient | ||
| from py4j.protocol import Py4JJavaError | ||
|
|
@@ -107,6 +107,50 @@ def isAutoConvertEnabled(self): | |
| def isImportAllPackageUnderSparkSql(self): | ||
| return self.version >= self.SPARK_1_3_0 | ||
|
|
||
| class PySparkCompletion: | ||
| def getGlobalCompletion(self): | ||
| objectDefList = [] | ||
| try: | ||
| for completionItem in list(globals().iterkeys()): | ||
| objectDefList.append(completionItem) | ||
| except: | ||
| return None | ||
| else: | ||
| return objectDefList | ||
|
|
||
| def getMethodCompletion(self, text_value): | ||
| objectDefList = [] | ||
| completion_target = text_value | ||
| try: | ||
| if len(completion_target) <= 0: | ||
| return None | ||
| if text_value[-1] == ".": | ||
| completion_target = text_value[:-1] | ||
| exec("%s = %s(%s)" % ("objectDefList", "dir", completion_target)) | ||
| except: | ||
| return None | ||
| else: | ||
| return objectDefList | ||
|
|
||
|
|
||
| def getCompletion(self, text_value): | ||
| completionList = set() | ||
|
|
||
| globalCompletionList = self.getGlobalCompletion() | ||
| if globalCompletionList != None: | ||
| for completionItem in list(globalCompletionList): | ||
| completionList.add(completionItem) | ||
|
|
||
| if text_value != None: | ||
| objectCompletionList = self.getMethodCompletion(text_value) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if text_value is None should it returned all objects/names in the current scope ( |
||
| if objectCompletionList != None: | ||
| for completionItem in list(objectCompletionList): | ||
| completionList.add(completionItem) | ||
| if len(completionList) <= 0: | ||
| print "" | ||
| else: | ||
| print json.dumps(filter(lambda x : not re.match("^__.*", x), list(completionList))) | ||
|
|
||
|
|
||
| output = Logger() | ||
| sys.stdout = output | ||
|
|
@@ -149,6 +193,7 @@ def isImportAllPackageUnderSparkSql(self): | |
| sqlc = SQLContext(sc, intp.getSQLContext()) | ||
| sqlContext = sqlc | ||
|
|
||
| completion = PySparkCompletion() | ||
| z = PyZeppelinContext(intp.getZeppelinContext()) | ||
|
|
||
| while True : | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
(actually it looks like
dir()should not be given a string, so please ignore my earlier comment here.)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.
also you might want to filter out private methods prefixed
__or_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.
@felixcheung
Thank you for Feed back.
You need to filter the __ private method?
I think filtering is unnecessary for __.
This is because in the private method __ to think you can use a class that you have created.
If you ever need a filter, you can hear more reasons?
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 think it is possible that you want to call a private method named starting with
__- but generally that is discouraged in pythonIn the following cases, autocomplete returns a list including
__add__and other private method, so maybe it shouldn't?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.
also they are not callable like
a.__add__- their names are mangled even thoughdir()returns them: http://www.diveintopython.net/object_oriented_framework/private_functions.html"You can access the __parse method of the MP3FileInfo class by the name _MP3FileInfo__parse. Acknowledge that this is interesting, but promise to never, ever do it in real code. Private methods are private for a reason, but like many other things in Python, their privateness is ultimately a matter of convention, not force."
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 understand.
I think the good feedback.
And by that omission in the auto-complete because it should not call,
I hope to add a filtering operation for __.
Thank you for feedback.