classArithmetic
final class Arithmetic
implements Scalar
uses Snapshot
@visibility public.A binary arithmetic or bit operation of the bit_expr level, in the order written (Item_func_plus, Item_func_int_div, Item_func_bit_or, …).
The operators associate to the left with the levels of MYSQL-PRECEDENCE-001; an operand that would be read differently without a grouping is rejected, among them a right operand of + or - that starts with a leading interval INTERVAL n unit + x, which the parser reads as a trailing interval.
Rule: MYSQL-ARITHMETIC-001. Facts: the type follows MYSQL-NUMERIC-RESULT-001. +, -, * and the bit operators are NULL when an operand is; /, DIV and % are also NULL for a zero divisor. Both operands take a single value. Terminates: the operands are strict parts. Source: https://dev.mysql.com/doc/refman/8.4/en/arithmetic-functions.html, https://dev.mysql.com/doc/refman/8.4/en/bit-functions.html. Status: Implemented.
(new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT a FROM t WHERE a MOD 2 = 1')->toString() // => 'SELECT a FROM t WHERE a % 2 = 1'$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT a FROM t WHERE 1 / 2');
$query->facts->scalar($query->statement->where)->type->descriptor->name() // => 'DECIMAL'Properties§
public ArithmeticOperator $operatorpublic Scalar $leftpublic Scalar $rightMethods§
public function __construct(
public ArithmeticOperator $operator,
public Scalar $left,
public Scalar $right,
)Parameters
$operator | ArithmeticOperator | The operator |
$left | Scalar | The left operand |
$right | Scalar | The right operand |
Calls 8
- new Precedence line 54
- static-call Check::input() line 55
- method-call Precedence::fits() line 55
- method-call ArithmeticOperator::level() line 55
- method-call Precedence::opening() line 56
- method-call Precedence::leading() line 57
- class-const ArithmeticOperator::Plus() line 57
- class-const ArithmeticOperator::Minus() line 57
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives both operands and the type of the result.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 10
- new Operands line 65
- method-call Operands::single() line 66
- method-call Derivation::scalar() line 66
- method-call NumericResult::binary() line 68
- new NumericResult line 68
- class-const ArithmeticOperator::Divide() line 69
- class-const ArithmeticOperator::IntegerDivide() line 69
- class-const ArithmeticOperator::Modulo() line 69
- new ScalarFact line 71
- class-const Nullability::Nullable() line 71
public function render(Output $out): voidWrites the operands around the operator.
Parameters
$out | Output |
Test cases 1
Calls 4
- method-call Output::node() line 79
- class-const ArithmeticOperator::IntegerDivide() line 80
- method-call Output::keyword() line 81
- method-call Output::symbol() line 83
Test cases 29§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 5
ArithmeticTest::testARightOperandOfTheSameLevelIsRejectedcallsArithmeticTest::testARightOperandStartingWithALeadingIntervalIsRejectedcallsArithmeticTest::testAWeakerLeftOperandIsRejectedcallsArithmeticTest::testDeriveScalarTypesTheResultAndMakesADivisionNullablecallsArithmeticTest::testRenderWritesDivAsAKeywordAndKeepsTheLeftAssociationcalls
Other tests reaching this symbol 24
BitRuleTest::testBitExpressionBuildsTheLeftAssociationAndTheIntervalFormcallsExpressionRulesTest::testBitExpressionLowersAnArithmeticOperationcallsBlockRuleTest::providerInitialLowersTheDefaultClausecallsFlowRuleTest::testJumpLowersReturnLeaveAndIteratecallsFlowRuleTest::testLoopLowersLoopWhileAndRepeatcallsPrecedenceTest::testAbsorbsTellsWhetherAFollowingOperatorBindsIntoTheRightEdgecallsPrecedenceTest::testEdgesAnswerTheLevelsAndOperandsOfABinaryOperatorcallsPrecedenceTest::testLeadingAnswersTheExpressionWrittenFirstcallsPrecedenceTest::testOpeningIsTheWeakestLevelOnTheLeftEdgecallsItemNamingTest::testNameAnswersTheAliasTheColumnNameOrTheTextcallsItemNamingTest::testNameRefusesALayoutThatSpellsTheCanonicalRenderingcallsItemNamingTest::testOwnAnswersTheNamesOfTheItemsThatNameThemselvescallsItemNamingTest::testTextAnswersTheLayoutOrTheCanonicalRenderingcallsRowAliasesTest::testVisibleResolvesTheOldRowToTheTriggerTablecallsIntervalArithmeticTest::testABitOperandIsRejectedcallsIntervalArithmeticTest::testAMultiplicativeOperandIsAcceptedcallsBetweenTest::testALowerBoundThatTakesTheAndIsRejectedcallsLikeTest::testAnArithmeticPatternIsRejectedcallsMemberOfTest::testAnArithmeticArrayIsRejectedcallsSelectExpressionTest::testALayoutWithTrailingTriviaIsRejectedcallsSelectExpressionTest::testRenderWritesAnItemBuiltWithoutLayoutCanonicallycallsColumnDefinitionTest::testDeriveElementDerivesTheSpecificationInTheTablecallsDefaultExpressionTest::testDeriveAttributeResolvesColumnsOfTheTablecallsCreateIndexTest::testDeriveStatementResolvesTheKeyPartsInTheTablecalls