- 
                Notifications
    
You must be signed in to change notification settings  - Fork 5.5k
 
Expression Type Inference
        Wenlei Xie edited this page Feb 17, 2020 
        ·
        1 revision
      
    In Presto, expression type inference is done recursively by post-order traversing over the expression tree. Consider the following expression
foo(x) + bar(y, z)where x is with type array(double), y is with type integer, and z is with type array(integer). The type resolution is demonstrated as follows:
- 
Xis visited and decided with typeARRAY(DOUBLE) - 
foois visited, and by searching the functions with namefooand input types,foo: ARRAY(T) -> Tis decided as the best match. Thusfoo(x)is decided with typeDOUBLE. - 
Yis visited and decided with typeINTEGER - 
Zis visited and decided with typeARRAY(INTEGER) - 
baris visited, and after searching the functions with namebarwith input types,bar: (T, ARRAY(T)) -> Tis decided as the best match. Thusbar(y, z)is decided with typeINTEGER. - 
+is visited, and after searching functions with name+with input types,+: (DOUBLE, DOUBLE) -> DOUBLEis decided as the best match. 
This logic procedure is reflected in part ExpressionAnalyzer#Vistor#visitFunctionCall before lambda is implemented. The actual implementation contains many other details.