Skip to content

Commit

Permalink
Python bindings (#1556)
Browse files Browse the repository at this point in the history
* Nillable corrections

Signed-off-by: Nik Gil <ngilevskiy@gmail.com>

* remove checkpoints in example

Signed-off-by: Nik Gil <ngilevskiy@gmail.com>
  • Loading branch information
Nik Gil authored and mawhitby committed May 8, 2019
1 parent d8592bd commit c1e3a53
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 16 deletions.
69 changes: 59 additions & 10 deletions python/src/examples/pygw-showcase.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Processing d:\\programming\\java\\geowave\\python\\src\\main\\python\n",
"Building wheels for collected packages: PyGw\n",
" Building wheel for PyGw (setup.py): started\n",
" Building wheel for PyGw (setup.py): finished with status 'done'\n",
" Stored in directory: C:\\Users\\ngile\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-_q9x2vfs\\wheels\\b5\\fe\\87\\545dd16dd789406d9a2f04e05899a2a8163ea0a6a1eb1de314\n",
"Successfully built PyGw\n",
"Installing collected packages: PyGw\n",
" Found existing installation: PyGw 0.1.dev0\n",
" Uninstalling PyGw-0.1.dev0:\n",
" Successfully uninstalled PyGw-0.1.dev0\n",
"Successfully installed PyGw-0.1.dev0\n"
]
}
],
"source": [
"# Install pygw\n",
"!pip install ../main/python/"
Expand All @@ -46,9 +64,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 2,
"metadata": {},
"outputs": [
{
"ename": "PyGwJavaGatewayNotStartedError",
"evalue": "The JavaGateway must be running before you can import pygw.",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32mD:\\Conda\\lib\\site-packages\\py4j\\java_gateway.py\u001b[0m in \u001b[0;36m_get_connection\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 957\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 958\u001b[1;33m \u001b[0mconnection\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdeque\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 959\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mIndexError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mIndexError\u001b[0m: pop from an empty deque",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[1;31mConnectionRefusedError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32mD:\\Conda\\lib\\site-packages\\py4j\\java_gateway.py\u001b[0m in \u001b[0;36mstart\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 1095\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1096\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msocket\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconnect\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0maddress\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mport\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1097\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstream\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msocket\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmakefile\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"rb\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mConnectionRefusedError\u001b[0m: [WinError 10061] No connection could be made because the target machine actively refused it",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[1;31mPy4JNetworkError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32mD:\\Conda\\lib\\site-packages\\pygw\\__init__.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 16\u001b[0m \u001b[1;31m# This should be called only once.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 17\u001b[1;33m \u001b[0mconfig\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 18\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mPy4JNetworkError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mexc\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mD:\\Conda\\lib\\site-packages\\pygw\\config.py\u001b[0m in \u001b[0;36minit\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[1;31m### Reflection utility ###\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 11\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreflection_util\u001b[0m\u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mGATEWAY\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mjvm\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpy4j\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreflection\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mReflectionUtil\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 12\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mD:\\Conda\\lib\\site-packages\\py4j\\java_gateway.py\u001b[0m in \u001b[0;36m__getattr__\u001b[1;34m(self, name)\u001b[0m\n\u001b[0;32m 1677\u001b[0m \u001b[0mproto\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mREFL_GET_UNKNOWN_SUB_COMMAND_NAME\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mname\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m\"\\n\"\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_id\u001b[0m \u001b[1;33m+\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1678\u001b[1;33m \"\\n\" + proto.END_COMMAND_PART)\n\u001b[0m\u001b[0;32m 1679\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0manswer\u001b[0m \u001b[1;33m==\u001b[0m \u001b[0mproto\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mSUCCESS_PACKAGE\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mD:\\Conda\\lib\\site-packages\\py4j\\java_gateway.py\u001b[0m in \u001b[0;36msend_command\u001b[1;34m(self, command, retry, binary)\u001b[0m\n\u001b[0;32m 1011\u001b[0m \"\"\"\n\u001b[1;32m-> 1012\u001b[1;33m \u001b[0mconnection\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_connection\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1013\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mD:\\Conda\\lib\\site-packages\\py4j\\java_gateway.py\u001b[0m in \u001b[0;36m_get_connection\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 959\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mIndexError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 960\u001b[1;33m \u001b[0mconnection\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_create_connection\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 961\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mconnection\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mD:\\Conda\\lib\\site-packages\\py4j\\java_gateway.py\u001b[0m in \u001b[0;36m_create_connection\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 965\u001b[0m self.gateway_parameters, self.gateway_property)\n\u001b[1;32m--> 966\u001b[1;33m \u001b[0mconnection\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstart\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 967\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mconnection\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mD:\\Conda\\lib\\site-packages\\py4j\\java_gateway.py\u001b[0m in \u001b[0;36mstart\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 1107\u001b[0m \u001b[0mlogger\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexception\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmsg\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1108\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mPy4JNetworkError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmsg\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1109\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mPy4JNetworkError\u001b[0m: An error occurred while trying to connect to the Java server (127.0.0.1:25333)",
"\nThe above exception was the direct cause of the following exception:\n",
"\u001b[1;31mPyGwJavaGatewayNotStartedError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-2-86fcf192413c>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mpygw\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;31m# --- Importing Relevant Modules ---\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;31m# Data Stores module\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mpygw\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstores\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mD:\\Conda\\lib\\site-packages\\pygw\\__init__.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 17\u001b[0m \u001b[0mconfig\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 18\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mPy4JNetworkError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mexc\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 19\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mPyGwJavaGatewayNotStartedError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"The JavaGateway must be running before you can import pygw.\"\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mexc\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;31mPyGwJavaGatewayNotStartedError\u001b[0m: The JavaGateway must be running before you can import pygw."
]
}
],
"source": [
"import pygw\n",
"\n",
Expand Down Expand Up @@ -122,9 +171,9 @@
"\n",
"# Creating the Data Type for Public Schools data\n",
"pub_school_dt = SFT(\"public_schools\",\n",
" SFTAttr.string(False, \"building_name\"),\n",
" SFTAttr.string(False, \"address\"),\n",
" SFTAttr.geometry(False, \"coordinates\")) # Let's group X and Y as a coordinate"
" SFTAttr.string(\"building_name\"),\n",
" SFTAttr.string(\"address\"),\n",
" SFTAttr.geometry(\"coordinates\")) # Let's group X and Y as a coordinate"
]
},
{
Expand Down Expand Up @@ -483,7 +532,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.7.3"
}
},
"nbformat": 4,
Expand Down
10 changes: 5 additions & 5 deletions python/src/main/python/pygw/geotools.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,23 @@ def __init__(self, type_, is_nilable, descriptor):
super().__init__(config.GATEWAY, j_attribute)

@classmethod
def string(cls, is_nilable, descriptor):
def string(cls, descriptor, is_nilable=False):
return cls(cls.Type.STRING, is_nilable, descriptor)

@classmethod
def date(cls, is_nilable, descriptor):
def date(cls, descriptor, is_nilable=False):
return cls(cls.Type.DATE, is_nilable, descriptor)

@classmethod
def double(cls, is_nilable, descriptor):
def double(cls, descriptor, is_nilable=False):
return cls(cls.Type.DOUBLE, is_nilable, descriptor)

@classmethod
def integer(cls, is_nilable, descriptor):
def integer(cls, descriptor, is_nilable=False):
return cls(cls.Type.INTEGER, is_nilable, descriptor)

@classmethod
def geometry(cls, is_nilable, descriptor):
def geometry(cls, descriptor, is_nilable=False):
return cls(cls.Type.GEOMETRY, is_nilable, descriptor)

class Type(Enum):
Expand Down
2 changes: 1 addition & 1 deletion python/src/main/python/pygw/stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class HBaseDs(DataStore):
"""
GeoWave HBaseDs datastore.
"""
def __init__(self, zookeeperh="example", hbase_namespace=None):
def __init__(self, zookeeper="example", hbase_namespace=None):
"""
Create an HBase data store
Expand Down

0 comments on commit c1e3a53

Please sign in to comment.