Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Add prototype version of pyhdk with Calcite. #18

Closed
wants to merge 1 commit into from

Conversation

ienkovich
Copy link
Contributor

With this commit pyhdk can be installed in conda env:

mkdir build
cd build
cmake -DBUILD_SHARED_LIBS=on ..
make
make install

Calcite usage example with installed pyhdk:

$ python3
Python 3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:25:59)
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyhdk.sql import Calcite
>>> calcite=Calcite()
>>> print(calcite.process("SELECT 1;", "{}"))
{
  "rels": [
    {
      "id": "0",
      "relOp": "LogicalValues",
      "type": [
        {
          "type": "INTEGER",
          "nullable": false,
          "name": "ZERO"
        }
      ],
      "tuples": [
        [
          {
            "literal": 0,
            "type": "DECIMAL",
            "target_type": "INTEGER",
            "scale": 0,
            "precision": 1,
            "type_scale": 0,
            "type_precision": 10
          }
        ]
      ],
      "inputs": []
    },
    {
      "id": "1",
      "relOp": "LogicalProject",
      "fields": [
        "EXPR$0"
      ],
      "exprs": [
        {
          "literal": 1,
          "type": "DECIMAL",
          "target_type": "INTEGER",
          "scale": 0,
          "precision": 1,
          "type_scale": 0,
          "type_precision": 10
        }
      ]
    }
  ]
}
>>>

@ienkovich ienkovich requested a review from alexbaden April 28, 2022 20:40
@alexbaden
Copy link
Contributor

Looks nice!

I almost got it to work without Conda playing with the paths, but ran into this:

>>> from pyhdk.sql import Calcite
>>> calcite=Calcite()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "calcite.pyx", line 30, in pyhdk._sql.Calcite.__cinit__
RuntimeError: cannot find Java class CalciteServerHandler

I see the jar in my bin, but evidently it can't be found by python. Any ideas?

@ienkovich
Copy link
Contributor Author

Looks nice!

I almost got it to work without Conda playing with the paths, but ran into this:

>>> from pyhdk.sql import Calcite
>>> calcite=Calcite()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "calcite.pyx", line 30, in pyhdk._sql.Calcite.__cinit__
RuntimeError: cannot find Java class CalciteServerHandler

I see the jar in my bin, but evidently it can't be found by python. Any ideas?

It depends on where your libs are located. The algo to find the jar file is the following:

  • to check if libOSDependent.so is loaded (should be a case for python usage)
  • get the dir where libOSDependent.so is placed
  • add ../bin to that path and use it as a classpath for Java

We can introduce more sophisticated algo here. E. g. looking in CMAKE_INSTALL_PREFIX might be reasonable.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants