mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
### What is this PR for?
After #1534 , Dynamic Forms were no longer working in the python interpreter. This is because the `Py4jZeppelinContext` constructor did not initialize the `_displayhook` which is always called on post-execute.
### What type of PR is it?
Bug Fix
### What is the Jira issue?
[ZEPPELIN-1655](https://issues.apache.org/jira/browse/ZEPPELIN-1655)
### How should this be tested?
Run the following `%python` paragraph, being sure that Py4j is installed:
```python
%python
a, b, c = (1, 2, 3)
z.select("Choose a letter", ([a,"a"], [b,"b"], [c,"c"] ))
```
### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No
Author: Alex Goodman <agoodm@users.noreply.github.com>
Closes #1626 from agoodm/ZEPPELIN-1655 and squashes the following commits:
2e4ee2d [Alex Goodman] Make sure _displayhook is initialized in Py4jZeppelinContext
58 lines
2.3 KiB
Python
58 lines
2.3 KiB
Python
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
# this work for additional information regarding copyright ownership.
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
# (the "License"); you may not use this file except in compliance with
|
|
# the License. You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
from py4j.java_gateway import JavaGateway
|
|
from py4j.java_gateway import java_import, JavaGateway, GatewayClient
|
|
|
|
|
|
client = GatewayClient(port=%PORT%)
|
|
gateway = JavaGateway(client)
|
|
java_import(gateway.jvm, "org.apache.zeppelin.display.Input")
|
|
|
|
|
|
class Py4jZeppelinContext(PyZeppelinContext):
|
|
"""A context impl that uses Py4j to communicate to JVM
|
|
"""
|
|
def __init__(self, z):
|
|
PyZeppelinContext.__init__(self)
|
|
self.z = z
|
|
self.paramOption = gateway.jvm.org.apache.zeppelin.display.Input.ParamOption
|
|
self.javaList = gateway.jvm.java.util.ArrayList
|
|
self.max_result = self.z.getMaxResult()
|
|
|
|
def input(self, name, defaultValue=""):
|
|
return self.z.getGui().input(name, defaultValue)
|
|
|
|
def select(self, name, options, defaultValue=""):
|
|
javaOptions = gateway.new_array(self.paramOption, len(options))
|
|
i = 0
|
|
for tuple in options:
|
|
javaOptions[i] = self.paramOption(tuple[0], tuple[1])
|
|
i += 1
|
|
return self.z.getGui().select(name, defaultValue, javaOptions)
|
|
|
|
def checkbox(self, name, options, defaultChecked=[]):
|
|
javaOptions = gateway.new_array(self.paramOption, len(options))
|
|
i = 0
|
|
for tuple in options:
|
|
javaOptions[i] = self.paramOption(tuple[0], tuple[1])
|
|
i += 1
|
|
javaDefaultCheck = self.javaList()
|
|
for check in defaultChecked:
|
|
javaDefaultCheck.append(check)
|
|
return self.z.getGui().checkbox(name, javaDefaultCheck, javaOptions)
|
|
|
|
|
|
z = Py4jZeppelinContext(gateway.entry_point)
|