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

Correct precedence for arithmetic operators #788

Merged
merged 3 commits into from
Feb 14, 2020
Merged

Correct precedence for arithmetic operators #788

merged 3 commits into from
Feb 14, 2020

Conversation

toefel18
Copy link
Contributor

@toefel18 toefel18 commented Feb 9, 2020

See issue #787

Exposed did not follow the correct operator precedence rules for arithmetic operators.

@Tapac
Copy link
Contributor

Tapac commented Feb 13, 2020

Thank you for the PR.
I have one extension: since the last release (0.21.1) there is CustomOperator class which suites operators like div/plus/etc very well.

Do you mind to change all the operators (where applicable) to be inherited from a CustomOperator?

@toefel18
Copy link
Contributor Author

I'll take a look and change it to CustomerOperator! 👍 Let's see if I have some time later on today.

I would also like to change the type of .avg(), any reason why that is the only one typed BigInteger?

@Tapac
Copy link
Contributor

Tapac commented Feb 13, 2020

It's BigDecimal because of some databases returns floating value as a result of AVG even on integer/long columns. (See samples here)

@Tapac
Copy link
Contributor

Tapac commented Feb 13, 2020

I meant something like:

class DivideOp<T, S: T>(
    val expr1: Expression<T>, val expr2: Expression<S>, override val columnType: IColumnType
): ExpressionWithColumnType<T>()

should become

class DivideOp<T, S: T>(expr1: Expression<T>, expr2: Expression<S>, columnType: IColumnType) 
  : CustomOperator<T>("/", columnType, expr1, expr2)

@toefel18
Copy link
Contributor Author

Sorry, I totally misread your initial comment. I updated the code and added a comment for the avg(). If you think this is common sense, I can remove it if you prefer.

Some unit tests fail at on my machine (also when I run a build without my changes)

Some failures are in the java-time module and are due to precision.

org.jetbrains.exposed.MiscTableTest > testUpdate03 FAILED
    java.lang.AssertionError: Failed on h2 expected:<2020-02-13T21:02:47.938743> but was:<2020-02-13T21:02:47.938>

But 6 failures in exposed-core seem valid, like ReplaceTests.testReplace01:
The error is:

22:24:13,294 ERROR Test worker Exposed:checkMultipleDeclaration:392 - Confusion between multiple declarations of primary key on . Use only override val primaryKey=PrimaryKey() declaration.
22:24:13,296  WARN Test worker Exposed:invoke:169 - Transaction attempt #0 failed: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Incorrect table name ''. Statement(s): CREATE TABLE IF NOT EXISTS `` (username VARCHAR(16) PRIMARY KEY, `session` VARBINARY(64) NOT NULL, `timestamp` BIGINT DEFAULT 0 NOT NULL, serverID VARCHAR(64) DEFAULT '' NOT NULL)
org.jetbrains.exposed.exceptions.ExposedSQLException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Incorrect table name ''
SQL: [CREATE TABLE IF NOT EXISTS `` (username VARCHAR(16) PRIMARY KEY, `session` VARBINARY(64) NOT NULL, `timestamp` BIGINT DEFAULT 0 NOT NULL, serverID VARCHAR(64) DEFAULT '' NOT NULL)]

Adding a table name fixes this:

    @Test
    fun testReplace01() {
        val NewAuth = object : Table() {   // <-  missing table name?
    ...

Shall I fix these errors or am I missing something here?

@Tapac
Copy link
Contributor

Tapac commented Feb 14, 2020

Which Java version do you use?
"Incorrect table name '' error looks similar to one when KClass.simpleName doesn't return a name for anonymouse classes (works fine on Java 8 but fails on 9+).

I'll check it by myself, so at the moment the PR looks fine to me.
Thank you.

@Tapac Tapac merged commit d512d18 into JetBrains:master Feb 14, 2020
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.

2 participants