GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fixing a problem with an OP_CONCAT in WhenExpression by amigalev · Pull Request #1837 · JSQLParser/JSqlParser

Conversation

@amigalev

@amigalev amigalev commented Jul 26, 2023

Copy link
Copy Markdown
Contributor

Version: 4.7-SNAPSHOT

The problem was in an ELSE part of the WHEN expression. When we had a sub WHEN in ELSE and concatenate it with some another string:
CASE WHEN 1 = 2 THEN 'string1' ELSE CASE WHEN 2 = 3 THEN 'string2' ELSE 'first part' END || 'second part' END

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
amigalev and others added 2 commits July 25, 2023 23:22
@amigalev
fix: Concatenation in inner ELSE statement (Second level of Case Expr…
d369805
…ession)
@amigalev
Merge branch 'JSQLParser:master' into master
7dfb732
@manticore-projects

manticore-projects commented Jul 26, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Thank you for your contribution.
Existing Tests fail, please ensure the complete test suite is running through before sending PRs.

If also do not understand why you would like to catch ConcatExpression first when there is already a general Expression in the second branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@amigalev

amigalev commented Jul 26, 2023

Copy link
Copy Markdown
Contributor Author

Thank you for your contribution. Existing Tests fail, please ensure the complete test suite is running through before sending PRs.

If also do not understand why you would like to catch ConcatExpression first when there is already a general Expression in the second branch.

I'm sorry for tests, for some reason some tests have been failed in my environment. I'll try to fix it asap. Which build system should I use? Gradle or Maven?

About your second question.
The reason is that in an ELSE part we check use LOOKAHEAD(3, {!interrupted}) and as I understand the execution will go throught LOOKAHEAD(3, {!interrupted}) elseExp=CaseWhenExpression() insead of elseExp=SimpleExpression(). To avoid an expensive LOOKAHEADs I decided to add additional ConcatExpression (the LOOKAHEAD(ConcatExpression()) looks cheaper.).

If I understand incorrectly, please tell me and I'll find another solution

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@amigalev
fix: broken tests
3c15f6e
@amigalev

amigalev commented Jul 28, 2023

Copy link
Copy Markdown
Contributor Author

I've fixed tests, but the solution of my core problem has changed. I think, It will be a bit slower then previous, but THEN part in WhenThenSearchCondition works similar.

The problem has been occurred because the ConcatExpression (and a lot of other) uses * instead of + and catches single S_IDENTIFIER instead of full concat expression. I've tried to change this behaviour, but many parts of grammar use it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@manticore-projects

manticore-projects commented Jul 29, 2023

Copy link
Copy Markdown
Contributor

The problem has been occurred because the ConcatExpression (and a lot of other) uses * instead of + and catches single S_IDENTIFIER instead of full concat expression.

From what I can see, your fix is likely correct since we need to always test the most complex possible interpretation first.
This is counter intuitive, because from a performance perspective one would like to look for the simplest interpretation before diving into unlikely complex structures.

Example: a + b + c + d
Will be parsed as (a + b + c) + d since (a + b) + c + d would left the parser stranded.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@amigalev

amigalev commented Jul 31, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

You're right. I forgot to delete LOOKAHEAD(3) and it this will be exactly the same as part THEN. Will this snippet good or do you mean sth else?

        <K_ELSE>
        (
              LOOKAHEAD({getAsBoolean(Feature.allowComplexParsing) && !interrupted}) elseExp=Expression()
              | elseExp=SimpleExpression()
        )
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@manticore-projects manticore-projects closed this Jul 31, 2023
@amigalev

amigalev commented Jul 31, 2023

Copy link
Copy Markdown
Contributor Author

Could you explain me, why did you close the PR? I really need the fix this problem. If my fix is not correct by performance reasons I'll try to fix it in some another way.
I thought if you use the same way for the THEN part, it will be ok for the ELSE part too (why not?). This is snippet for THEN:

<K_THEN>
    (
        LOOKAHEAD({getAsBoolean(Feature.allowComplexParsing) && !interrupted}) thenExp=Expression()
        |
        thenExp=SimpleExpression()
    ) 

As an example I can try to rewrite the concat function to solve this problem. It will be a bit more complex but it will work faster

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@manticore-projects

manticore-projects commented Jul 31, 2023

Copy link
Copy Markdown
Contributor

Apologies, I actually believed to have MERGED it!
At least this was what I wanted to do.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@manticore-projects manticore-projects reopened this Jul 31, 2023
@amigalev

amigalev commented Jul 31, 2023

Copy link
Copy Markdown
Contributor Author

Thank you, please wait for 5 min, I'll delete LOOKAHEAD(3).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@amigalev
fix: Delete lookahead(3)
b185370
@manticore-projects
manticore-projects merged commit f05cb7f into JSQLParser:master Aug 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@amigalev @manticore-projects
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.