] 
Steven Hawkins commented on TEIID-5485:
---------------------------------------
No problem.  It is a pretty narrow set of circumstances, but it does have the potential to
mix up result columns, so it needed to be addressed.
 JOIN of a table and sub-query containing DISTINCT and table function
of a procedural call with arguments fails
--------------------------------------------------------------------------------------------------------------
                 Key: TEIID-5485
                 URL: 
https://issues.jboss.org/browse/TEIID-5485
             Project: Teiid
          Issue Type: Bug
          Components: Query Engine
    Affects Versions: 11.1
         Environment: teiid-11.1.0 (from 01.09.2018) on WildFly Full 11.0.0.Final (WildFly
Core 3.0.8.Final)
            Reporter: dalex dalex
            Assignee: Steven Hawkins
            Priority: Blocker
             Fix For: 11.2, 11.0.3, 10.3.5, 11.1.2
 JOIN of a table and sub-query containing DISTINCT and table function of a procedural call
with arguments, like:
 {code:sql}
 SELECT t2.i
 FROM (
 	SELECT DISTINCT 1 a, b from test_tables_pg.test_x) t1,
 	table(CALL "views.pr"(arg => t1.a)
 	) sub
 JOIN test_tables_pg.test_y t2 ON true ;;
 {code}
 fails with the following stack trace:
 {code:noformat}
 2018-09-25 17:47:15,024 ERROR [org.teiid.TRANSPORT] (NIO1)  TEIID40113 Unhandled
exception, aborting operation: org.teiid.transport.ObjectEncoder$FailedWriteException:
org.teiid.core
 .TeiidRuntimeException: TEIID20001 The modeled datatype integer for column 0 doesn't
match the runtime type "java.lang.Boolean". Please ensure that the column's
modeled datatype matc
 hes the expected data.
         at org.teiid.transport.ObjectEncoder.write(ObjectEncoder.java:132)
         at
io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738)
         at
io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:730)
         at
io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:816)
         at
io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:723)
         at io.netty.channel.ChannelDuplexHandler.write(ChannelDuplexHandler.java:106)
         at
io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738)
         at
io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:730)
         at
io.netty.channel.AbstractChannelHandlerContext.access$1900(AbstractChannelHandlerContext.java:38)
         at
io.netty.channel.AbstractChannelHandlerContext$AbstractWriteTask.write(AbstractChannelHandlerContext.java:1089)
         at
io.netty.channel.AbstractChannelHandlerContext$AbstractWriteTask.run(AbstractChannelHandlerContext.java:1078)
         at
io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
         at
io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403)
         at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:442)
         at
io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
         at java.lang.Thread.run(Thread.java:745)
 Caused by: org.teiid.core.TeiidRuntimeException: TEIID20001 The modeled datatype integer
for column 0 doesn't match the runtime type "java.lang.Boolean". Please
ensure that the colum
 n's modeled datatype matches the expected data.
         at org.teiid.client.BatchSerializer.writeBatch(BatchSerializer.java:874)
         at org.teiid.client.ResultsMessage.writeExternal(ResultsMessage.java:315)
         at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1459)
         at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1430)
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
         at org.teiid.net.socket.Message.writeExternal(Message.java:57)
         at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1459)
         at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1430)
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
         at org.teiid.transport.ObjectEncoder.write(ObjectEncoder.java:112)
         ... 15 more
 Caused by: java.lang.ClassCastException: java.lang.Boolean cannot be cast to
java.lang.Integer
         at
org.teiid.client.BatchSerializer$IntColumnSerializer.writeObject(BatchSerializer.java:559)
         at
org.teiid.client.BatchSerializer$ColumnSerializer.writeColumn(BatchSerializer.java:530)
         at org.teiid.client.BatchSerializer.writeBatch(BatchSerializer.java:863)
         ... 26 more
 {code}