]
Steven Hawkins commented on TEIID-1465:
---------------------------------------
Teiid is comparing the string form as returned by the JDBC driver. char values retrieved
this way generally do append spaces. The Teiid string comparison then treats all
characters as meaningful, which fails your equality check. There is a built-in workaround
for this situation in Teiid, which is the trimstrings setting on any JDBC translator.
trimstrings is a little heavy handed though. Any column reference to a char type in the
source sql will be wrapped in the source's equivalent of rtrim. So you're
workaround that is targeted to just your join condition may be more appropriate.
Teiid would need to add a true char type to support comparison and other methods that
ignores padding.
Join between char and varchar
-----------------------------
Key: TEIID-1465
URL:
https://issues.jboss.org/browse/TEIID-1465
Project: Teiid
Issue Type: Bug
Components: Query Engine
Affects Versions: 7.3
Environment: Teiid 7.3 deployed on Jboss AS 5.1.0 GA running on Ubuntu Server
10.04 LTS, MySQL 5.1.51 running on the same machine as JBoss, SQL Server 2000 Standard SP4
running on Windows Server 2003
Reporter: Claudio Venturini
Assignee: Steven Hawkins
Labels: char, join, varchar
Joins between char and varchar fields fail.
Suppose to have a table T1 with a field A, declared as char(10), and a table T2 with a
field B, declared as varchar(10). Suppose that the two tables have the following data.
*T1*:
||A||
|ML0001|
*T2*:
||B||
|ML0001|
When performing a INNER JOIN with the condition {{T1.A = T2.B}} the result set is empty,
even if the two record match correctly.
This happens when the two base tables refer to two different sources, because if they are
in the same source Teiid pushes the join to the source, which computes it correctly.
I think the problem is in the comparison of the two strings. I have the table T1 in SQL
Server 2000, and the table T2 in MySQL 5.1.
If one asks SQL Server to convert the string to bytes, the result is
{{0x4D4C3030303120202020}}, because the string is filled with (invisible) blanks in order
to reach the limit of 10 characters. Note that if one asks for the length of that string,
SQL Server states (correctly) that it is 6 characters.
The string in MySQL is a VARCHAR(10), so its conversion to binary is {{0x4D4C30303031}}.
I think that Teiid compares the two binary strings in their entire length. That
comparison fails, and no match is found.
The problem remains even if the table T1 is placed in MySQL, and T2 in SQL Server (the
opposite situation). I also verified that the problem exists either when querying the
source models or view models built over them.
*Workaround:*
A workaround exists but it is too complex (IMHO). I haven't tested it with many
records, but I think it will slow down performances considerably.
It consists in casting the string from char to varchar, and then trimming it (with
RTRIM() and LTRIM() because SQL Server doesn't support TRIM()). So the join condition
is:
{noformat}
RTRIM(LTRIM(CAST(T1.A AS VARCHAR))) = T2.B
{noformat}
--
This message is automatically generated by JIRA.
-
For more information on JIRA, see: