classResultTyping
final class ResultTyping
The result facts of a built-in function from its result code and the facts of its arguments.
Rule: MYSQL-CALL-RESULT-001. A result code is two letters: the type and the NULL rule. Fixed types: I BIGINT, U BIGINT UNSIGNED, D DOUBLE, N DECIMAL, T a character string, B a binary string, J JSON, V VECTOR, G a geometry, A DATE, M TIME, E DATETIME. Derived types: S a string whose character set comes from the arguments (binary when one is binary); H the numeric type of the first argument and O that of all arguments (an exact integer stays BIGINT, DECIMAL stays DECIMAL, anything else is DOUBLE); C CEILING and FLOOR, whose DECIMAL argument gives BIGINT or DECIMAL by its size; 1 and 2 the type of the first or second argument; + the aggregated type of all arguments and Z of the arguments after the first (MYSQL-TYPE-AGGREGATION-001); X ADDTIME and SUBTIME, which keep a DATETIME or TIME first argument and give a string otherwise; K STR_TO_DATE, a DATE, TIME or DATETIME by the format; W UNIX_TIMESTAMP of a value, BIGINT or DECIMAL by its fractional seconds. NULL rules: P NULL exactly when an argument can be NULL, N never NULL, Y possibly NULL, C NULL only when every argument can be, F as the first argument, L as the last argument, R NULL when an argument after the first can be. The codes of the built-in functions are listed by MYSQL-NATIVE-FUNCTIONS-001 and the call classes. Terminates: one pass over the arguments. Source: https://dev.mysql.com/doc/refman/8.4/en/functions.html, https://dev.mysql.com/doc/refman/8.4/en/type-conversion.html. Status: Implemented.
Methods§
public function fact(string $code, list<ScalarFact> $arguments): ScalarFactAnswers the facts of a result.
Parameters
$code | string | The two-letter result code |
$arguments | list<ScalarFact> | The facts of the arguments in order |
Returns
Test cases 2
Called from 8
- method-call SqlSemantics\Platform\MySql\Rules\Call\RoutineCalls::result() packages/sql-semantics-mysql/src/Rules/Call/RoutineCalls.php:63
- method-call SqlSemantics\Platform\MySql\Statement\Call\Extract::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Extract.php:48
- method-call SqlSemantics\Platform\MySql\Statement\Call\KeywordCall::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/KeywordCall.php:76
- method-call SqlSemantics\Platform\MySql\Statement\Call\Position::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Position.php:53
- method-call SqlSemantics\Platform\MySql\Statement\Call\Temporal\GetFormat::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Temporal/GetFormat.php:47
- method-call SqlSemantics\Platform\MySql\Statement\Call\Trim::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Trim.php:56
- method-call SqlSemantics\Platform\MySql\Statement\Call\Weight\WeightString::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Weight/WeightString.php:71
- method-call SqlSemantics\Platform\MySql\Statement\Call\Weight\WeightStringParameters::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Weight/WeightStringParameters.php:51
Calls 5
- static-call Check::invariant() line 64
- function-call
strlenline 64 - new ScalarFact line 66
- method-call ResultTyping::type() line 66
- method-call ResultTyping::nullability() line 66
public function type(string $code, list<ScalarFact> $arguments): TypeFactAnswers the type a type code gives.
Parameters
$code | string | |
$arguments | list<ScalarFact> |
Returns
Throws
InvariantViolation When the code is not a type codeTest cases 2
Called from 2
- method-call SqlSemantics\Platform\MySql\Rules\Call\ResultTyping::fact() packages/sql-semantics-mysql/src/Rules/Call/ResultTyping.php:66
- method-call SqlSemantics\Platform\MySql\Statement\Call\Aggregate\GroupConcat::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Aggregate/GroupConcat.php:103
Calls 18
- class-const ResultTyping::FIXED() line 77
- new Known line 78
- function-call
array_mapline 80 - new TypeAggregation line 81
- new TypeClasses line 82
- method-call ResultTyping::string() line 85
- method-call ResultTyping::numeric() line 86
- function-call
array_sliceline 86 - new NullOnly line 89
- method-call TypeAggregation::aggregate() line 91
- method-call ResultTyping::temporal() line 93
- method-call TypeClasses::fact() line 94
- class-const TypeClass::Date() line 94
- class-const TypeClass::Time() line 94
- class-const TypeClass::DateTime() line 94
- class-const TypeClass::Integer() line 95
- class-const TypeClass::Decimal() line 95
- new InvariantViolation line 96
Answers the type of a string result whose character set comes from the arguments.
Parameters
$types | list<TypeFact> |
Returns
Test cases 1
Called from 1
Calls 8
- method-call TypeClasses::classes() line 110
- new TypeClasses line 110
- function-call
in_arrayline 111 - class-const TypeClass::Binary() line 111
- class-const TypeClass::Spatial() line 111
- new Known line 115
- method-call TypeClasses::fact() line 118
- class-const TypeClass::Character() line 118
Answers the numeric type of the arguments of a numeric function.
An argument of an integer class, YEAR or BIT is an integer, DECIMAL is DECIMAL (or an integer for CEILING and FLOOR when it fits), a date or time is an integer or a DECIMAL by its fractional seconds, any other argument is DOUBLE; several arguments combine as numbers do.
Parameters
$types | list<TypeFact> | |
$integral | bool | Whether a DECIMAL argument may give an integer, as for CEILING and FLOOR |
Returns
Test cases 1
Called from 3
- method-call SqlSemantics\Platform\MySql\Rules\Call\ResultTyping::type() packages/sql-semantics-mysql/src/Rules/Call/ResultTyping.php:86
- method-call SqlSemantics\Platform\MySql\Rules\Call\ResultTyping::type() packages/sql-semantics-mysql/src/Rules/Call/ResultTyping.php:87
- method-call SqlSemantics\Platform\MySql\Rules\Call\ResultTyping::type() packages/sql-semantics-mysql/src/Rules/Call/ResultTyping.php:88
Calls 8
- new TypeClasses line 134
- method-call ResultTyping::numbers() line 141
- method-call TypeClasses::classes() line 141
- method-call TypeClasses::merge() line 143
- function-call
array_valuesline 148 - function-call
array_filterline 148 - new NullOnly line 150
- method-call TypeClasses::fact() line 150
Answers the numeric classes an argument of the given classes is converted to; no class is any number.
Parameters
$classes | list<TypeClass> | |
$integral | bool |
Returns
list<TypeClass>Test cases 1
Called from 1
Calls 8
- class-const TypeClass::Integer() line 162
- class-const TypeClass::Decimal() line 162
- class-const TypeClass::Floating() line 162
- function-call
array_pushline 166 - function-call
in_arrayline 167 - class-const TypeClass::Unsigned() line 167
- class-const TypeClass::Year() line 167
- class-const TypeClass::Bit() line 167
Answers the type of ADDTIME and SUBTIME from the type of the first argument.
Parameters
$first | TypeFact |
Returns
Test cases 1
Called from 1
Calls 17
- method-call TypeClasses::classes() line 185
- new TypeClasses line 185
- method-call TypeClasses::fact() line 187
- class-const TypeClass::DateTime() line 187
- class-const TypeClass::Time() line 187
- class-const TypeClass::Character() line 187
- class-const TypeClass::Date() line 192
- class-const TypeClass::Integer() line 194
- class-const TypeClass::Unsigned() line 194
- class-const TypeClass::Decimal() line 194
- class-const TypeClass::Floating() line 194
- class-const TypeClass::Binary() line 194
- class-const TypeClass::Year() line 195
- class-const TypeClass::Json() line 195
- class-const TypeClass::Spatial() line 195
- class-const TypeClass::Bit() line 195
- class-const TypeClass::Vector() line 195
public function dateArithmetic(TypeFact $date, IntervalUnit $unit): TypeFactAnswers the type of a date plus or minus an interval: DATE_ADD, DATE_SUB, ADDDATE, SUBDATE and TIMESTAMPADD.
A DATE stays a DATE for a unit of days or larger and becomes a DATETIME otherwise; a TIME stays a TIME for a unit of hours or smaller; a DATETIME or TIMESTAMP gives a DATETIME; any other argument gives a string (https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html#function_date-add).
Parameters
$date | TypeFact | |
$unit | IntervalUnit |
Returns
Test cases 1
Called from 3
- method-call SqlSemantics\Platform\MySql\Statement\Call\KeywordCall::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/KeywordCall.php:73
- method-call SqlSemantics\Platform\MySql\Statement\Call\Temporal\DateArithmetic::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Temporal/DateArithmetic.php:57
- method-call SqlSemantics\Platform\MySql\Statement\Call\Temporal\TimestampCall::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Temporal/TimestampCall.php:59
Calls 34
- method-call TypeClasses::classes() line 215
- new TypeClasses line 215
- method-call TypeClasses::fact() line 217
- class-const TypeClass::Date() line 217
- class-const TypeClass::Time() line 217
- class-const TypeClass::DateTime() line 217
- class-const TypeClass::Character() line 217
- function-call
in_arrayline 219 - class-const IntervalUnit::Day() line 219
- class-const IntervalUnit::Week() line 219
- class-const IntervalUnit::Month() line 219
- class-const IntervalUnit::Quarter() line 219
- class-const IntervalUnit::Year() line 219
- class-const IntervalUnit::YearMonth() line 219
- class-const IntervalUnit::Microsecond() line 220
- class-const IntervalUnit::Second() line 220
- class-const IntervalUnit::Minute() line 220
- class-const IntervalUnit::Hour() line 220
- class-const IntervalUnit::SecondMicrosecond() line 220
- class-const IntervalUnit::MinuteMicrosecond() line 220
- class-const IntervalUnit::MinuteSecond() line 220
- class-const IntervalUnit::HourMicrosecond() line 220
- class-const IntervalUnit::HourSecond() line 220
- class-const IntervalUnit::HourMinute() line 220
- class-const TypeClass::Integer() line 227
- class-const TypeClass::Unsigned() line 227
- class-const TypeClass::Decimal() line 227
- class-const TypeClass::Floating() line 227
- class-const TypeClass::Binary() line 227
- class-const TypeClass::Year() line 228
- class-const TypeClass::Json() line 228
- class-const TypeClass::Spatial() line 228
- class-const TypeClass::Bit() line 228
- class-const TypeClass::Vector() line 228
public function nullability(string $rule, list<ScalarFact> $arguments): NullabilityAnswers the NULL fact a NULL rule gives.
Parameters
$rule | string | |
$arguments | list<ScalarFact> |
Returns
Throws
InvariantViolation When the code is not a NULL ruleTest cases 2
Called from 2
Calls 8
- function-call
array_mapline 243 - method-call ResultTyping::propagate() line 246
- class-const Nullability::NotNull() line 247
- class-const Nullability::Nullable() line 248
- method-call ResultTyping::coalesce() line 249
- function-call
countline 251 - function-call
array_sliceline 252 - new InvariantViolation line 253
public function propagate(list<Nullability> $facts): NullabilityCombines NULL facts when NULL in any operand gives NULL.
Parameters
$facts | list<Nullability> |
Returns
Test cases 1
Called from 2
Calls 1
- class-const Nullability::NotNull() line 264
public function coalesce(list<Nullability> $facts): NullabilityCombines NULL facts when the result is NULL only if every operand is.
Parameters
$facts | list<Nullability> |
Returns
Test cases 1
Called from 1
Calls 4
- function-call
in_arrayline 279 - class-const Nullability::NotNull() line 279
- class-const Nullability::Dependent() line 283
- class-const Nullability::Nullable() line 283
Private surface 1§
Implementation details, listed for orientation only.
private const FIXED = ['I' => \SqlSemantics\Platform\MySql\Rules\Call\TypeClass::Integer, 'U' => \Sql…Test cases 13§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 13
ResultTypingTest::testCoalesceIsNullOnlyWhenEveryOperandCanBecallsResultTypingTest::testDateArithmeticFollowsTheDateAndTheUnitcallsResultTypingTest::testFactCombinesTheTypeAndTheNullRulecallsResultTypingTest::testFactRejectsAMalformedCodecallsResultTypingTest::testNullabilityAppliesTheNullRulescallsResultTypingTest::testNullabilityRejectsAnUnknownRulecallsResultTypingTest::testNumbersAnswersTheNumericClassesOfAnArgumentcallsResultTypingTest::testNumericConvertsArgumentsToNumberscallsResultTypingTest::testPropagateIsNullWhenAnOperandCanBecallsResultTypingTest::testStringFollowsTheCharacterSetOfTheArgumentscallsResultTypingTest::testTemporalKeepsATimeOrADatetimecallsResultTypingTest::testTypeAnswersFixedAndDerivedTypescallsResultTypingTest::testTypeRejectsAnUnknownCodecalls
Relations§
Instantiated in 11
- new SqlSemantics\Platform\MySql\Rules\Call\RoutineCalls::result() packages/sql-semantics-mysql/src/Rules/Call/RoutineCalls.php:63
- new SqlSemantics\Platform\MySql\Statement\Call\Aggregate\GroupConcat::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Aggregate/GroupConcat.php:103
- new SqlSemantics\Platform\MySql\Statement\Call\Extract::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Extract.php:48
- new SqlSemantics\Platform\MySql\Statement\Call\KeywordCall::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/KeywordCall.php:71
- new SqlSemantics\Platform\MySql\Statement\Call\Position::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Position.php:53
- new SqlSemantics\Platform\MySql\Statement\Call\Temporal\DateArithmetic::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Temporal/DateArithmetic.php:57
- new SqlSemantics\Platform\MySql\Statement\Call\Temporal\GetFormat::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Temporal/GetFormat.php:47
- new SqlSemantics\Platform\MySql\Statement\Call\Temporal\TimestampCall::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Temporal/TimestampCall.php:59
- new SqlSemantics\Platform\MySql\Statement\Call\Trim::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Trim.php:56
- new SqlSemantics\Platform\MySql\Statement\Call\Weight\WeightString::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Weight/WeightString.php:71
- new SqlSemantics\Platform\MySql\Statement\Call\Weight\WeightStringParameters::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Weight/WeightStringParameters.php:51
Method calls 13
- method-call SqlSemantics\Platform\MySql\Rules\Call\RoutineCalls::result() packages/sql-semantics-mysql/src/Rules/Call/RoutineCalls.php:63
- method-call SqlSemantics\Platform\MySql\Statement\Call\Aggregate\GroupConcat::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Aggregate/GroupConcat.php:103
- method-call SqlSemantics\Platform\MySql\Statement\Call\Extract::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Extract.php:48
- method-call SqlSemantics\Platform\MySql\Statement\Call\KeywordCall::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/KeywordCall.php:73
- method-call SqlSemantics\Platform\MySql\Statement\Call\KeywordCall::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/KeywordCall.php:73
- method-call SqlSemantics\Platform\MySql\Statement\Call\KeywordCall::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/KeywordCall.php:76
- method-call SqlSemantics\Platform\MySql\Statement\Call\Position::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Position.php:53
- method-call SqlSemantics\Platform\MySql\Statement\Call\Temporal\DateArithmetic::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Temporal/DateArithmetic.php:57
- method-call SqlSemantics\Platform\MySql\Statement\Call\Temporal\GetFormat::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Temporal/GetFormat.php:47
- method-call SqlSemantics\Platform\MySql\Statement\Call\Temporal\TimestampCall::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Temporal/TimestampCall.php:59
- method-call SqlSemantics\Platform\MySql\Statement\Call\Trim::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Trim.php:56
- method-call SqlSemantics\Platform\MySql\Statement\Call\Weight\WeightString::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Weight/WeightString.php:71
- method-call SqlSemantics\Platform\MySql\Statement\Call\Weight\WeightStringParameters::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Weight/WeightStringParameters.php:51