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

Error when neutral is null and exprs is empty in OperatorAST #2

Open
Seb35 opened this issue Dec 4, 2021 · 0 comments
Open

Error when neutral is null and exprs is empty in OperatorAST #2

Seb35 opened this issue Dec 4, 2021 · 0 comments

Comments

@Seb35
Copy link

Seb35 commented Dec 4, 2021

In SQLDSL, some methods like sum create an OperatorAST with a neutral argument (4th parameter) null, but in some cases (when exprs is empty) OperatorAST calls this.neutral.writeTo(b); so I guess it can create errors, something like:

AST tree = select(sum(), from(id("songs")));

because in OperatorAST in method writeTo, if this.neutral is null there is no method writeTo():

if (n == 0) {
	this.neutral.writeTo(b);
}

Obviously this would lead to incorrect SQL, so a choice must be taken: either throw an exception either write wrong SQL and let the SQL library trigger an error. Personally I would choose the second option because the objective of this library sqltrees is probably not to re-implement the whole (dialects of) SQL semantics.

I’m not completely affirmative because I’m not fluent in Java, so perhaps I miss some language detail. But I was interested by the article in MISC and I took as an exercice to transpile/implement it to PHP (I master this language), and in the corresponding situation PHP complains.

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

No branches or pull requests

1 participant