Skip to content
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

[#2113] feat(pyClient): initial Gravitino Python client module #2676

Merged
merged 17 commits into from
Apr 2, 2024
Merged

[#2113] feat(pyClient): initial Gravitino Python client module #2676

merged 17 commits into from
Apr 2, 2024

Conversation

zhaoyongjie
Copy link
Member

@zhaoyongjie zhaoyongjie commented Mar 25, 2024

What changes were proposed in this pull request?

image

The more detailed introductions for the PR has been uploaded on the bilibili, please jump in there to get a quick view.

#2113

Follow the below command

  1. Install the python-client in your local machine, notice that version of Python should be upper than 3.8.
$ cd clients/client-python
$ pip install -e .
$ pip install ipython (optional)
$ ipython (optional)
  1. Run the Python terminal and happy coding.
In [1]: from gravitino import GravitinoClient
In [2]: client = GravitinoClient("http://localhost:8090")
In [3]: client.get_metalakes()
In [4]: metalake_demo = client.get_metalakes()[1]
In [5]: metalake_demo.catalog_hive.sales.customers.info()

I will follow next steps to refactor/implement the initial Python Client, also heads up @Lanznx was the initial contributor for the Python Client.

  • Remove requests since we are using really simple HTTP client to communicate between Python script and Gravitino, the http.client in Python3 is sufficient.
  • Add Unit test
  • Add codes linter
  • Provide an approach for uploading PyPI

Why are the changes needed?

The motivation of the PR intend to introduce an interactivity and exploratory user-experience between Python terminal and Gravitino Server.

Does this PR introduce any user-facing change?

N/A

How was this patch tested?

Unit tests will cover changes.

@zhaoyongjie zhaoyongjie changed the title feat: initial Python Client [WIP]feat: initial Python Client Mar 25, 2024
@shaofengshi
Copy link
Contributor

Awesome @zhaoyongjie ! It is flexible, I can use the get_child method on each level, and also I can use the the quick way which is to use the child's name to directly accessing it, this is pretty user-friendly.

@zhaoyongjie one small thing, we expect to specify the "metalake_name" when initiating the gravitino client object, then after that, user doesn't need to aware the metalake much, directly list or operate on catalogs; We can refactor this later after this PR be merged. :)

Codes linter can be added later also; For the unit test, is a mock tool needed?

@coolderli @Lanznx Peidian and Brandon, please take a try as well. Thank you!

@zhaoyongjie
Copy link
Member Author

zhaoyongjie commented Mar 27, 2024

one small thing, we expect to specify the "metalake_name" when initiating the gravitino client object, then after that, user doesn't need to aware the metalake much, directly list or operate on catalogs; We can refactor this later after this PR be merged. :)

It makes sense. I'll create another constructor in GravitinoClient might call initialize_matelake, which will have the same arguments as __init__ but also include a matelake_name parameter, after that will expose the new constructor method as a function in the top-level of client, the end-user should use GravitinoClient or GravitinoMatalake to initialize the instance of Gravitino.

Codes linter can be added later also; For the unit test, is a mock tool needed?

Given that the purpose of this utility is to serve as a client for Gravitino, using mock payloads might limit the scope for realistic testing. To be honest, I prefer integrating Python testing into Gravitino's integration tests and only maintaining a few basic unit tests within the utility itself.

@coolderli
Copy link
Contributor

@zhaoyongjie Greate! Could you add some unit tests? The README.md may also need to be updated.

@zhaoyongjie
Copy link
Member Author

Could you add some unit tests? The README.md may also need to be updated.

Sure, will add unit tests and updates the correlative document for the changes.

@zhaoyongjie zhaoyongjie changed the title [WIP]feat: initial Python Client feat: initial Python Client Mar 30, 2024
clients/client-python/gravitino/gravitino_client.py Outdated Show resolved Hide resolved
clients/client-python/gravitino/gravitino_client.py Outdated Show resolved Hide resolved
Comment on lines 97 to 98
protocol: str = "http",
port: int = 8090,
Copy link
Member

Choose a reason for hiding this comment

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

I think maybe we didn't need these parameter protocol and port.
Because we already have parameter host.

Copy link
Member Author

Choose a reason for hiding this comment

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

Depending on how the Client class is initialized, host, protocol, and port offer an alternative way to define the class

e.g.:

initialize_metalake("example-domain", "example-metalake", protocal="https", port=8080)

Copy link
Member

@xunliu xunliu Apr 1, 2024

Choose a reason for hiding this comment

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

hi @zhaoyongjie thank you for your reply.
The host, protocol, and port parameters add to the complexity of the interface.
The host can be either http://localhost:8090 or localhost, which seems to be very flexible, but actually increases the cost of understanding. We just need to provide a robust host parameter.

clients/client-python/gravitino/typing.py Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Gravitino use Gradle to compile, so we didn't need this file.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's for client test and build. Gradle might run it as well if you want.

Copy link
Member

@xunliu xunliu Apr 1, 2024

Choose a reason for hiding this comment

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

I commit a PR #2753 to support Gradle to build and test Python client module, This way we can use the Gradle command in a unified way.

  1. ./gradlew build
  2. ./gradlew clean
  3. ./gradlew test

So, I sure we didn't need use this Makefile file.

clients/client-python/gravitino/gravitino_client.py Outdated Show resolved Hide resolved
clients/client-python/gravitino/service.py Show resolved Hide resolved
@zhaoyongjie
Copy link
Member Author

zhaoyongjie commented Apr 1, 2024 via email

@xunliu
Copy link
Member

xunliu commented Apr 1, 2024

so.....if I hadn't installed Gradle, there might be a block running such commands. And the other hand that Makefile wants to provide a way to create venv, ideally, Makefile might be an entry of the CI.

On Mon, Apr 1, 2024 at 11:35 AM Xun Liu @.> wrote: @.* commented on this pull request. ------------------------------ On clients/client-python/Makefile <#2676 (comment)> : I commit a PR #2753 <#2753> to support Gradle to build and test Python client module, This way we can use the Gradle command in a unified way. 1. ./gradlew build 2. ./gradlew clean 3. ./gradlew test — Reply to this email directly, view it on GitHub <#2676 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPMKUSNSP4TFG2SQZ67W43Y3ES75AVCNFSM6AAAAABFH2LGM2VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTSNZQHE4DINBWG4 . You are receiving this because you were mentioned.Message ID: @.***>
-- Best regards, Yongjie

Developer didn't need install Gradle, Them only need have Java 8, 11, or 17.
When you execute ./gradlew command ant it will automatic download Gradle in template ./gradle directory.

@xunliu xunliu requested a review from shaofengshi April 1, 2024 09:59
@xunliu xunliu changed the title feat: initial Python Client [#2113] feat(pyClient): initial Gravitino Python client module Apr 1, 2024
clients/client-python/gravitino/service.py Outdated Show resolved Hide resolved
clients/client-python/gravitino/service.py Show resolved Hide resolved
clients/client-python/gravitino/__init__.py Outdated Show resolved Hide resolved
class TestGravitinoMetalake(unittest.TestCase):
def test_gravitino_metalake(self, *args):
metalake = gravitino_metalake("http://localhost:9000", "metalake_demo")
self.assertEqual(metalake.name, "metalake_demo")
Copy link
Contributor

Choose a reason for hiding this comment

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

We'd better assert the comment and audit

Copy link
Member Author

Choose a reason for hiding this comment

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

the class TestGravitinoMetalake(unittest.TestCase): inherit from unit test that is in Python standard library and removed pytest, aim to reduce the dependences for the beginning of a project.

BTW, pytest is also providing assertEqual statements.

Copy link
Member

@xunliu xunliu left a comment

Choose a reason for hiding this comment

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

LGTM

@xunliu xunliu merged commit 4411459 into apache:main Apr 2, 2024
19 checks passed
yuqi1129 added a commit to yuqi1129/gravitino that referenced this pull request Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants