Hi Lukas,
We are lucky that Java does not have more reserved keywords, otherwise:I think keywords should not be replaced with synonyms, otherwise you are not mapping SQL to Java, but SQL to a jOOQ-specific QL. I think that even if it is not as good as having "case()" and "else()", there should be "case_()" and "else_()". Developers would understand that this is because of reserved keywords and would not have to analyze the API/documentation to map their SQL.The CASE expression is indeed modeled by DSL.decode(), as you can see here:
"Unfortunately, both case and else are reserved words in Java. jOOQ chose to use decode() from the OracleDECODE
function, and otherwise(), which means the same as else."
SELECT * FROM BOOK WHERE PUBLISHED_IN = 2011 ORDER BY TITLE
would have been:
create.pickFrom(BOOK).condition(PUBLISHED_IN.sameAs(2011)).sortBy(TITLE)
:)
I have to say, if you were to change things to get around reserved words I would vote for d (all-uppercase).
The logic is no more than - this seems to be the way people have/do write SQL queries. I can't say its part of any standard, but it does seem to be the convention and its one I've been following for rather to many years. It maybe just because I and SQL come from an age when uppercase was use in languages such as Informix 4GL :)
One thing, all the background info you have provided would fit rather well in the main jOOQ document - under some form of background or why it is as it is heading.
--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
2013/6/23 Roger Thomas <rithom...@gmail.com>
I have to say, if you were to change things to get around reserved words I would vote for d (all-uppercase).
The logic is no more than - this seems to be the way people have/do write SQL queries. I can't say its part of any standard, but it does seem to be the convention and its one I've been following for rather to many years. It maybe just because I and SQL come from an age when uppercase was use in languages such as Informix 4GL :)
.... and FORTRAN, COBOL, BASIC, I remember those days. Pascal and C really messed up our upper / lower casing universe! ;-)d) has its "extreme cases" as well, such as:- ON_DUPLICATE_KEY_UPDATE()- WHEN_MATCHED_THEN_UPDATE()- WHEN_NOT_MATCHED_THEN_INSERT()The obvious advantage of making SQL DSL methods all-uppercase is the fact that they can be immediately distinguished from non-DSL methods, such as:- a.BETWEEN(b).AND(c)- a.BETWEEN_SYMMETRIC(b).AND(c)- a.IS_NULL()- a.IS_NOT_NULL()- ROW_NUMBER().OVER().PARTITION_BY(a).ORDER_BY(b)as opposed to- a.getName()- a.getType()- a.getDataType()Maybe, both APIs could be maintained in parallel using a code-generator, leaving the decision up to the user, whether they want to camel-case or upper-case their SQL DSL. From a backwards-compatibility perspective, there's probably no choice in maintaining both in parallel anyway.
I have to say, if you were to change things to get around reserved words I would vote for d (all-uppercase).
The logic is no more than - this seems to be the way people have/do write SQL queries. I can't say its part of any standard, but it does seem to be the convention and its one I've been following for rather to many years. It maybe just because I and SQL come from an age when uppercase was use in languages such as Informix 4GL :)
One thing, all the background info you have provided would fit rather well in the main jOOQ document - under some form of background or why it is as it is heading.
--
1. By introducing artificial keywords. ExamplesSQL: UPDATE t SET a = 1, b = 2jOOQ: update(t).set(a, 1).set(b, 2)
Note that this example also shows missing operator overloading capabilities, where "=" is replaced by ","
SQL: ORDER BYjOOQ: orderBy()
6. By using descriptive methods, or a commaMost SQL operators have to be mapped to descriptive method names in Java:
SQL: =jOOQ: equal(), eq()
SQL: <>jOOQ: notEqual(), ne()
7. That cannot be worked aroundThis is what has been keeping me from implementing CTE so far.SQL: WITH a(x, y) AS (SELECT 1, 2) SELECT a.x, a.y FROM a
Discussiona) by using synonyms
b) by appending "disambiguators" such as case_ or case$ or case
c) by introducing artificial spelling, such as casë, casǝ, casɇ ;-)
d) by changing the API to be all-uppercase: SELECT(), CASE(), ORDER_BY()
e) by changing the API to be camel-case with an upper-case initial letter: Select(), Case(), OrderBy()
d) and e) are massive changes.
Any other ideas?
2013/6/23 Lukas Eder <lukas...@gmail.com>2013/6/23 Roger Thomas <rithom...@gmail.com>
I have to say, if you were to change things to get around reserved words I would vote for d (all-uppercase).
The logic is no more than - this seems to be the way people have/do write SQL queries. I can't say its part of any standard, but it does seem to be the convention and its one I've been following for rather to many years. It maybe just because I and SQL come from an age when uppercase was use in languages such as Informix 4GL :)
.... and FORTRAN, COBOL, BASIC, I remember those days. Pascal and C really messed up our upper / lower casing universe! ;-)
It's odd, but I think Informix was mixed case, its just SQL was by convention uppercase. Having looked around a bit the old embedded SQL in C and SQLJ also followed this convention of SQL reserved words being upper case in a mixed case world. Its odd how such a hangover from the 80s can still be a strong convention now.
On Sunday, June 23, 2013 9:34:34 AM UTC+1, Lukas Eder wrote:2013/6/23 Lukas Eder <lukas...@gmail.com>It's odd, but I think Informix was mixed case, its just SQL was by convention uppercase. Having looked around a bit the old embedded SQL in C and SQLJ also followed this convention of SQL reserved words being upper case in a mixed case world. Its odd how such a hangover from the 80s can still be a strong convention now.2013/6/23 Roger Thomas <rithom...@gmail.com>
I have to say, if you were to change things to get around reserved words I would vote for d (all-uppercase).
The logic is no more than - this seems to be the way people have/do write SQL queries. I can't say its part of any standard, but it does seem to be the convention and its one I've been following for rather to many years. It maybe just because I and SQL come from an age when uppercase was use in languages such as Informix 4GL :)
.... and FORTRAN, COBOL, BASIC, I remember those days. Pascal and C really messed up our upper / lower casing universe! ;-)
I presume to get the different styles of case (current, upper and camel-case) would involve writting each method in DSL.java 3 times over - each with the different name and each with it's own java doc.
While not very active, I did keep an eye on this discussion, and I too found your answer to be very valuable. I am glad to see it making it somewhere in the manual.
Languages have reserved keywords, so mapping a language to another is likely to clash on some reserved keywords. The amount of clash depends on the languages that we consider and tricks we can apply. One consideration is about the target languages: should we have the same considerations for jOOQ used in Java and jOOQ used in say Scala? I will use "Scala" as a generic way of saying "other languages" throughout the discussion. Of course I understand that jOOQ's primary target is Java, but I am curious.
1. By introducing artificial keywords. ExamplesSQL: UPDATE t SET a = 1, b = 2jOOQ: update(t).set(a, 1).set(b, 2)Note that this example also shows missing operator overloading capabilities, where "=" is replaced by ","
Would jOOQ on Scala be able to more closely match such construct if one wanted to?
SQL: ORDER BYjOOQ: orderBy()
Would jOOQ on Scala be able to more closely match such construct? I guess that would mean having ORDER(BY(xxx)) and then BY could be problematic if used in other places.
6. By using descriptive methods, or a commaMost SQL operators have to be mapped to descriptive method names in Java:
SQL: =jOOQ: equal(), eq()
What is the rule with verbs? Should it be 3rd person, like "equals()" (if there were no collisions with Java's equals)?
SQL: <>jOOQ: notEqual(), ne()Would jOOQ on Scala be able to more closely match such construct?
7. That cannot be worked aroundThis is what has been keeping me from implementing CTE so far.SQL: WITH a(x, y) AS (SELECT 1, 2) SELECT a.x, a.y FROM a
What is the problem with the above expression?
Discussiona) by using synonymsThis is the worst suggestion in my view.
b) by appending "disambiguators" such as case_ or case$ or case
I don't mind hard rules, like "any keyword that may clash with Java keyword is going to be suffixed with '_'". I prefer suffix, because code completion would work when I start typing "case".
c) by introducing artificial spelling, such as casë, casǝ, casɇ ;-)
OK, this *IS* the worst suggestion :)
You forgot \uFF43\uFF41\uFF53\uFF45: case
d) by changing the API to be all-uppercase: SELECT(), CASE(), ORDER_BY()
My initial reaction was "ouch, this is ugly Java", but I do write SQL all caps, so having the DSL part be all caps to map SQL is really not that bad.
e) by changing the API to be camel-case with an upper-case initial letter: Select(), Case(), OrderBy()
This is odd, because it is neither the Java convention nor SQL.
d) and e) are massive changes.
Apart from being an incompatible API, what is the complexity? User manual mainly?
Any other ideas?Apart from silly ideas like "cASE", not really :)
> As you can see, there are a lot of caveats when> (as opposed to an external one). [...]
> implementing an internal domain specific language
> I currently see four ways to solve 5)Not good, because the synonyms have to be looked up in the API doc.
>
> a) by using synonyms
Workable but ugly.
> b) by appending "disambiguators" such as case_ or case$ or case
Cute :-)
> c) by introducing artificial spelling, such as casë, casǝ, casɇ ;-)
But doesn't solve the problem, since you still have to look up the spelling variation employed in each specific case.
> d) by changing the API to be all-uppercase: SELECT(), CASE(), ORDER_BY()Workable but awkward to type.
Also awkward to read. Lowercase letters are easier to distinguish than uppercase letters (because the outlines have more variation I think).
And an incompatible change, too.
> e) by changing the API to be camel-case with an upper-case initial letter: Select(), Case(), OrderBy()
Workable but an incompatible change.
> Any other ideas?
None. You've been quite thorough here.
I see a slightly different issue at work here: Most replacements are more-or-less obvious choices, but decode() is a nonobvious replacement for IF/CASE.
It's essentially perpetuating the misnaming of Oracle's DECODE(). It sort-of makes sense to do it that way, but it won't be understood or appreciated by those who work in other languages. Given the tool wars many people entertain, reusing Oracle nomenclature might even mark you as adherent of one particular camp.
select() might work. choice() could even be an even better, erm, choice. Or maybe choose().
Yes, "choose" would be much better. Given that "else" is mapped to "otherwise", "choose" wouldn't be too bad. This would at least remind of XSL or JSTL. Both XSL and JSTL also know "then", so it would at least be more consistent.I guess, a short-term solution would include either "case_" or "choose"
Yes, "choose" would be much better. Given that "else" is mapped to "otherwise", "choose" wouldn't be too bad. This would at least remind of XSL or JSTL. Both XSL and JSTL also know "then", so it would at least be more consistent.I guess, a short-term solution would include either "case_" or "choose"
If you are looking to add a nice short-term solution if would say case_ (and I guess else_) as both of these use the correct SQL verb and would both operate correctly in an IDE lookahead editor.