robll-v1 opened a new pull request, #68814:
URL: https://github.com/apache/doris/pull/68814

   ### What problem does this PR solve?
   
   Issue Number: #48203 (umbrella tracking list "Support All SQL Functions in 
Other SQL System" — please keep it open)
   
   Problem Summary:
   
   Implements the Trino/Presto-compatible `typeof(expr)` scalar function, which 
returns the name of the static type of its argument as a string, e.g. 
`integer`, `bigint`, `varchar(10)`, `char(4)`, `decimal(5,1)`, 
`array(integer)`, `map(varchar, array(decimal(12,3)))`, `row("x" integer, "y" 
varchar(10))`, and `unknown` for NULL.
   
   - **BE**: new `be/src/exprs/function/function_type_of.cpp` maps Doris types 
to Trino-style type names (char/varchar lengths, nested array/map/struct) and 
the function is registered in `be/src/exprs/function/simple_function_factory.h`.
   - **FE**: new `TypeOf` scalar expression, registration in 
`BuiltinScalarFunctions`, `ScalarFunctionVisitor.visitTypeOf`, and constant 
folding in `FoldConstantRuleOnFE`, so constant arguments are folded on the FE 
and both paths return the same names.
   - **Tests**:
     - BE unit test `FunctionTypeOfTest` (6 cases: registration/const-string, 
primitive + nullable types, nested + special types, NULL literals/constants, 
zero-row blocks, declared-vs-storage type);
     - FE unit tests `TypeOfTest` and `FoldConstantTest#testTypeOfFold`;
     - `query_p0` regression suite `test_typeof`, which runs every case twice — 
with `debug_skip_fold_constant` false and true — so the FE-fold and 
BE-execution paths are both covered. The `.out` file is generated by the test 
framework (not hand-written).
   
   Verified locally on macOS (arm64, ASAN build): `run-be-ut.sh --run 
--filter=FunctionTypeOfTest.*` → 6/6 pass; `run-fe-ut.sh --run` for the two FE 
classes → pass; `run-regression-test.sh -s test_typeof` → green; `typeof` 
checked against a local single-node cluster on literals (FE folding) and table 
columns (BE execution).
   
   Naming rationale: the type names follow Trino 
(`integer`/`bigint`/`varchar(n)`/`array(...)`/`row(...)`/`unknown`) so results 
line up with the Presto/Trino dialect-compatibility corpus. Note that Doris 
integer literals keep their Doris type (`typeof(1)` → `tinyint`), so the Trino 
dialect-compat SQL file for this function is intentionally left untouched; it 
can be enabled separately once verified against a live Presto.
   
   ### Release note
   
   Add the `typeof()` scalar function (Trino/Presto compatible): returns the 
type name of its argument.
   
   ### Check List (For Author)
   
   - Test
       - [x] Regression test
       - [x] Unit Test
       - [ ] Manual test (add detailed scripts or steps below)
       - [ ] No need to test or manual test. Explain why:
           - [ ] This is a refactor/code format and no logic has been changed.
           - [ ] Previous test can cover this change.
           - [ ] No code files have been changed.
           - [ ] Other reason <!-- Add your reason?  -->
   - Behavior changed:
       - [x] No. <!-- new function only -->
       - [ ] Yes. <!-- Explain the behavior change -->
   - Does this need documentation?
       - [ ] No.
       - [x] Yes. <!-- the function list on the Doris website should add 
typeof(); happy to open a doris-website PR if wanted -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to