Uploaded image for project: 'Teiid'
  1. Teiid
  2. TEIID-5535

CTE: Inconsistent Error Message when SELECTing a View Instead of its Definition

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Critical
    • None
    • 11.1
    • Query Engine
    • None
    • Hide

      1. Create several empty tables based on the code below in postgreSQL (in my case I created them in "test_dwh" database):

      CREATE TABLE public.tab1
      (
        name character varying(4000)
      );
      CREATE TABLE public.tab2
      (
        course_id integer
      );
      CREATE TABLE public.tab3
      (
        course_id bigint
      );
      

      2. Add postgresql (in my example I use "test_dwh" database) database configurations in standalone-teiid.xml:

                      <datasource jndi-name="java:/test_dwh_pg" pool-name="test_dwh_pg" enabled="true" use-java-context="true">
                          <connection-url>jdbc:postgresql://localhost:5432/test_dwh?charSet=utf8</connection-url>
                          <driver-class>org.postgresql.Driver</driver-class>
                          <driver>org.postgresql</driver>
                          <pool>
                              <min-pool-size>2</min-pool-size>
                              <max-pool-size>70</max-pool-size>
                              <prefill>false</prefill>
                              <use-strict-min>false</use-strict-min>
                              <flush-strategy>FailingConnectionOnly</flush-strategy>
                          </pool>
                          <security>
                              <user-name>postgres</user-name>
                              <password>xxxxxx</password>
                          </security>
                          <validation>
                              <check-valid-connection-sql>select 0</check-valid-connection-sql>
                          </validation>
                          <timeout>
                              <blocking-timeout-millis>120000</blocking-timeout-millis>
                              <idle-timeout-minutes>5</idle-timeout-minutes>
                          </timeout>
                      </datasource>
      

      3. Add in test-vdb.xml java:/test_dwh_pg configured in previous step as data source:

          <model name="dwh">
              <property name="importer.useFullSchemaName" value="false"/>
              <property name="importer.tableTypes" value="TABLE,VIEW"/>
              <property name="importer.importKeys" value="false"/>
              <source name="test_dwh_pg" translator-name="myPg" connection-jndi-name="java:/test_dwh_pg"/>
          </model>
      
          <translator name="myPg" type="postgresql">
              <property name="SupportsNativeQueries" value="true"/>
          </translator>
      

      4. Add in test-vdb.xml the virtual "instructor_statement_2_3" view:

      <model visible = "true" type = "VIRTUAL" name = "views">
              <metadata type = "DDL"><![CDATA[
                create view instructor_statement_2_3 as
      with base_data as (
          select
              instructor_payment.course_id
          from dwh.tab3 as instructor_payment
      )
          ,adjustments as (
          select
              course_id
          from dwh.tab2
      )
          ,union_data as (
          select
              course_id
          from base_data      
          union
          select
             course_id
          from base_data         
          union
          select
              course_id
          from adjustments    
      )
          ,line_items as (
          select
               dim_playlist.name as playlist_name
          from union_data
          left join dwh.tab1 as dim_playlist on true
      )
          ,sub_totals as (
          select
              playlist_name
          from line_items
      )
      select
               line_items.playlist_name      
      from line_items
      union
      select
               sub_totals.playlist_name
      from sub_totals
              ]]>
              </metadata>
          </model>
      

      5. Run the following query:

      select * from views.instructor_statement_2_3 ;;
      

      which will fail with the following stack trace (but if I run the query second time it will work):

      Unable to find source-code formatter for language: noformat. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      2018-11-08 17:45:35,858 WARN  [org.teiid.CONNECTOR] (Worker1_QueryProcessorQueue6) HBMErVHDTEsV Connector worker process failed for atomic-request=HBMErVHDTEsV.0.2.0: org.teiid.trans
      lator.jdbc.JDBCExecutionException: 0 TEIID11008:TEIID11004 Error executing statement(s): [Prepared Values: [] SQL: WITH base_data (course_id) AS (SELECT NULL FROM "public"."tab3" AS
      g_0), line_items (playlist_name) AS (SELECT g_3."name" FROM (SELECT g_2.course_id AS c_0 FROM base_data AS g_2 UNION SELECT g_1.course_id AS c_0 FROM base_data AS g_1 UNION SELECT ca
      st(g_0."course_id" AS bigint) AS c_0 FROM "public"."tab2" AS g_0) AS v_0 LEFT OUTER JOIN "public"."tab1" AS g_3 ON 1 = 1) SELECT g_1.playlist_name AS c_0 FROM line_items AS g_1 UNION
       SELECT g_0.playlist_name AS c_0 FROM line_items AS g_0 LIMIT 100]
              at org.teiid.translator.jdbc.JDBCQueryExecution.execute(JDBCQueryExecution.java:127)
              at org.teiid.dqp.internal.datamgr.ConnectorWorkItem.execute(ConnectorWorkItem.java:382)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:498)
              at org.teiid.dqp.internal.datamgr.ConnectorManager$1.invoke(ConnectorManager.java:229)
              at com.sun.proxy.$Proxy36.execute(Unknown Source)
              at org.teiid.dqp.internal.process.DataTierTupleSource.getResults(DataTierTupleSource.java:302)
              at org.teiid.dqp.internal.process.DataTierTupleSource$1.call(DataTierTupleSource.java:108)
              at org.teiid.dqp.internal.process.DataTierTupleSource$1.call(DataTierTupleSource.java:104)
              at java.util.concurrent.FutureTask.run(FutureTask.java:266)
              at org.teiid.dqp.internal.process.FutureWork.run(FutureWork.java:61)
              at org.teiid.dqp.internal.process.DQPWorkContext.runInContext(DQPWorkContext.java:277)
              at org.teiid.dqp.internal.process.ThreadReuseExecutor$RunnableWrapper.run(ThreadReuseExecutor.java:115)
              at org.teiid.dqp.internal.process.ThreadReuseExecutor$3.run(ThreadReuseExecutor.java:206)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
              at java.lang.Thread.run(Thread.java:745)
      Caused by: org.postgresql.util.PSQLException-FEHLER: UNION-Typen text und bigint passen nicht zusammen
        Position: 248
              at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
              at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
              at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
              at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
              at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
              at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
              at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:504)
              at org.teiid.translator.jdbc.JDBCQueryExecution.execute(JDBCQueryExecution.java:119)
              ... 18 more
      

      If I run select against definition of the view it will work:

      with base_data as (
          select
              instructor_payment.course_id
          from dwh.tab3 as instructor_payment) ,adjustments as (
          select
              course_id
          from dwh.tab2
      )
          ,union_data as (
          select
              course_id
          from base_data      
          union
          select
             course_id
          from base_data         
          union
          select
              course_id
          from adjustments    
      )
          ,line_items as (
          select
               dim_playlist.name as playlist_name
          from union_data
          left join dwh.tab1 as dim_playlist on true
      )
          ,sub_totals as (
          select
              playlist_name
          from line_items
      )
      select
               line_items.playlist_name      
      from line_items
      union
      select
               sub_totals.playlist_name
      from sub_totals ;;
      
      Show
      1. Create several empty tables based on the code below in postgreSQL (in my case I created them in "test_dwh" database): CREATE TABLE public .tab1 ( name character varying (4000) ); CREATE TABLE public .tab2 ( course_id integer ); CREATE TABLE public .tab3 ( course_id bigint ); 2. Add postgresql (in my example I use "test_dwh" database) database configurations in standalone-teiid.xml: <datasource jndi-name= "java:/test_dwh_pg" pool-name= "test_dwh_pg" enabled= "true" use-java-context= "true" > <connection-url> jdbc:postgresql://localhost:5432/test_dwh?charSet=utf8 </connection-url> <driver-class> org.postgresql.Driver </driver-class> <driver> org.postgresql </driver> <pool> <min-pool-size> 2 </min-pool-size> <max-pool-size> 70 </max-pool-size> <prefill> false </prefill> <use-strict-min> false </use-strict-min> <flush-strategy> FailingConnectionOnly </flush-strategy> </pool> <security> <user-name> postgres </user-name> <password> xxxxxx </password> </security> <validation> <check-valid-connection-sql> select 0 </check-valid-connection-sql> </validation> <timeout> <blocking-timeout-millis> 120000 </blocking-timeout-millis> <idle-timeout-minutes> 5 </idle-timeout-minutes> </timeout> </datasource> 3. Add in test-vdb.xml java:/test_dwh_pg configured in previous step as data source: <model name= "dwh" > <property name= "importer.useFullSchemaName" value= "false" /> <property name= "importer.tableTypes" value= "TABLE,VIEW" /> <property name= "importer.importKeys" value= "false" /> <source name= "test_dwh_pg" translator-name= "myPg" connection-jndi-name= "java:/test_dwh_pg" /> </model> <translator name= "myPg" type= "postgresql" > <property name= "SupportsNativeQueries" value= "true" /> </translator> 4. Add in test-vdb.xml the virtual "instructor_statement_2_3" view: <model visible = "true" type = "VIRTUAL" name = "views" > <metadata type = "DDL" > <![CDATA[ create view instructor_statement_2_3 as with base_data as ( select instructor_payment.course_id from dwh.tab3 as instructor_payment ) ,adjustments as ( select course_id from dwh.tab2 ) ,union_data as ( select course_id from base_data union select course_id from base_data union select course_id from adjustments ) ,line_items as ( select dim_playlist.name as playlist_name from union_data left join dwh.tab1 as dim_playlist on true ) ,sub_totals as ( select playlist_name from line_items ) select line_items.playlist_name from line_items union select sub_totals.playlist_name from sub_totals ]]> </metadata> </model> 5. Run the following query: select * from views.instructor_statement_2_3 ;; which will fail with the following stack trace (but if I run the query second time it will work): Unable to find source-code formatter for language: noformat. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml 2018-11-08 17:45:35,858 WARN [org.teiid.CONNECTOR] (Worker1_QueryProcessorQueue6) HBMErVHDTEsV Connector worker process failed for atomic-request=HBMErVHDTEsV.0.2.0: org.teiid.trans lator.jdbc.JDBCExecutionException: 0 TEIID11008:TEIID11004 Error executing statement(s): [Prepared Values: [] SQL: WITH base_data (course_id) AS (SELECT NULL FROM " public " . "tab3" AS g_0), line_items (playlist_name) AS (SELECT g_3. "name" FROM (SELECT g_2.course_id AS c_0 FROM base_data AS g_2 UNION SELECT g_1.course_id AS c_0 FROM base_data AS g_1 UNION SELECT ca st(g_0. "course_id" AS bigint) AS c_0 FROM " public " . "tab2" AS g_0) AS v_0 LEFT OUTER JOIN " public " . "tab1" AS g_3 ON 1 = 1) SELECT g_1.playlist_name AS c_0 FROM line_items AS g_1 UNION SELECT g_0.playlist_name AS c_0 FROM line_items AS g_0 LIMIT 100] at org.teiid.translator.jdbc.JDBCQueryExecution.execute(JDBCQueryExecution.java:127) at org.teiid.dqp.internal.datamgr.ConnectorWorkItem.execute(ConnectorWorkItem.java:382) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.teiid.dqp.internal.datamgr.ConnectorManager$1.invoke(ConnectorManager.java:229) at com.sun.proxy.$Proxy36.execute(Unknown Source) at org.teiid.dqp.internal.process.DataTierTupleSource.getResults(DataTierTupleSource.java:302) at org.teiid.dqp.internal.process.DataTierTupleSource$1.call(DataTierTupleSource.java:108) at org.teiid.dqp.internal.process.DataTierTupleSource$1.call(DataTierTupleSource.java:104) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.teiid.dqp.internal.process.FutureWork.run(FutureWork.java:61) at org.teiid.dqp.internal.process.DQPWorkContext.runInContext(DQPWorkContext.java:277) at org.teiid.dqp.internal.process.ThreadReuseExecutor$RunnableWrapper.run(ThreadReuseExecutor.java:115) at org.teiid.dqp.internal.process.ThreadReuseExecutor$3.run(ThreadReuseExecutor.java:206) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang. Thread .run( Thread .java:745) Caused by: org.postgresql.util.PSQLException-FEHLER: UNION-Typen text und bigint passen nicht zusammen Position: 248 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302) at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:504) at org.teiid.translator.jdbc.JDBCQueryExecution.execute(JDBCQueryExecution.java:119) ... 18 more If I run select against definition of the view it will work: with base_data as ( select instructor_payment.course_id from dwh.tab3 as instructor_payment) ,adjustments as ( select course_id from dwh.tab2 ) ,union_data as ( select course_id from base_data union select course_id from base_data union select course_id from adjustments ) ,line_items as ( select dim_playlist. name as playlist_name from union_data left join dwh.tab1 as dim_playlist on true ) ,sub_totals as ( select playlist_name from line_items ) select line_items.playlist_name from line_items union select sub_totals.playlist_name from sub_totals ;;

    Description

      There are queries involving CTEs and set operators that can be executed and return results.
      However, creating a view based on the working queries makes these views unusable as they return an error message.

      Attachments

        Issue Links

          Activity

            People

              rhn-engineering-shawkins Steven Hawkins
              dalex005 Dmitrii Pogorelov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: