paul-rogers commented on pull request #2461: URL: https://github.com/apache/drill/pull/2461#issuecomment-1047290649
@estherbuchwalter, thanks for the explanation. The function must, however, declare an output type. The other input must be cast to the correct type. For example, if the VARCHAR is to be cast to a DECIMAL, so must the other argument, and the output is DECIMAL. On the other hand, if we infer the type from the numeric type, then 10 + "10.1" will produce 20, not 20.1. SQL is a statically typed language: every row must produce the output type. Drill does defer the type decision to runtime, but the type decision becomes frozen on the first row. To be clear, what is the output type for: VARCHAR + INT --> ? VARCHAR + DOUBLE --> ? VARCHAR + DECIMAL -> ? Since the VARCHAR can be anything, the safest result is if the output is always VARDECIMAL (unlimited precision) or DOUBLE (largest range of values, with some truncation). For any other output type, we can invent an input that will make the output type invalid. Again, this is why SQL normally requires: (CAST col AS INT) + 10 --> BIGINT So that the user declares that the VARCHAR "col" column is converable to INT, and thus the normal INT addition type promotion rules apply. Or, have you come up with some trick to work around this issue? -- 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]
