From 9e5f0b8b2ddd65938cf360811dcd3bd0f0076047 Mon Sep 17 00:00:00 2001 From: Zhongnan Su Date: Mon, 19 Apr 2021 09:58:54 -0700 Subject: [PATCH] Opensearch migration for sql-cli and doctest module (#4) * rename to opesearch for sql-cli * continue renaming --- doctest/build.gradle | 2 +- doctest/requirements.txt | 3 +- doctest/test_docs.py | 12 +- sql-cli/CODE_OF_CONDUCT.md | 26 +++- sql-cli/CONTRIBUTING.md | 131 +++++++++++++----- sql-cli/CONTRIBUTORS.md | 11 -- sql-cli/MAINTAINERS.md | 13 ++ sql-cli/NOTICE | 13 +- sql-cli/README.md | 45 +++--- sql-cli/development_guide.md | 10 +- .../odfe-sql-cli.release-notes-1.7.0.0.md | 6 +- .../odfe-sql-cli.release-notes-1.8.0.0.md | 4 +- .../odfe-sql-cli.release-notes-1.9.0.0.md | 4 +- sql-cli/setup.py | 14 +- .../__init__.py | 0 .../conf/__init__.py | 0 .../conf/clirc | 14 +- .../config.py | 8 +- .../formatter.py | 6 +- .../main.py | 24 ++-- .../opensearch_buffer.py} | 6 +- .../opensearch_connection.py} | 40 +++--- .../opensearch_literals}/__init__.py | 0 .../opensearch_literals.json} | 0 .../opensearch_style.py} | 0 .../opensearchsql_cli.py} | 40 +++--- .../utils.py | 0 sql-cli/tests/conftest.py | 2 +- sql-cli/tests/test_config.py | 2 +- sql-cli/tests/test_formatter.py | 14 +- sql-cli/tests/test_main.py | 10 +- ...ction.py => test_opensearch_connection.py} | 28 ++-- ...fesql_cli.py => test_opensearchsql_cli.py} | 22 +-- sql-cli/tests/test_plan.md | 25 ++-- sql-cli/tests/utils.py | 34 ++--- 35 files changed, 327 insertions(+), 242 deletions(-) delete mode 100644 sql-cli/CONTRIBUTORS.md create mode 100644 sql-cli/MAINTAINERS.md rename sql-cli/src/{odfe_sql_cli => opensearch_sql_cli}/__init__.py (100%) rename sql-cli/src/{odfe_sql_cli => opensearch_sql_cli}/conf/__init__.py (100%) rename sql-cli/src/{odfe_sql_cli => opensearch_sql_cli}/conf/clirc (87%) rename sql-cli/src/{odfe_sql_cli => opensearch_sql_cli}/config.py (90%) rename sql-cli/src/{odfe_sql_cli => opensearch_sql_cli}/formatter.py (95%) rename sql-cli/src/{odfe_sql_cli => opensearch_sql_cli}/main.py (83%) rename sql-cli/src/{odfe_sql_cli/esbuffer.py => opensearch_sql_cli/opensearch_buffer.py} (89%) rename sql-cli/src/{odfe_sql_cli/esconnection.py => opensearch_sql_cli/opensearch_connection.py} (82%) rename sql-cli/src/{odfe_sql_cli/esliterals => opensearch_sql_cli/opensearch_literals}/__init__.py (100%) rename sql-cli/src/{odfe_sql_cli/esliterals/esliterals.json => opensearch_sql_cli/opensearch_literals/opensearch_literals.json} (100%) rename sql-cli/src/{odfe_sql_cli/esstyle.py => opensearch_sql_cli/opensearch_style.py} (100%) rename sql-cli/src/{odfe_sql_cli/odfesql_cli.py => opensearch_sql_cli/opensearchsql_cli.py} (81%) rename sql-cli/src/{odfe_sql_cli => opensearch_sql_cli}/utils.py (100%) rename sql-cli/tests/{test_esconnection.py => test_opensearch_connection.py} (79%) rename sql-cli/tests/{test_odfesql_cli.py => test_opensearchsql_cli.py} (68%) diff --git a/doctest/build.gradle b/doctest/build.gradle index 56a6dedcdc..d7b7ae9685 100644 --- a/doctest/build.gradle +++ b/doctest/build.gradle @@ -51,6 +51,6 @@ testClusters { } } tasks.register("runRestTestCluster", RunTask) { - description = 'Runs ODFE SQL plugin in OpenSearch' + description = 'Runs OpenSearch SQL plugin' useCluster testClusters.docTestCluster; } \ No newline at end of file diff --git a/doctest/requirements.txt b/doctest/requirements.txt index 6d84269eee..7d178b80ae 100644 --- a/doctest/requirements.txt +++ b/doctest/requirements.txt @@ -1,2 +1 @@ -zc.customdoctests==1.0.1 -# Add odfe-sql-cli once we have it on official PyPI \ No newline at end of file +zc.customdoctests==1.0.1 \ No newline at end of file diff --git a/doctest/test_docs.py b/doctest/test_docs.py index a0f46d3658..2db3e8e922 100644 --- a/doctest/test_docs.py +++ b/doctest/test_docs.py @@ -23,10 +23,10 @@ import click from functools import partial -from odfe_sql_cli.esconnection import ESConnection -from odfe_sql_cli.utils import OutputSettings -from odfe_sql_cli.formatter import Formatter -from elasticsearch import Elasticsearch, helpers +from opensearch_sql_cli.opensearch_connection import OpenSearchConnection +from opensearch_sql_cli.utils import OutputSettings +from opensearch_sql_cli.formatter import Formatter +from elasticsearch import Elasticsearch as OpenSearch, helpers ENDPOINT = "http://localhost:9200" ACCOUNTS = "accounts" @@ -34,7 +34,7 @@ PEOPLE = "people" -class DocTestConnection(ESConnection): +class DocTestConnection(OpenSearchConnection): def __init__(self, query_language="sql"): super(DocTestConnection, self).__init__(endpoint=ENDPOINT, query_language=query_language) @@ -61,7 +61,7 @@ def pretty_print(s): sql_cmd = DocTestConnection(query_language="sql") ppl_cmd = DocTestConnection(query_language="ppl") -test_data_client = Elasticsearch([ENDPOINT], verify_certs=True) +test_data_client = OpenSearch([ENDPOINT], verify_certs=True) def sql_cli_transform(s): diff --git a/sql-cli/CODE_OF_CONDUCT.md b/sql-cli/CODE_OF_CONDUCT.md index 8543edd1cc..2e863762fd 100644 --- a/sql-cli/CODE_OF_CONDUCT.md +++ b/sql-cli/CODE_OF_CONDUCT.md @@ -1,2 +1,24 @@ -## Code of Conduct -This project has adopted an [Open Source Code of Conduct](https://opendistro.github.io/for-elasticsearch/codeofconduct.html). +This code of conduct applies to all spaces provided by the OpenSource project including in code, documentation, issue trackers, mailing lists, chat channels, wikis, blogs, social media and any other communication channels used by the project. + + +**Our open source communities endeavor to:** + +* Be Inclusive: We are committed to being a community where everyone can join and contribute. This means using inclusive and welcoming language. +* Be Welcoming: We are committed to maintaining a safe space for everyone to be able to contribute. +* Be Respectful: We are committed to encouraging differing viewpoints, accepting constructive criticism and work collaboratively towards decisions that help the project grow. Disrespectful and unacceptable behavior will not be tolerated. +* Be Collaborative: We are committed to supporting what is best for our community and users. When we build anything for the benefit of the project, we should document the work we do and communicate to others on how this affects their work. + + +**Our Responsibility. As contributors, members, or bystanders we each individually have the responsibility to behave professionally and respectfully at all times. Disrespectful and unacceptable behaviors include, but are not limited to:** + +* The use of violent threats, abusive, discriminatory, or derogatory language; +* Offensive comments related to gender, gender identity and expression, sexual orientation, disability, mental illness, race, political or religious affiliation; +* Posting of sexually explicit or violent content; +* The use of sexualized language and unwelcome sexual attention or advances; +* Public or private harassment of any kind; +* Publishing private information, such as physical or electronic address, without permission; +* Other conduct which could reasonably be considered inappropriate in a professional setting; +* Advocating for or encouraging any of the above behaviors. +* Enforcement and Reporting Code of Conduct Issues: + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported. [Contact us](mailto:opensource-codeofconduct@amazon.com). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. diff --git a/sql-cli/CONTRIBUTING.md b/sql-cli/CONTRIBUTING.md index 688d58a0a3..a0c928b87c 100644 --- a/sql-cli/CONTRIBUTING.md +++ b/sql-cli/CONTRIBUTING.md @@ -1,61 +1,116 @@ -# Contributing Guidelines +Contributing to OpenSearch +============================= -Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional -documentation, we greatly value feedback and contributions from our community. +OpenSearch is a community project that is built and maintained by people just like **you**. We're glad you're interested in helping out. There are several different ways you can do it, but before we talk about that, let's talk about how to get started. -Please read through this document before submitting any issues or pull requests to ensure we have all the necessary -information to effectively respond to your bug report or contribution. +## Table of Contents: +- [First Things First](#first-things-first) +- [Ways to Contribute](#ways-to-contribute) +- [Developer Certificate of Origin](#developer-certificate-of-origin) +- [Review Process](#review-process) -## Reporting Bugs/Feature Requests +## First Things First -We welcome you to use the GitHub issue tracker to report bugs or suggest features. +1. **When in doubt, open an issue** - For almost any type of contribution, the first step is opening an issue. Even if you think you already know what the solution is, writing down a description of the problem you're trying to solve will help everyone get context when they review your pull request. If it's truly a trivial change (e.g. spelling error), you can skip this step -- but as the subject says, when it doubt, [open an issue](https://github.com/opensearch-project/OpenSearch/issues). -When filing an issue, please check [existing open](https://github.com/opendistro-for-elasticsearch/sql/issues?q=is%3Aopen+is%3Aissue+label%3ACLI), or [recently closed](https://github.com/opendistro-for-elasticsearch/sql/issues?q=is%3Aissue+is%3Aclosed+label%3ACLI), issues to make sure somebody else hasn't already -reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: +2. **Only submit your own work** (or work you have sufficient rights to submit) - Please make sure that any code or documentation you submit is your work or you have the rights to submit. We respect the intellectual property rights of others, and as part of contributing, we'll ask you to sign your contribution with a "Developer Certificate of Origin" (DCO) that states you have the rights to submit this work and you understand we'll +use your contribution. There's more information about this topic in the [DCO section](#developer-certificate-of-origin). -* A reproducible test case or series of steps -* The version of our code being used -* Any modifications you've made relevant to the bug -* Anything unusual about your environment or deployment +## Ways to Contribute +**Please note:** OpenSearch is a fork of [Elasticsearch 7.10.2](https://github.com/elastic/elasticsearch), and is currently in a pre-alpha state, so it's still very much a work in progress. If you do find references to Elasticsearch (outside of attributions and copyrights!) please [open an issue](https://github.com/opensearch-project/OpenSearch/issues) -## Contributing via Pull Requests -Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: +### Bug Reports -1. You are working against the latest source on the *master* branch. -2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. -3. You open an issue to discuss any significant work - we would hate for your time to be wasted. +Ugh! Bugs! -To send us a pull request, please: +A bug is when software behaves in a way that you didn't expect and the developer didn't intend. To help us understand what's going on, we first want to make sure you're working from the latest version. Please make sure you're testing against the [latest version](https://github.com/opensearch-project/OpenSearch). -1. Fork the repository. -2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. -3. Ensure local tests pass. -4. Commit to your fork using clear commit messages. -5. Send us a pull request, answering any default questions in the pull request interface. -6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. +Once you've confirmed that the bug still exists in the latest version, you'll want to check to make sure it's not something we already know about on the [open issues GitHub page](https://github.com/opensearch-project/OpenSearch/issues). -GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and -[creating a pull request](https://help.github.com/articles/creating-a-pull-request/). +If you've upgraded to the latest version and you can't find it in our open issues list, then you'll need to tell us how to reproduce it. To make the behavior as clear as possible, please provided your steps as `curl` commands which we can copy and paste into a terminal to run it locally, for example: +```sh +# delete the index +curl -X DELETE localhost:9200/test -## Finding contributions to work on -Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/opendistro-for-elasticsearch/sql/issues?q=is%3Aopen+label%3A%22help+wanted%22+label%3ACLI) issues is a great place to start. +# insert a document +curl -x PUT localhost:9200/test/test/1 -d '{ + "title": "test document" +}' +# this should return XXXX but instead returns YYYY +curl .... +``` -## Code of Conduct -This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). -For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact -opensource-codeofconduct@amazon.com with any additional questions or comments. +Provide as much information as you can. You may think that the problem lies with your query, when actually it depends on how your data is indexed. The easier it is for us to recreate your problem, the faster it is likely to be fixed. +### Feature Requests -## Security issue notifications -If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. +If you've thought of a way that OpenSearch could be better, we want to hear about it. We track feature requests using GitHub, so please feel free to open an issue which describes the feature you would like to see, why you need it, and how it should work. +### Documentation Changes -## Licensing +//TODO -See the [LICENSE](https://github.com/opendistro-for-elasticsearch/sql/blob/master/sql-cli/LICENSE.TXT) file for our project's licensing. We will ask you to confirm the licensing of your contribution. +### Contributing Code -We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. +As with other types of contributions, the first step is to [**open an issue on GitHub**](https://github.com/opensearch-project/OpenSearch/issues/new/choose). Opening an issue before you make changes makes sure that someone else isn't already working on that particular problem. It also lets us all work together to find the right approach before you spend a bunch of time on a PR. So again, when in doubt, open an issue. + +Once you've opened an issue, check out our [Developer Guide](./DEVELOPER_GUIDE.md) for instructions on how to get started. + +## Developer Certificate of Origin + +OpenSearch is an open source product released under the Apache 2.0 license (see either [the Apache site](https://www.apache.org/licenses/LICENSE-2.0) or the [LICENSE.txt file](./LICENSE.txt)). The Apache 2.0 license allows you to freely use, modify, distribute, and sell your own products that include Apache 2.0 licensed software. + +We respect intellectual property rights of others and we want to make sure all incoming contributions are correctly attributed and licensed. A Developer Certificate of Origin (DCO) is a lightweight mechanism to do that. + +The DCO is a declaration attached to every contribution made by every developer. In the commit message of the contribution, the developer simply adds a `Signed-off-by` statement and thereby agrees to the DCO, which you can find below or at [DeveloperCertificate.org](http://developercertificate.org/). + +``` +Developer's Certificate of Origin 1.1 + +By making a contribution to this project, I certify that: + +(a) The contribution was created in whole or in part by me and I + have the right to submit it under the open source license + indicated in the file; or + +(b) The contribution is based upon previous work that, to the + best of my knowledge, is covered under an appropriate open + source license and I have the right under that license to + submit that work with modifications, whether created in whole + or in part by me, under the same open source license (unless + I am permitted to submit under a different license), as + Indicated in the file; or + +(c) The contribution was provided directly to me by some other + person who certified (a), (b) or (c) and I have not modified + it. + +(d) I understand and agree that this project and the contribution + are public and that a record of the contribution (including + all personal information I submit with it, including my + sign-off) is maintained indefinitely and may be redistributed + consistent with this project or the open source license(s) + involved. + ``` +We require that every contribution to OpenSearch is signed with a Developer Certificate of Origin. Additionally, please use your real name. We do not accept anonymous contributors nor those utilizing pseudonyms. + +Each commit must include a DCO which looks like this + +``` +Signed-off-by: Jane Smith +``` +You may type this line on your own when writing your commit messages. However, if your user.name and user.email are set in your git configs, you can use `-s` or `– – signoff` to add the `Signed-off-by` line to the end of the commit message. + +## Review Process + +We deeply appreciate everyone who takes the time to make a contribution. We will review all contributions as quickly as possible. As a reminder, [opening an issue](https://github.com/opensearch-project/OpenSearch/issues/new/choose) discussing your change before you make it is the best way to smooth the PR process. This will prevent a rejection because someone else is already working on the problem, or because the solution is incompatible with the architectural direction. + +During the PR process, expect that there will be some back-and-forth. Please try to respond to comments in a timely fashion, and if you don't wish to continue with the PR, let us know. If a PR takes too many iterations for its complexity or size, we may reject it. Additionally, if you stop responding we may close the PR as abandoned. In either case, if you feel this was done in error, please add a comment on the PR. + +If we accept the PR, we will merge your change and usually take care of backporting it to appropriate branches ourselves. + +If we reject the PR, we will close the pull request with a comment explaining why. This decision isn't always final: if you feel we have misunderstood your intended change or otherwise think that we should reconsider then please continue the conversation with a comment on the PR and we'll do our best to address any further points you raise. diff --git a/sql-cli/CONTRIBUTORS.md b/sql-cli/CONTRIBUTORS.md deleted file mode 100644 index d19fcc1234..0000000000 --- a/sql-cli/CONTRIBUTORS.md +++ /dev/null @@ -1,11 +0,0 @@ -Contributors in order of last name: - -Abbas Hussain - -Zhongnan Su - -Chloe Zhang - -Anirudh Jadhav - -Alolita Sharma diff --git a/sql-cli/MAINTAINERS.md b/sql-cli/MAINTAINERS.md new file mode 100644 index 0000000000..098ae18733 --- /dev/null +++ b/sql-cli/MAINTAINERS.md @@ -0,0 +1,13 @@ +# OpenSearch Maintainers + +## Maintainers +| Maintainer | GitHub ID | Affiliation | +| --------------- | --------- | ----------- | +| Abbas Hussain | [abbashus](https://github.com/abbashus) | Amazon | +| Alolita Sharma | [alolita](https://github.com/alolita) | Amazon | +| Anirudha Jadhav | [anirudha](https://github.com/anirudha) | Amazon | +| Chloe Zhang | [chloe-zh](https://github.com/chloe-zh) | Amazon | +| Joshua Li | [joshuali925](https://github.com/joshuali925) | Amazon | +| Zhongnan Su | [zhongnansu](https://github.com/CEHENKLE) | Amazon | + + diff --git a/sql-cli/NOTICE b/sql-cli/NOTICE index 713f227952..32ca4f1954 100644 --- a/sql-cli/NOTICE +++ b/sql-cli/NOTICE @@ -1,2 +1,11 @@ -Open Distro for Elasticsearch SQL CLI -Copyright 2019-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. \ No newline at end of file +OpenSearch +Copyright 2021 OpenSearch Contributors + +This product includes software developed by +Elasticsearch (http://www.elastic.co). +Copyright 2009-2018 Elasticsearch + +This product includes software developed by The Apache Software +Foundation (http://www.apache.org/). +This product includes software developed by +Joda.org (http://www.joda.org/). \ No newline at end of file diff --git a/sql-cli/README.md b/sql-cli/README.md index bb72376f23..4c6abf46b2 100644 --- a/sql-cli/README.md +++ b/sql-cli/README.md @@ -1,17 +1,17 @@ -[![SQL CLI Test and Build](https://github.com/opendistro-for-elasticsearch/sql/workflows/SQL%20CLI%20Test%20and%20Build/badge.svg)](https://github.com/opendistro-for-elasticsearch/sql/actions) -[![Latest Version](https://img.shields.io/pypi/v/odfe-sql-cli.svg)](https://pypi.python.org/pypi/odfe-sql-cli/) +[![SQL CLI Test and Build](https://github.com/opensearch-project/sql/workflows/SQL%20CLI%20Test%20and%20Build/badge.svg)](https://github.com/opensearch-project/sql/actions) +[![Latest Version](https://img.shields.io/pypi/v/opensearch-sql-cli.svg)](https://pypi.python.org/pypi/opensearch-sql-cli/) [![Documentation](https://img.shields.io/badge/documentation-blue.svg)](https://opendistro.github.io/for-elasticsearch-docs/docs/sql/cli/) [![Chat](https://img.shields.io/badge/chat-on%20forums-blue)](https://discuss.opendistrocommunity.dev/c/sql/) -![PyPi Downloads](https://img.shields.io/pypi/dm/odfe-sql-cli.svg) +![PyPi Downloads](https://img.shields.io/pypi/dm/opensearch-sql-cli.svg) ![PRs welcome!](https://img.shields.io/badge/PRs-welcome!-success) -# Open Distro for Elasticsearch SQL CLI +# OpenSearch SQL CLI -The SQL CLI component in Open Distro for Elasticsearch (ODFE) is a stand-alone Python application and can be launched by a 'wake' word `odfesql`. +The SQL CLI component in OpenSearch is a stand-alone Python application and can be launched by a 'wake' word `opensearchsql`. -It only supports [Open Distro for Elasticsearch (ODFE) SQL Plugin](https://opendistro.github.io/for-elasticsearch-docs/docs/sql/) -You must have the ODFE SQL plugin installed to your Elasticsearch instance to connect. -Users can run this CLI from MacOS and Linux, and connect to any valid Elasticsearch end-point such as Amazon Elasticsearch Service (AES). +It only supports [OpenSearch SQL Plugin](https://opendistro.github.io/for-elasticsearch-docs/docs/sql/) +You must have the OpenSearch SQL plugin installed to your OpenSearch instance to connect. +Users can run this CLI from MacOS and Linux, and connect to any valid OpenSearch end-point such as Amazon Elasticsearch Service (AES). ![](./screenshots/usage.gif) @@ -27,13 +27,13 @@ Users can run this CLI from MacOS and Linux, and connect to any valid Elasticsea * Field names with color * Enabled horizontal display (by default) and vertical display when output is too wide for your terminal, for better visualization * Pagination for large output -* Connect to Elasticsearch with/without security enabled on either **Elasticsearch OSS or Amazon Elasticsearch Service domains**. +* Connect to OpenSearch with/without security enabled on either **OpenSearch or Amazon Elasticsearch Service domains**. * Supports loading configuration files * Supports all SQL plugin queries ## Install -Launch your local Elasticsearch instance and make sure you have the Open Distro for Elasticsearch SQL plugin installed. +Launch your local OpenSearch instance and make sure you have the OpenSearch SQL plugin installed. To install the SQL CLI: @@ -51,7 +51,7 @@ To install the SQL CLI: 1. Install the CLI: ``` - pip3 install odfe-sql-cli + pip3 install opensearch-sql-cli ``` The SQL CLI only works with Python 3, since Python 2 is no longer maintained since 01/01/2020. See https://pythonclock.org/ @@ -60,33 +60,32 @@ To install the SQL CLI: 1. To launch the CLI, run: ``` - odfesql https://localhost:9200 --username admin --password admin + opensearchsql https://localhost:9200 --username admin --password admin ``` - By default, the `odfesql` command connects to [http://localhost:9200](http://localhost:9200/). + By default, the `opensearchsql` command connects to [http://localhost:9200](http://localhost:9200/). ## Configure -When you first launch the SQL CLI, a configuration file is automatically created at `~/.config/odfesql-cli/config` (for MacOS and Linux), the configuration is auto-loaded thereafter. +When you first launch the SQL CLI, a configuration file is automatically created at `~/.config/opensearchsql-cli/config` (for MacOS and Linux), the configuration is auto-loaded thereafter. You can also configure the following connection properties: -* `endpoint`: You do not need to specify an option, anything that follows the launch command `odfesql` is considered as the endpoint. If you do not provide an endpoint, by default, the SQL CLI connects to [http://localhost:9200](http://localhost:9200/). +* `endpoint`: You do not need to specify an option, anything that follows the launch command `opensearchsql` is considered as the endpoint. If you do not provide an endpoint, by default, the SQL CLI connects to [http://localhost:9200](http://localhost:9200/). * `-u/-w`: Supports username and password for HTTP basic authentication, such as: - * Elasticsearch OSS with [Open Distro for Elasticsearch Security Plugin](https://opendistro.github.io/for-elasticsearch-docs/docs/install/plugins/) installed + * OpenSearch with [OpenSearch Security Plugin](https://opendistro.github.io/for-elasticsearch-docs/docs/install/plugins/) installed * Amazon Elasticsearch Service domain with [Fine Grained Access Control](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/fgac.html) enabled - * Elasticsearch with X-pack security enabled * `--aws-auth`: Turns on AWS sigV4 authentication to connect to an Amazon Elasticsearch Service endpoint. Use with the AWS CLI (`aws configure`) to retrieve the local AWS configuration to authenticate and connect. -For a list of all available configurations, see [clirc](https://github.com/opendistro-for-elasticsearch/sql/blob/master/sql-cli/src/odfe_sql_cli/conf/clirc). +For a list of all available configurations, see [clirc](https://github.com/opensearch-project/sql/blob/master/sql-cli/src/opensearch_sql_cli/conf/clirc). ## Using the CLI -1. Save the sample [accounts test data](https://github.com/opendistro-for-elasticsearch/sql/blob/master/integ-test/src/test/resources/accounts.json) file. +1. Save the sample [accounts test data](https://github.com/opensearch-project/sql/blob/master/integ-test/src/test/resources/accounts.json) file. 2. Index the sample data. ``` @@ -94,7 +93,7 @@ For a list of all available configurations, see [clirc](https://github.com/opend ``` -1. Run a simple SQL command in ODFE SQL CLI: +1. Run a simple SQL command in OpenSearch SQL CLI: ``` SELECT * FROM accounts; @@ -102,7 +101,7 @@ For a list of all available configurations, see [clirc](https://github.com/opend By default, you see a maximum output of 200 rows. To show more results, add a `LIMIT` clause with the desired value. -The CLI supports all types of query that ODFE SQL supports. Refer to [ODFE SQL basic usage documentation.](https://github.com/opendistro-for-elasticsearch/sql#basic-usage) +The CLI supports all types of query that OpenSearch SQL supports. Refer to [OpenSearch SQL basic usage documentation.](https://github.com/opensearch-project/sql#basic-usage) ## Query options @@ -124,7 +123,7 @@ Run single query from command line with options ## Code of Conduct -This project has adopted an [Open Source Code of Conduct](https://opendistro.github.io/for-elasticsearch/codeofconduct.html). +This project has adopted an [Open Source Code of Conduct](/CODE_OF_CONDUCT.md). @@ -134,7 +133,7 @@ If you discover a potential security issue in this project we ask that you notif ## Licensing -See the [LICENSE](https://github.com/opendistro-for-elasticsearch/sql/blob/master/sql-cli/LICENSE.TXT) file for our project's licensing. We will ask you to confirm the licensing of your contribution. +See the [LICENSE](/LICENSE.TXT) file for our project's licensing. We will ask you to confirm the licensing of your contribution. diff --git a/sql-cli/development_guide.md b/sql-cli/development_guide.md index b5dc61210c..8a15acc489 100644 --- a/sql-cli/development_guide.md +++ b/sql-cli/development_guide.md @@ -7,16 +7,16 @@ - `pip install --editable .` will install all dependencies from `setup.py`. ### Run CLI -- Start an Elasticsearch instance from either local, Docker with Open Distro SQL plugin, or AWS Elasticsearch -- To launch the cli, use 'wake' word `odfesql` followed by endpoint of your running ES instance. If not specifying +- Start an OpenSearch instance from either local, Docker with OpenSearch SQL plugin, or AWS Elasticsearch +- To launch the cli, use 'wake' word `opensearchsql` followed by endpoint of your running OpenSearch instance. If not specifying any endpoint, it uses http://localhost:9200 by default. If not provided with port number, http endpoint uses 9200 and https uses 443 by default. ### Testing - Prerequisites - Build the application - - Start a local Elasticsearch instance (OSS) with - [Open Distro SQL plugin for Elasticsearch](https://opendistro.github.io/for-elasticsearch-docs/docs/sql/) installed + - Start a local OpenSearch instance with + [OpenSearch SQL plugin](https://opendistro.github.io/for-elasticsearch-docs/docs/sql/) installed and listening at http://localhost:9200. - Pytest - `pip install -r requirements-dev.txt` Install test frameworks including Pytest and mock. @@ -49,7 +49,7 @@ https uses 443 by default. 2. `python3 -m pip install --user --upgrade twine` 3. `python3 -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*` 6. Install your package from TestPyPI and do manual test - 1. `pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple odfe-sql-cli` + 1. `pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple opensearch-sql-cli` 7. Upload to PyPI 1. Register an account on [PyPI](https://pypi.org/), note that these are two separate servers and the credentials from the test server are not shared with the main server. 2. Use `twine upload dist/*` to upload your package and enter your credentials for the account you registered on PyPI.You don’t need to specify --repository; the package will upload to https://pypi.org/ by default. diff --git a/sql-cli/release-notes/odfe-sql-cli.release-notes-1.7.0.0.md b/sql-cli/release-notes/odfe-sql-cli.release-notes-1.7.0.0.md index 3fd095347b..c6afabf9c4 100644 --- a/sql-cli/release-notes/odfe-sql-cli.release-notes-1.7.0.0.md +++ b/sql-cli/release-notes/odfe-sql-cli.release-notes-1.7.0.0.md @@ -1,9 +1,9 @@ ## 2020-05-04 Version 1.7.0.0 -This is the first official release of Open Distro for Elasticsearch SQL CLI +This is the first official release of OpenSearch SQL CLI -ODFE SQL CLI is a stand alone Python application and can be launched by a wake word `odfesql`. It serves as a support only for -[Open Distro SQL plugin for Elasticsearch](https://opendistro.github.io/for-elasticsearch-docs/docs/sql/). User must have ODFE SQL +OpenSearch SQL CLI is a stand alone Python application and can be launched by a wake word `opensearchsql`. It serves as a support only for +[OpenSearch SQL plugin](https://opendistro.github.io/for-elasticsearch-docs/docs/sql/). User must have OpenSearch SQL plugin installed to the Elasticsearch instance for connection. Usr can run this CLI from MacOS and Linux, and connect to any valid Elasticsearch endpoint such as AWS Elasticsearch. diff --git a/sql-cli/release-notes/odfe-sql-cli.release-notes-1.8.0.0.md b/sql-cli/release-notes/odfe-sql-cli.release-notes-1.8.0.0.md index 92d7184127..c5f6a8c985 100644 --- a/sql-cli/release-notes/odfe-sql-cli.release-notes-1.8.0.0.md +++ b/sql-cli/release-notes/odfe-sql-cli.release-notes-1.8.0.0.md @@ -1,5 +1,5 @@ ## 2020-05-18 Version 1.8.0.0 ### Features -#### Elasticsearch and ODFE SQL Plugin Compatibility -* Feature [#41](https://github.com/opendistro-for-elasticsearch/sql-cli/pull/41): Elasticsearch 7.7.0 and ODFE SQL Plugin 1.8.0 compatibility (issue: [#40](https://github.com/opendistro-for-elasticsearch/sql-cli/issues/40)) +#### Elasticsearch and OpenSearch SQL Plugin Compatibility +* Feature [#41](https://github.com/opendistro-for-elasticsearch/sql-cli/pull/41): Elasticsearch 7.7.0 and OpenSearch SQL Plugin 1.8.0 compatibility (issue: [#40](https://github.com/opendistro-for-elasticsearch/sql-cli/issues/40)) diff --git a/sql-cli/release-notes/odfe-sql-cli.release-notes-1.9.0.0.md b/sql-cli/release-notes/odfe-sql-cli.release-notes-1.9.0.0.md index 26855244d4..b1e50eb7fe 100644 --- a/sql-cli/release-notes/odfe-sql-cli.release-notes-1.9.0.0.md +++ b/sql-cli/release-notes/odfe-sql-cli.release-notes-1.9.0.0.md @@ -1,8 +1,8 @@ ## 2020-06-24 Version 1.9.0.0 (Current) ### Features -#### Elasticsearch and ODFE SQL Plugin Compatibility -* Feature [#55](https://github.com/opendistro-for-elasticsearch/sql-cli/pull/55): Elasticsearch 7.8.0 and ODFE SQL Plugin 1.9.0 compatibility +#### Elasticsearch and OpenSearch SQL Plugin Compatibility +* Feature [#55](https://github.com/opendistro-for-elasticsearch/sql-cli/pull/55): Elasticsearch 7.8.0 and OpenSearch SQL Plugin 1.9.0 compatibility (issue: [#54](https://github.com/opendistro-for-elasticsearch/sql-cli/issues/54)) #### Documentation diff --git a/sql-cli/setup.py b/sql-cli/setup.py index 34a1310eb0..65091dda7d 100644 --- a/sql-cli/setup.py +++ b/sql-cli/setup.py @@ -30,31 +30,31 @@ _version_re = re.compile(r"__version__\s+=\s+(.*)") -with open("src/odfe_sql_cli/__init__.py", "rb") as f: +with open("src/opensearch_sql_cli/__init__.py", "rb") as f: version = str( ast.literal_eval(_version_re.search(f.read().decode("utf-8")).group(1)) ) -description = "Open Distro for Elasticsearch SQL CLI with auto-completion and syntax highlighting" +description = "OpenSearch SQL CLI with auto-completion and syntax highlighting" with open("README.md", "r") as fh: long_description = fh.read() setup( - name="odfe-sql-cli", - author="Open Distro for Elasticsearch", - author_email="odfe-infra@amazon.com", + name="opensearch-sql-cli", + author="OpenSearch", + author_email="opensearch-infra@amazon.com", version=version, license="Apache 2.0", url="https://opendistro.github.io/for-elasticsearch-docs/docs/sql/cli/", packages=find_packages('src'), package_dir={'': 'src'}, - package_data={"odfe_sql_cli": ["conf/clirc", "esliterals/esliterals.json"]}, + package_data={"opensearch_sql_cli": ["conf/clirc", "opensearch_literals/opensearch_literals.json"]}, description=description, long_description=long_description, long_description_content_type="text/markdown", install_requires=install_requirements, - entry_points={"console_scripts": ["odfesql=odfe_sql_cli.main:cli"]}, + entry_points={"console_scripts": ["opensearchsql=opensearch_sql_cli.main:cli"]}, classifiers=[ "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", diff --git a/sql-cli/src/odfe_sql_cli/__init__.py b/sql-cli/src/opensearch_sql_cli/__init__.py similarity index 100% rename from sql-cli/src/odfe_sql_cli/__init__.py rename to sql-cli/src/opensearch_sql_cli/__init__.py diff --git a/sql-cli/src/odfe_sql_cli/conf/__init__.py b/sql-cli/src/opensearch_sql_cli/conf/__init__.py similarity index 100% rename from sql-cli/src/odfe_sql_cli/conf/__init__.py rename to sql-cli/src/opensearch_sql_cli/conf/__init__.py diff --git a/sql-cli/src/odfe_sql_cli/conf/clirc b/sql-cli/src/opensearch_sql_cli/conf/clirc similarity index 87% rename from sql-cli/src/odfe_sql_cli/conf/clirc rename to sql-cli/src/opensearch_sql_cli/conf/clirc index 133dd2e19b..36495f3f92 100644 --- a/sql-cli/src/odfe_sql_cli/conf/clirc +++ b/sql-cli/src/opensearch_sql_cli/conf/clirc @@ -20,22 +20,22 @@ # lines. End of line (return) is considered as the end of the statement. multi_line = True -# If multi_line_mode is set to "odfesql_cli", in multi-line mode, [Enter] will execute +# If multi_line_mode is set to "opensearchsql_cli", in multi-line mode, [Enter] will execute # the current input if the input ends in a semicolon. # If multi_line_mode is set to "safe", in multi-line mode, [Enter] will always # insert a newline, and [Esc] [Enter] or [Alt]-[Enter] must be used to execute # a command. -multi_line_mode = odfesql_cli +multi_line_mode = opensearchsql_cli # log_file location. -# In Unix/Linux: ~/.conf/odfesql-cli/log -# In Windows: %USERPROFILE%\AppData\Local\dbcli\odfesql-cli\log +# In Unix/Linux: ~/.conf/opensearchsql-cli/log +# In Windows: %USERPROFILE%\AppData\Local\dbcli\opensearchsql-cli\log # %USERPROFILE% is typically C:\Users\{username} log_file = default # history_file location. -# In Unix/Linux: ~/.conf/odfesql-cli/history -# In Windows: %USERPROFILE%\AppData\Local\dbcli\odfesql-cli\history +# In Unix/Linux: ~/.conf/opensearchsql-cli/history +# In Windows: %USERPROFILE%\AppData\Local\dbcli\opensearchsql-cli\history # %USERPROFILE% is typically C:\Users\{username} history_file = default @@ -55,7 +55,7 @@ table_format = psql syntax_style = default # Set threshold for row limit prompt. Use 0 to disable prompt. -# maybe not now, since elasticsearch opendisto sql plugin returns 200 rows of data by default if not +# maybe not now, since OpenSearch sql plugin returns 200 rows of data by default if not # using LIMIT. row_limit = 1000 diff --git a/sql-cli/src/odfe_sql_cli/config.py b/sql-cli/src/opensearch_sql_cli/config.py similarity index 90% rename from sql-cli/src/odfe_sql_cli/config.py rename to sql-cli/src/opensearch_sql_cli/config.py index 571c9a65a7..539ba7efd6 100644 --- a/sql-cli/src/odfe_sql_cli/config.py +++ b/sql-cli/src/opensearch_sql_cli/config.py @@ -24,12 +24,12 @@ def config_location(): """Return absolute conf file path according to different OS.""" if "XDG_CONFIG_HOME" in os.environ: - return "%s/odfesql-cli/" % expanduser(os.environ["XDG_CONFIG_HOME"]) + return "%s/opensearchsql-cli/" % expanduser(os.environ["XDG_CONFIG_HOME"]) elif platform.system() == "Windows": # USERPROFILE is typically C:\Users\{username} - return "%s\\AppData\\Local\\dbcli\\odfesql-cli\\" % os.getenv("USERPROFILE") + return "%s\\AppData\\Local\\dbcli\\opensearchsql-cli\\" % os.getenv("USERPROFILE") else: - return expanduser("~/.config/odfesql-cli/") + return expanduser("~/.config/opensearchsql-cli/") def _load_config(user_config, default_config=None): @@ -68,7 +68,7 @@ def _write_default_config(source, destination, overwrite=False): # https://stackoverflow.com/questions/40193112/python-setuptools-distribute-configuration-files-to-os-specific-directories def get_config(clirc_file=None): """ - Get config for odfesql cli. + Get config for opensearchsql cli. This config comes from either existing config in the OS, or create a config file in the OS, and write default config including in the package to it. diff --git a/sql-cli/src/odfe_sql_cli/formatter.py b/sql-cli/src/opensearch_sql_cli/formatter.py similarity index 95% rename from sql-cli/src/odfe_sql_cli/formatter.py rename to sql-cli/src/opensearch_sql_cli/formatter.py index de8248ea13..ee69d333bc 100644 --- a/sql-cli/src/odfe_sql_cli/formatter.py +++ b/sql-cli/src/opensearch_sql_cli/formatter.py @@ -22,7 +22,7 @@ class Formatter: - """Formatter instance is used to format the data retrieved from Elasticsearch.""" + """Formatter instance is used to format the data retrieved from OpenSearch.""" def __init__(self, settings): """A formatter can be customized by passing settings as a parameter.""" @@ -58,7 +58,7 @@ def format_arrays(field_data, headers, **_): def format_output(self, data): """Format data. - :param data: raw data get from ES + :param data: raw data get from OpenSearch :return: formatted output, it's either table or vertical format """ formatter = TabularOutputFormatter(format_name=self.table_format) @@ -80,7 +80,7 @@ def format_output(self, data): output = formatter.format_output(datarows, fields, **self.output_kwargs) output_message = "fetched rows / total rows = %d/%d" % (cur_size, total_hits) - # Open Distro for ES sql has a restriction of retrieving 200 rows of data by default + # OpenSearch sql has a restriction of retrieving 200 rows of data by default if total_hits > 200 == cur_size: output_message += "\n" + "Attention: Use LIMIT keyword when retrieving more than 200 rows of data" diff --git a/sql-cli/src/odfe_sql_cli/main.py b/sql-cli/src/opensearch_sql_cli/main.py similarity index 83% rename from sql-cli/src/odfe_sql_cli/main.py rename to sql-cli/src/opensearch_sql_cli/main.py index b3b0586935..96bb11e326 100644 --- a/sql-cli/src/odfe_sql_cli/main.py +++ b/sql-cli/src/opensearch_sql_cli/main.py @@ -18,9 +18,9 @@ import sys from .config import config_location -from .esconnection import ESConnection +from .opensearch_connection import OpenSearchConnection from .utils import OutputSettings -from .odfesql_cli import OdfeSqlCli +from .opensearchsql_cli import OpenSearchSqlCli from .formatter import Formatter click.disable_unicode_literals_warning = True @@ -29,7 +29,7 @@ @click.command() @click.argument("endpoint", default="http://localhost:9200") @click.option("-q", "--query", "query", type=click.STRING, help="Run single query in non-interactive mode") -@click.option("-e", "--explain", "explain", is_flag=True, help="Explain SQL to ES DSL") +@click.option("-e", "--explain", "explain", is_flag=True, help="Explain SQL to OpenSearch DSL") @click.option( "--clirc", default=config_location() + "config", @@ -53,7 +53,7 @@ default=False, help="Convert output from horizontal to vertical. Only used for non-interactive mode", ) -@click.option("-u", "--username", help="Username to connect to the Elasticsearch") +@click.option("-u", "--username", help="Username to connect to the OpenSearch") @click.option("-w", "--password", help="password corresponding to username") @click.option( "-p", @@ -93,7 +93,7 @@ def cli( query_language, ): """ - Provide endpoint for Elasticsearch client. + Provide endpoint for OpenSearch client. By default, it uses http://localhost:9200 to connect. """ @@ -106,12 +106,12 @@ def cli( # handle single query without more interaction with user if query: - es_executor = ESConnection(endpoint, http_auth, use_aws_authentication) - es_executor.set_connection() + opensearch_executor = OpenSearchConnection(endpoint, http_auth, use_aws_authentication) + opensearch_executor.set_connection() if explain: - output = es_executor.execute_query(query, explain=True, use_console=False) + output = opensearch_executor.execute_query(query, explain=True, use_console=False) else: - output = es_executor.execute_query(query, output_format=result_format, use_console=False) + output = opensearch_executor.execute_query(query, output_format=result_format, use_console=False) if output and result_format == "jdbc": settings = OutputSettings(table_format="psql", is_vertical=is_vertical) formatter = Formatter(settings) @@ -122,14 +122,14 @@ def cli( sys.exit(0) # use console to interact with user - odfesql_cli = OdfeSqlCli( + opensearchsql_cli = OpenSearchSqlCli( clirc_file=clirc, always_use_pager=always_use_pager, use_aws_authentication=use_aws_authentication, query_language=query_language, ) - odfesql_cli.connect(endpoint, http_auth) - odfesql_cli.run_cli() + opensearchsql_cli.connect(endpoint, http_auth) + opensearchsql_cli.run_cli() if __name__ == "__main__": diff --git a/sql-cli/src/odfe_sql_cli/esbuffer.py b/sql-cli/src/opensearch_sql_cli/opensearch_buffer.py similarity index 89% rename from sql-cli/src/odfe_sql_cli/esbuffer.py rename to sql-cli/src/opensearch_sql_cli/opensearch_buffer.py index 651df4ee8f..af4c36bbfd 100644 --- a/sql-cli/src/odfe_sql_cli/esbuffer.py +++ b/sql-cli/src/opensearch_sql_cli/opensearch_buffer.py @@ -19,16 +19,16 @@ from prompt_toolkit.application import get_app -def es_is_multiline(odfesql_cli): +def opensearch_is_multiline(opensearchsql_cli): """Return function that returns boolean to enable/unable multiline mode.""" @Condition def cond(): doc = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER).document - if not odfesql_cli.multi_line: + if not opensearchsql_cli.multi_line: return False - if odfesql_cli.multiline_mode == "safe": + if opensearchsql_cli.multiline_mode == "safe": return True else: return not _multiline_exception(doc.text) diff --git a/sql-cli/src/odfe_sql_cli/esconnection.py b/sql-cli/src/opensearch_sql_cli/opensearch_connection.py similarity index 82% rename from sql-cli/src/odfe_sql_cli/esconnection.py rename to sql-cli/src/opensearch_sql_cli/opensearch_connection.py index 7a5688e7d3..322e7bf5d4 100644 --- a/sql-cli/src/odfe_sql_cli/esconnection.py +++ b/sql-cli/src/opensearch_sql_cli/opensearch_connection.py @@ -19,19 +19,19 @@ import sys import urllib3 -from elasticsearch import Elasticsearch, RequestsHttpConnection +from elasticsearch import Elasticsearch as OpenSearch, RequestsHttpConnection from elasticsearch.exceptions import ConnectionError, RequestError from elasticsearch.connection import create_ssl_context from requests_aws4auth import AWS4Auth -class ESConnection: - """ESConnection instances are used to set up and maintain client to Elasticsearch cluster, +class OpenSearchConnection: + """OpenSearchConnection instances are used to set up and maintain client to Elasticsearch cluster, as well as send user's SQL query to Elasticsearch. """ def __init__(self, endpoint=None, http_auth=None, use_aws_authentication=False, query_language="sql"): - """Initialize an ESConnection instance. + """Initialize an OpenSearchConnection instance. Set up client and get indices list. @@ -40,7 +40,7 @@ def __init__(self, endpoint=None, http_auth=None, use_aws_authentication=False, """ self.client = None self.ssl_context = None - self.es_version = None + self.opensearch_version = None self.plugins = None self.aws_auth = None self.indices_list = [] @@ -65,7 +65,7 @@ def get_aes_client(self): else: click.secho(message="Can not retrieve your AWS credentials, check your AWS config", fg="red") - aes_client = Elasticsearch( + aes_client = OpenSearch( hosts=[self.endpoint], http_auth=self.aws_auth, use_ssl=True, @@ -80,7 +80,7 @@ def get_open_distro_client(self): ssl_context.check_hostname = False ssl_context.verify_mode = ssl.CERT_NONE - open_distro_client = Elasticsearch( + open_distro_client = OpenSearch( [self.endpoint], http_auth=self.http_auth, verify_certs=False, @@ -90,8 +90,8 @@ def get_open_distro_client(self): return open_distro_client - def is_sql_plugin_installed(self, es_client): - self.plugins = es_client.cat.plugins(params={"s": "component", "v": "true"}) + def is_sql_plugin_installed(self, opensearch_client): + self.plugins = opensearch_client.cat.plugins(params={"s": "component", "v": "true"}) sql_plugin_name_list = ["opendistro-sql", "opendistro_sql"] return any(x in self.plugins for x in sql_plugin_name_list) @@ -100,28 +100,28 @@ def set_connection(self, is_reconnect=False): logging.captureWarnings(True) if self.http_auth: - es_client = self.get_open_distro_client() + opensearch_client = self.get_open_distro_client() elif self.use_aws_authentication: - es_client = self.get_aes_client() + opensearch_client = self.get_aes_client() else: - es_client = Elasticsearch([self.endpoint], verify_certs=True) + opensearch_client = OpenSearch([self.endpoint], verify_certs=True) - # check connection. check Open Distro Elasticsearch SQL plugin availability. + # check connection. check OpenSearch SQL plugin availability. try: - if not self.is_sql_plugin_installed(es_client): + if not self.is_sql_plugin_installed(opensearch_client): click.secho( - message="Must have Open Distro SQL plugin installed in your Elasticsearch " - "instance!\nCheck this out: https://github.com/opendistro-for-elasticsearch/sql", + message="Must have OpenSearch SQL plugin installed in your OpenSearch" + "instance!\nCheck this out: https://github.com/opensearch-project/sql", fg="red", ) click.echo(self.plugins) sys.exit() # info() may throw ConnectionError, if connection fails to establish - info = es_client.info() - self.es_version = info["version"]["number"] - self.client = es_client + info = opensearch_client.info() + self.opensearch_version = info["version"]["number"] + self.client = opensearch_client self.get_indices() except ConnectionError as error: @@ -140,7 +140,7 @@ def handle_server_close_connection(self): self.set_connection(is_reconnect=True) click.secho(message="Reconnected! Please run query again", fg="green") except ConnectionError as reconnection_err: - click.secho(message="Connection Failed. Check your ES is running and then come back", fg="red") + click.secho(message="Connection Failed. Check your OpenSearch is running and then come back", fg="red") click.secho(repr(reconnection_err), err=True, fg="red") def execute_query(self, query, output_format="jdbc", explain=False, use_console=True): diff --git a/sql-cli/src/odfe_sql_cli/esliterals/__init__.py b/sql-cli/src/opensearch_sql_cli/opensearch_literals/__init__.py similarity index 100% rename from sql-cli/src/odfe_sql_cli/esliterals/__init__.py rename to sql-cli/src/opensearch_sql_cli/opensearch_literals/__init__.py diff --git a/sql-cli/src/odfe_sql_cli/esliterals/esliterals.json b/sql-cli/src/opensearch_sql_cli/opensearch_literals/opensearch_literals.json similarity index 100% rename from sql-cli/src/odfe_sql_cli/esliterals/esliterals.json rename to sql-cli/src/opensearch_sql_cli/opensearch_literals/opensearch_literals.json diff --git a/sql-cli/src/odfe_sql_cli/esstyle.py b/sql-cli/src/opensearch_sql_cli/opensearch_style.py similarity index 100% rename from sql-cli/src/odfe_sql_cli/esstyle.py rename to sql-cli/src/opensearch_sql_cli/opensearch_style.py diff --git a/sql-cli/src/odfe_sql_cli/odfesql_cli.py b/sql-cli/src/opensearch_sql_cli/opensearchsql_cli.py similarity index 81% rename from sql-cli/src/odfe_sql_cli/odfesql_cli.py rename to sql-cli/src/opensearch_sql_cli/opensearchsql_cli.py index e7d56ea29d..f05c35cec7 100644 --- a/sql-cli/src/odfe_sql_cli/odfesql_cli.py +++ b/sql-cli/src/opensearch_sql_cli/opensearchsql_cli.py @@ -30,9 +30,9 @@ from pygments.lexers.sql import SqlLexer from .config import get_config -from .esconnection import ESConnection -from .esbuffer import es_is_multiline -from .esstyle import style_factory, style_factory_output +from .opensearch_connection import OpenSearchConnection +from .opensearch_buffer import opensearch_is_multiline +from .opensearch_style import style_factory, style_factory_output from .formatter import Formatter from .utils import OutputSettings from . import __version__ @@ -44,8 +44,8 @@ click.disable_unicode_literals_warning = True -class OdfeSqlCli: - """OdfeSqlCli instance is used to build and run the ODFE SQL CLI.""" +class OpenSearchSqlCli: + """OpenSearchSqlCli instance is used to build and run the OpenSearch SQL CLI.""" def __init__(self, clirc_file=None, always_use_pager=False, use_aws_authentication=False, query_language="sql"): # Load conf file @@ -53,7 +53,7 @@ def __init__(self, clirc_file=None, always_use_pager=False, use_aws_authenticati literal = self.literal = self._get_literals() self.prompt_app = None - self.es_executor = None + self.opensearch_executor = None self.query_language = query_language self.always_use_pager = always_use_pager self.use_aws_authentication = use_aws_authentication @@ -70,7 +70,7 @@ def __init__(self, clirc_file=None, always_use_pager=False, use_aws_authenticati def build_cli(self): # TODO: Optimize index suggestion to serve indices options only at the needed position, such as 'from' - indices_list = self.es_executor.indices_list + indices_list = self.opensearch_executor.indices_list sql_completer = WordCompleter(self.keywords_list + self.functions_list + indices_list, ignore_case=True) # https://stackoverflow.com/a/13726418 denote multiple unused arguments of callback in Python @@ -86,7 +86,7 @@ def get_continuation(width, *_): # history=history, style=style_factory(self.syntax_style, self.cli_style), prompt_continuation=get_continuation, - multiline=es_is_multiline(self), + multiline=opensearch_is_multiline(self), auto_suggest=AutoSuggestFromHistory(), input_processors=[ ConditionalProcessor( @@ -115,25 +115,25 @@ def run_cli(self): ) # print Banner - banner = pyfiglet.figlet_format("Open Distro", font="slant") + banner = pyfiglet.figlet_format("OpenSearch", font="slant") print(banner) # print info on the welcome page - print("Server: Open Distro for ES %s" % self.es_executor.es_version) + print("Server: OpenSearch %s" % self.opensearch_executor.opensearch_version) print("CLI Version: %s" % __version__) - print("Endpoint: %s" % self.es_executor.endpoint) + print("Endpoint: %s" % self.opensearch_executor.endpoint) print("Query Language: %s" % self.query_language) while True: try: - text = self.prompt_app.prompt(message="odfesql> ") + text = self.prompt_app.prompt(message="opensearchsql> ") except KeyboardInterrupt: continue # Control-C pressed. Try again. except EOFError: break # Control-D pressed. try: - output = self.es_executor.execute_query(text) + output = self.opensearch_executor.execute_query(text) if output: formatter = Formatter(settings) formatted_output = formatter.format_output(output) @@ -167,20 +167,20 @@ def echo_via_pager(self, text, color=None): click.echo(text, color=color) def connect(self, endpoint, http_auth=None): - self.es_executor = ESConnection(endpoint, http_auth, self.use_aws_authentication, self.query_language) - self.es_executor.set_connection() + self.opensearch_executor = OpenSearchConnection(endpoint, http_auth, self.use_aws_authentication, self.query_language) + self.opensearch_executor.set_connection() def _get_literals(self): - """Parse "esliterals.json" with literal type of SQL "keywords" and "functions", which - are SQL keywords and functions supported by Open Distro SQL Plugin. + """Parse "opensearch_literals.json" with literal type of SQL "keywords" and "functions", which + are SQL keywords and functions supported by OpenSearch SQL Plugin. - :return: a dict that is parsed from esliterals.json + :return: a dict that is parsed from opensearch_literals.json """ - from .esliterals import __file__ as package_root + from .opensearch_literals import __file__ as package_root package_root = os.path.dirname(package_root) - literal_file = os.path.join(package_root, "esliterals.json") + literal_file = os.path.join(package_root, "opensearch_literals.json") with open(literal_file) as f: literals = json.load(f) return literals diff --git a/sql-cli/src/odfe_sql_cli/utils.py b/sql-cli/src/opensearch_sql_cli/utils.py similarity index 100% rename from sql-cli/src/odfe_sql_cli/utils.py rename to sql-cli/src/opensearch_sql_cli/utils.py diff --git a/sql-cli/tests/conftest.py b/sql-cli/tests/conftest.py index 9d60f35ce1..2021f948ce 100644 --- a/sql-cli/tests/conftest.py +++ b/sql-cli/tests/conftest.py @@ -34,7 +34,7 @@ def connection(): @pytest.fixture(scope="function") def default_config_location(): - from src.odfe_sql_cli.conf import __file__ as package_root + from src.opensearch_sql_cli.conf import __file__ as package_root package_root = os.path.dirname(package_root) default_config = os.path.join(package_root, "clirc") diff --git a/sql-cli/tests/test_config.py b/sql-cli/tests/test_config.py index d94ec91eaf..1ba87f5840 100644 --- a/sql-cli/tests/test_config.py +++ b/sql-cli/tests/test_config.py @@ -16,7 +16,7 @@ import stat import pytest -from src.odfe_sql_cli.config import ensure_dir_exists +from src.opensearch_sql_cli.config import ensure_dir_exists class TestConfig: diff --git a/sql-cli/tests/test_formatter.py b/sql-cli/tests/test_formatter.py index 3131eac91b..eae5bef949 100644 --- a/sql-cli/tests/test_formatter.py +++ b/sql-cli/tests/test_formatter.py @@ -18,17 +18,17 @@ import pytest from collections import namedtuple -from src.odfe_sql_cli.odfesql_cli import OdfeSqlCli, COLOR_CODE_REGEX -from src.odfe_sql_cli.formatter import Formatter -from src.odfe_sql_cli.utils import OutputSettings +from src.opensearch_sql_cli.opensearchsql_cli import OpenSearchSqlCli, COLOR_CODE_REGEX +from src.opensearch_sql_cli.formatter import Formatter +from src.opensearch_sql_cli.utils import OutputSettings class TestFormatter: @pytest.fixture def pset_pager_mocks(self): - cli = OdfeSqlCli() - with mock.patch("src.odfe_sql_cli.main.click.echo") as mock_echo, mock.patch( - "src.odfe_sql_cli.main.click.echo_via_pager" + cli = OpenSearchSqlCli() + with mock.patch("src.opensearch_sql_cli.main.click.echo") as mock_echo, mock.patch( + "src.opensearch_sql_cli.main.click.echo_via_pager" ) as mock_echo_via_pager, mock.patch.object(cli, "prompt_app") as mock_app: yield cli, mock_echo, mock_echo_via_pager, mock_app @@ -143,7 +143,7 @@ def test_format_output_vertical(self): "age | 24", ] - with mock.patch("src.odfe_sql_cli.main.click.secho") as mock_secho, mock.patch("src.odfe_sql_cli.main.click.confirm") as mock_confirm: + with mock.patch("src.opensearch_sql_cli.main.click.secho") as mock_secho, mock.patch("src.opensearch_sql_cli.main.click.confirm") as mock_confirm: expanded_results = formatter.format_output(data) mock_secho.assert_called_with(message="Output longer than terminal width", fg="red") diff --git a/sql-cli/tests/test_main.py b/sql-cli/tests/test_main.py index 6535b1d9ef..b3d64ca24b 100644 --- a/sql-cli/tests/test_main.py +++ b/sql-cli/tests/test_main.py @@ -18,8 +18,8 @@ from click.testing import CliRunner from .utils import estest, load_data, TEST_INDEX_NAME -from src.odfe_sql_cli.main import cli -from src.odfe_sql_cli.odfesql_cli import OdfeSqlCli +from src.opensearch_sql_cli.main import cli +from src.opensearch_sql_cli.opensearchsql_cli import OpenSearchSqlCli INVALID_ENDPOINT = "http://invalid:9200" ENDPOINT = "http://localhost:9200" @@ -44,7 +44,7 @@ def test_explain(self, connection): +-----+""" ) - with mock.patch("src.odfe_sql_cli.main.click.echo") as mock_echo, mock.patch("src.odfe_sql_cli.main.click.secho") as mock_secho: + with mock.patch("src.opensearch_sql_cli.main.click.echo") as mock_echo, mock.patch("src.opensearch_sql_cli.main.click.secho") as mock_secho: runner = CliRunner() # test -q -e @@ -63,8 +63,8 @@ def test_explain(self, connection): @estest def test_cli(self): - with mock.patch.object(OdfeSqlCli, "connect") as mock_connect, mock.patch.object( - OdfeSqlCli, "run_cli" + with mock.patch.object(OpenSearchSqlCli, "connect") as mock_connect, mock.patch.object( + OpenSearchSqlCli, "run_cli" ) as mock_run_cli: runner = CliRunner() result = runner.invoke(cli) diff --git a/sql-cli/tests/test_esconnection.py b/sql-cli/tests/test_opensearch_connection.py similarity index 79% rename from sql-cli/tests/test_esconnection.py rename to sql-cli/tests/test_opensearch_connection.py index 45d40b9870..82ea911706 100644 --- a/sql-cli/tests/test_esconnection.py +++ b/sql-cli/tests/test_opensearch_connection.py @@ -20,7 +20,7 @@ from elasticsearch import Elasticsearch, RequestsHttpConnection from .utils import estest, load_data, run, TEST_INDEX_NAME -from src.odfe_sql_cli.esconnection import ESConnection +from src.opensearch_sql_cli.opensearch_connection import OpenSearchConnection INVALID_ENDPOINT = "http://invalid:9200" OPEN_DISTRO_ENDPOINT = "https://opedistro:9200" @@ -59,23 +59,23 @@ def test_query_nonexistent_index(self, connection): "type": "IndexNotFoundException", } - with mock.patch("src.odfe_sql_cli.esconnection.click.secho") as mock_secho: + with mock.patch("src.opensearch_sql_cli.opensearch_connection.click.secho") as mock_secho: run(connection, "select * from non-existed") mock_secho.assert_called_with(message=str(expected), fg="red") def test_connection_fail(self): - test_executor = ESConnection(endpoint=INVALID_ENDPOINT) + test_executor = OpenSearchConnection(endpoint=INVALID_ENDPOINT) err_message = "Can not connect to endpoint %s" % INVALID_ENDPOINT - with mock.patch("sys.exit") as mock_sys_exit, mock.patch("src.odfe_sql_cli.esconnection.click.secho") as mock_secho: + with mock.patch("sys.exit") as mock_sys_exit, mock.patch("src.opensearch_sql_cli.opensearch_connection.click.secho") as mock_secho: test_executor.set_connection() mock_sys_exit.assert_called() mock_secho.assert_called_with(message=err_message, fg="red") def test_lost_connection(self): - test_esexecutor = ESConnection(endpoint=INVALID_ENDPOINT) + test_esexecutor = OpenSearchConnection(endpoint=INVALID_ENDPOINT) def side_effect_set_connection(is_reconnected): if is_reconnected: @@ -83,7 +83,7 @@ def side_effect_set_connection(is_reconnected): else: return ConnectionError() - with mock.patch("src.odfe_sql_cli.esconnection.click.secho") as mock_secho, mock.patch.object( + with mock.patch("src.opensearch_sql_cli.opensearch_connection.click.secho") as mock_secho, mock.patch.object( test_esexecutor, "set_connection" ) as mock_set_connection: # Assume reconnection success @@ -98,33 +98,33 @@ def side_effect_set_connection(is_reconnected): mock_secho.assert_any_call(message="Reconnecting...", fg="green") mock_secho.assert_any_call( - message="Connection Failed. Check your ES is running and then come back", fg="red" + message="Connection Failed. Check your OpenSearch is running and then come back", fg="red" ) def test_reconnection_exception(self): - test_executor = ESConnection(endpoint=INVALID_ENDPOINT) + test_executor = OpenSearchConnection(endpoint=INVALID_ENDPOINT) with pytest.raises(ConnectionError) as error: assert test_executor.set_connection(True) def test_select_client(self): - od_test_executor = ESConnection(endpoint=OPEN_DISTRO_ENDPOINT, http_auth=AUTH) - aes_test_executor = ESConnection(endpoint=AES_ENDPOINT, use_aws_authentication=True) + od_test_executor = OpenSearchConnection(endpoint=OPEN_DISTRO_ENDPOINT, http_auth=AUTH) + aes_test_executor = OpenSearchConnection(endpoint=AES_ENDPOINT, use_aws_authentication=True) with mock.patch.object(od_test_executor, "get_open_distro_client") as mock_od_client, mock.patch.object( - ESConnection, "is_sql_plugin_installed", return_value=True + OpenSearchConnection, "is_sql_plugin_installed", return_value=True ): od_test_executor.set_connection() mock_od_client.assert_called() with mock.patch.object(aes_test_executor, "get_aes_client") as mock_aes_client, mock.patch.object( - ESConnection, "is_sql_plugin_installed", return_value=True + OpenSearchConnection, "is_sql_plugin_installed", return_value=True ): aes_test_executor.set_connection() mock_aes_client.assert_called() def test_get_od_client(self): - od_test_executor = ESConnection(endpoint=OPEN_DISTRO_ENDPOINT, http_auth=AUTH) + od_test_executor = OpenSearchConnection(endpoint=OPEN_DISTRO_ENDPOINT, http_auth=AUTH) with mock.patch.object(Elasticsearch, "__init__", return_value=None) as mock_es: od_test_executor.get_open_distro_client() @@ -135,7 +135,7 @@ def test_get_od_client(self): ) def test_get_aes_client(self): - aes_test_executor = ESConnection(endpoint=AES_ENDPOINT, use_aws_authentication=True) + aes_test_executor = OpenSearchConnection(endpoint=AES_ENDPOINT, use_aws_authentication=True) with mock.patch.object(Elasticsearch, "__init__", return_value=None) as mock_es: aes_test_executor.get_aes_client() diff --git a/sql-cli/tests/test_odfesql_cli.py b/sql-cli/tests/test_opensearchsql_cli.py similarity index 68% rename from sql-cli/tests/test_odfesql_cli.py rename to sql-cli/tests/test_opensearchsql_cli.py index b9b71bac6d..9e8861cf1c 100644 --- a/sql-cli/tests/test_odfesql_cli.py +++ b/sql-cli/tests/test_opensearchsql_cli.py @@ -17,11 +17,11 @@ from prompt_toolkit.shortcuts import PromptSession from prompt_toolkit.input.defaults import create_pipe_input -from src.odfe_sql_cli.esbuffer import es_is_multiline +from src.opensearch_sql_cli.opensearch_buffer import opensearch_is_multiline from .utils import estest, load_data, TEST_INDEX_NAME, ENDPOINT -from src.odfe_sql_cli.odfesql_cli import OdfeSqlCli -from src.odfe_sql_cli.esconnection import ESConnection -from src.odfe_sql_cli.esstyle import style_factory +from src.opensearch_sql_cli.opensearchsql_cli import OpenSearchSqlCli +from src.opensearch_sql_cli.opensearch_connection import OpenSearchConnection +from src.opensearch_sql_cli.opensearch_style import style_factory AUTH = None QUERY_WITH_CTRL_D = "select * from %s;\r\x04\r" % TEST_INDEX_NAME @@ -31,17 +31,17 @@ @pytest.fixture() def cli(default_config_location): - return OdfeSqlCli(clirc_file=default_config_location, always_use_pager=False) + return OpenSearchSqlCli(clirc_file=default_config_location, always_use_pager=False) -class TestOdfeSqlCli: +class TestOpenSearchSqlCli: def test_connect(self, cli): - with mock.patch.object(ESConnection, "__init__", return_value=None) as mock_ESConnection, mock.patch.object( - ESConnection, "set_connection" + with mock.patch.object(OpenSearchConnection, "__init__", return_value=None) as mock_OpenSearchConnection, mock.patch.object( + OpenSearchConnection, "set_connection" ) as mock_set_connectiuon: cli.connect(endpoint=ENDPOINT) - mock_ESConnection.assert_called_with(ENDPOINT, AUTH, USE_AWS_CREDENTIALS, QUERY_LANGUAGE) + mock_OpenSearchConnection.assert_called_with(ENDPOINT, AUTH, USE_AWS_CREDENTIALS, QUERY_LANGUAGE) mock_set_connectiuon.assert_called() @estest @@ -55,14 +55,14 @@ def test_run_cli(self, connection, cli, capsys): "fetched rows / total rows = 1/1" "\n+-----+\n| \x1b[38;5;47;01ma\x1b[39;00m |\n|-----|\n| aws |\n+-----+" ) - with mock.patch.object(OdfeSqlCli, "echo_via_pager") as mock_pager, mock.patch.object( + with mock.patch.object(OpenSearchSqlCli, "echo_via_pager") as mock_pager, mock.patch.object( cli, "build_cli" ) as mock_prompt: inp = create_pipe_input() inp.send_text(QUERY_WITH_CTRL_D) mock_prompt.return_value = PromptSession( - input=inp, multiline=es_is_multiline(cli), style=style_factory(cli.syntax_style, cli.cli_style) + input=inp, multiline=opensearch_is_multiline(cli), style=style_factory(cli.syntax_style, cli.cli_style) ) cli.connect(ENDPOINT) diff --git a/sql-cli/tests/test_plan.md b/sql-cli/tests/test_plan.md index 1804a3a4c9..d40c60d28c 100644 --- a/sql-cli/tests/test_plan.md +++ b/sql-cli/tests/test_plan.md @@ -1,5 +1,5 @@ # Test Plan - The purpose of this checklist is to guide you through the basic usage of ODFE SQL CLI, as well as a manual test process. + The purpose of this checklist is to guide you through the basic usage of OpenSearch SQL CLI, as well as a manual test process. ## Display @@ -12,7 +12,7 @@ * [ ] Test table formatted output. * [ ] Test successful conversion from horizontal to vertical display with confirmation. * resize the terminal window before launching sql cli, there will be a warning message if your terminal is too narrow for horizontal output. It will ask if you want to convert to vertical display -* [ ] Test warning message when output > 200 rows of data. (Limited by ODFE SQL syntax) +* [ ] Test warning message when output > 200 rows of data. (Limited by OpenSearch SQL syntax) * `SELECT * FROM accounts` * Run above command, you’ll see the max output is 200, and there will be a message at the top of your results telling you how much data was fetched. * If you want to query more than 200 rows of data, try add a `LIMIT` with more than 200. @@ -20,17 +20,16 @@ ## Connection -* [ ] Test connection to a local Elasticsearch instance - * [ ] Standard Elastic version, with/without authentication by Elastic X-pack security (https://www.elastic.co/guide/en/elasticsearch/reference/7.6/security-getting-started.html) - * [ ] OSS version, no authentication - * [ ] OSS version, install [ODFE Security plugin](https://opendistro.github.io/for-elasticsearch-docs/docs/install/plugins/) to enable authentication and SSL - * Run command like `odfesql -u -w ` to connect to instance with authentication. +* [ ] Test connection to a local OpenSearch instance + * [ ] OpenSearch, no authentication + * [ ] OpenSearch, install [OpenSearch Security plugin](https://opendistro.github.io/for-elasticsearch-docs/docs/install/plugins/) to enable authentication and SSL + * Run command like `opensearchsql -u -w ` to connect to instance with authentication. * [ ] Test connection to [Amazon Elasticsearch domain](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-gsg.html) with [Fine Grained Access Control](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/fgac.html) enabled. * Have your aws credentials correctly configured by `aws configure` - * `odfesql --aws-auth -u -w ` + * `opensearchsql --aws-auth -u -w ` * [ ] Test connection fail when connecting to invalid endpoint. - * `odfesql invalidendpoint.com` + * `opensearchsql invalidendpoint.com` ## Execution @@ -39,7 +38,7 @@ * `SELECT * FROM bank WHERE age >30 AND gender = 'm'` * [ ] Test unsuccessful execution with an invalid SQL query will give an error message * [ ] Test load config file - * `vim .config/odfesql-cli/config` + * `vim .config/opensearchsql-cli/config` * change settings such as `table_format = github` * restart sql cli, check the tabular output change @@ -47,11 +46,11 @@ ## Query Options * [ ] Test explain option -e - * `odfesql -q "SELECT * FROM accounts LIMIT 5;" -e` + * `opensearchsql -q "SELECT * FROM accounts LIMIT 5;" -e` * [ ] Test query and format option -q, -f - * `odfesql -q "SELECT * FROM accounts LIMIT 5;" -f csv` + * `opensearchsql -q "SELECT * FROM accounts LIMIT 5;" -f csv` * [ ] Test vertical output option -v - * `odfesql -q "SELECT * FROM accounts LIMIT 5;" -v` + * `opensearchsql -q "SELECT * FROM accounts LIMIT 5;" -v` ## OS and Python Version compatibility diff --git a/sql-cli/tests/utils.py b/sql-cli/tests/utils.py index 6cc693b2b1..f5e409cba5 100644 --- a/sql-cli/tests/utils.py +++ b/sql-cli/tests/utils.py @@ -16,30 +16,30 @@ import pytest from elasticsearch import ConnectionError, helpers, ConnectionPool -from src.odfe_sql_cli.esconnection import ESConnection -from src.odfe_sql_cli.utils import OutputSettings -from src.odfe_sql_cli.formatter import Formatter +from src.opensearch_sql_cli.opensearch_connection import OpenSearchConnection +from src.opensearch_sql_cli.utils import OutputSettings +from src.opensearch_sql_cli.formatter import Formatter -TEST_INDEX_NAME = "odfesql_cli_test" +TEST_INDEX_NAME = "opensearchsql_cli_test" ENDPOINT = "http://localhost:9200" def create_index(test_executor): - es = test_executor.client - es.indices.create(index=TEST_INDEX_NAME) + opensearch = test_executor.client + opensearch.indices.create(index=TEST_INDEX_NAME) def delete_index(test_executor): - es = test_executor.client - es.indices.delete(index=TEST_INDEX_NAME) + opensearch = test_executor.client + opensearch.indices.delete(index=TEST_INDEX_NAME) -def close_connection(es): - ConnectionPool.close(es) +def close_connection(opensearch): + ConnectionPool.close(opensearch) def load_file(test_executor, filename="accounts.json"): - es = test_executor.client + opensearch = test_executor.client filepath = "./test_data/" + filename @@ -49,17 +49,17 @@ def load_json(): for line in f: yield json.loads(line) - helpers.bulk(es, load_json(), index=TEST_INDEX_NAME) + helpers.bulk(opensearch, load_json(), index=TEST_INDEX_NAME) def load_data(test_executor, doc): - es = test_executor.client - es.index(index=TEST_INDEX_NAME, body=doc) - es.indices.refresh(index=TEST_INDEX_NAME) + opensearch = test_executor.client + opensearch.index(index=TEST_INDEX_NAME, body=doc) + opensearch.indices.refresh(index=TEST_INDEX_NAME) def get_connection(): - test_es_connection = ESConnection(endpoint=ENDPOINT) + test_es_connection = OpenSearchConnection(endpoint=ENDPOINT) test_es_connection.set_connection() return test_es_connection @@ -87,5 +87,5 @@ def run(test_executor, query, use_console=True): # use @estest annotation to mark test functions estest = pytest.mark.skipif( - not CAN_CONNECT_TO_ES, reason="Need a Elasticsearch server running at localhost:9200 accessible" + not CAN_CONNECT_TO_ES, reason="Need a OpenSearch server running at localhost:9200 accessible" ) \ No newline at end of file