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

Initial support for JQL #721

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Initial support for JQL #721

wants to merge 9 commits into from

Conversation

doc-sheet
Copy link

Hello.

There is some basic support for JQL, could you suggest some impovements?

For now it produces

project IN ("PROJ1","PROJ2") AND issuetype="My issue" AND (labels is EMPTY OR labels NOT IN ("stale","bug")) AND Привет is EMPTY AND repos is not EMPTY AND repos NOT IN ("main","dev")

for a query like this

J = JiraTable()
j = (
    JiraQueryBuilder()
    .where(J.project.isin(["PROJ1", "PROJ2"]))
    .where(J.issuetype == "My issue")
    .where(J.labels.isempty() | J.labels.notin(["stale", "bug"]))
    .where(getattr(J, "Привет").isempty())
    .where(J.repos.notempty() & J.repos.notin(["main", "dev"]))
)
print(j.get_sql())

@doc-sheet doc-sheet requested a review from a team as a code owner March 25, 2023 15:22
@AzisK
Copy link

AzisK commented Sep 22, 2023

By JQL do you mean the selection in Jira or does it have more meanings?

@AzisK
Copy link

AzisK commented Sep 22, 2023

Could you add tests?

@doc-sheet
Copy link
Author

By JQL do you mean the selection in Jira or does it have more meanings?
Yeah, jql as jira query language

I din't aim for full support, just the tools I use myself.
But I can add more if needed. I guess.

@AzisK
Copy link

AzisK commented Sep 24, 2023

I believe there is no need to start with full support. We can start little and then later extend it. Could you also add this possibility in the documentation?

@doc-sheet
Copy link
Author

Sure! Done.


.. code-block:: python

from pypika import MySQLQuery, MSSQLQuery, PostgreSQLQuery, OracleQuery, VerticaQuery
Copy link

Choose a reason for hiding this comment

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

JiraTable seems not to be imported and these seem unnecessary

Copy link
Author

Choose a reason for hiding this comment

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

oh
sorry, copypaste issue

@doc-sheet
Copy link
Author

ugh
There was a dependency conflict in my venv: https://stackoverflow.com/a/71674345


.. code-block:: python

from pypika import JiraTable, JiraQueryBuilder
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the example use JiraQuery instead of JiraQueryBuilder?

Copy link
Contributor

Choose a reason for hiding this comment

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

Think that that would provide consistency with the rest of the API

Copy link
Author

Choose a reason for hiding this comment

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

To be honest I just don't know how to make in consistent.
There are no such thing as tables (so JiraTable is just a dummy placeholder).

Best thing I can do is probably create a bunch of overrides for from_, into and other methods which would return cls._builder(**kwargs)

Is it ok?

>>> table = JiraTable()
>>> JiraQuery._builder().where(table.project.isin(["PROJ1", "PROJ2"]))
project IN ("PROJ1","PROJ2")

Copy link
Author

Choose a reason for hiding this comment

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

Hm. I guess JiraQuery.from_(table).where(table.project.isin(["PROJ1", "PROJ2"])) looks kind consistent.

Copy link
Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@wd60622 wd60622 Oct 17, 2023

Choose a reason for hiding this comment

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

Maybe the JiraQuery could have a where class method as well that initializes table.

Personally, I tend to used Fields

Maybe it would read like this

query = (
    JiraQuery
    .where(
        (Field("project").isin(["PROJ1", "PROJ2"]))
        & (Field("issuetype") == "my_issue_type")
    )
)

Copy link
Author

Choose a reason for hiding this comment

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

Done.
Working in both ways:

>>> JiraQuery.where(Field("project").isin(["PROJ1", "PROJ2"]) & (Field("issuetype") == "my_issue_type"))
project IN ("PROJ1","PROJ2") AND issuetype="my_issue_type"
>>> table = JiraTable()
>>> JiraQuery.where(table.project.isin(["PROJ1", "PROJ2"]) | table.project == 2)
project IN ("PROJ1","PROJ2") OR project=2


J = JiraTable()
j = (
JiraQuery._builder().from_(J)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd recommend against using the _ methods

Copy link
Contributor

@wd60622 wd60622 left a comment

Choose a reason for hiding this comment

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

Looks good to me! Just one more comment on the example

.where(J.labels.isempty() | J.labels.notin(["stale", "bug"]))
.where(J.repos.notempty() & J.repos.notin(["main", "dev"]))
)
print(j.get_sql())
Copy link
Contributor

Choose a reason for hiding this comment

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

Some of the other examples show the result explicitly

Copy link
Author

Choose a reason for hiding this comment

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

Done.
Also I forgot to import JiraQuery into main class. So I also had to add Table method for consistency

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.

3 participants