Skip to content

Commit

Permalink
HHH-16048 Handle integer division emulation also for TiDB
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Feb 19, 2024
1 parent d7a4645 commit 7f14b2c
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.hibernate.sql.ast.tree.MutationStatement;
import org.hibernate.sql.ast.tree.Statement;
import org.hibernate.sql.ast.tree.delete.DeleteStatement;
import org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression;
import org.hibernate.sql.ast.tree.expression.CastTarget;
import org.hibernate.sql.ast.tree.expression.ColumnReference;
import org.hibernate.sql.ast.tree.expression.Expression;
Expand Down Expand Up @@ -54,6 +55,20 @@ public TiDBSqlAstTranslator(SessionFactoryImplementor sessionFactory, Statement
this.dialect = (TiDBDialect) super.getDialect();
}

@Override
public void visitBinaryArithmeticExpression(BinaryArithmeticExpression arithmeticExpression) {
if ( isIntegerDivisionEmulationRequired( arithmeticExpression ) ) {
appendSql( OPEN_PARENTHESIS );
arithmeticExpression.getLeftHandOperand().accept( this );
appendSql( " div " );
arithmeticExpression.getRightHandOperand().accept( this );
appendSql( CLOSE_PARENTHESIS );
}
else {
super.visitBinaryArithmeticExpression(arithmeticExpression);
}
}

@Override
protected void visitInsertSource(InsertSelectStatement statement) {
if ( statement.getSourceSelectStatement() != null ) {
Expand Down

0 comments on commit 7f14b2c

Please sign in to comment.