[ https://issues.apache.org/jira/browse/IMPALA-10086?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17764280#comment-17764280 ]
ASF subversion and git services commented on IMPALA-10086: ---------------------------------------------------------- Commit 9f05cf79fa385ee6a5245ec7cb9ec1b9302c543d in impala's branch refs/heads/master from Michael Smith [ https://gitbox.apache.org/repos/asf?p=impala.git;h=9f05cf79f ] IMPALA-10086: Implicit cast comparing char and varchar Until IMPALA-7368, Impala allowed comparing char and varchar slots as in select * from functional.chars_tiny where cs = vc; IMPALA-7368 added DATE type support, and as part of that changed function call resolution to use a fit function based on the number of arguments that match the call types. Previously the comparison above would take the first matching function, which happened to be equality between STRING and STRING; CHAR and VARCHAR can both be implicitly cast to STRING, so this function worked. With the new function resolution, the best fit is equality between VARCHAR and VARCHAR, however implicit casting to VARCHAR(*) from CHAR wasn't allowed. The behavior before IMPALA-7368 was somewhat accidental; it depended on the order that builtin EQ functions are added via BinaryPredicate.initBuiltins -> Type.getSupportedTypes. Supported types happened to be ordered with STRING preceding VARCHAR and CHAR. The fit function makes sense and changing its behavior may have other consequences; it also makes sense that CHAR should be castable to VARCHAR. This change allows implicit cast between matching types. Functionally it only changes how we handle char/varchar comparison with wildcard char/varchar, because decimals are handled before checking for matching types and other type matching is the same as equals. It now allows casting to a compatible type when it is a char or varchar and the target type is a wildcard version of the same. Does not attempt to address differences from CHAR padding (IMPALA-1652). Testing: - Adds tests covering cast comparison and other implicit conversions. - Passed exhaustive test run. Change-Id: Ib89d0a391bc8f2152ecd9151c8872a01ba19c436 Reviewed-on: http://gerrit.cloudera.org:8080/20425 Reviewed-by: Peter Rozsa <pro...@cloudera.com> Reviewed-by: Daniel Becker <daniel.bec...@cloudera.com> Tested-by: Impala Public Jenkins <impala-public-jenk...@cloudera.com> > SqlCastException when comparing char with varchar > ------------------------------------------------- > > Key: IMPALA-10086 > URL: https://issues.apache.org/jira/browse/IMPALA-10086 > Project: IMPALA > Issue Type: Bug > Components: Frontend > Affects Versions: Impala 4.0.0, Impala 3.3.0 > Reporter: Tim Armstrong > Assignee: Michael Smith > Priority: Critical > Labels: newbie, ramp-up > Fix For: Impala 4.3.0 > > > {noformat} > [localhost:21000] default> select 'expected 2',count(*) from ax where cast(t > as string) = cast('a ' as varchar(10)); > +--------------+----------+ > | 'expected 2' | count(*) | > +--------------+----------+ > | expected 2 | 2 | > +--------------+----------+ > Fetched 1 row(s) in 0.44s > [localhost:21000] default> create table chartbl (c char(10)); > +-------------------------+ > | summary | > +-------------------------+ > | Table has been created. | > +-------------------------+ > Fetched 1 row(s) in 0.23s > [localhost:21000] default> select * from chartbl where c = cast('test' as > varchar(10)); > ERROR: SqlCastException: targetType=VARCHAR(*) type=VARCHAR(10) > {noformat} > Also using the functional dataset: > {noformat} > [localhost:21000] functional> select * from chars_tiny where cs = vc; > ERROR: SqlCastException: targetType=VARCHAR(*) type=VARCHAR(5) > {noformat} -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-all-unsubscr...@impala.apache.org For additional commands, e-mail: issues-all-h...@impala.apache.org