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

Aggregation is performed incorrectly for JOIN queries

    XMLWordPrintable

Details

    • Hide

      1. In postgresql create the tbl_1 table by the following script:

      CREATE TABLE tbl_1
      (
        a integer,
        b bigdecimal
      );
       
      INSERT INTO tbl_1(a, b) VALUES (1, 1);
      INSERT INTO tbl_1(a, b) VALUES (1, 2);
      INSERT INTO tbl_1(a, b) VALUES (1, 2);
      INSERT INTO tbl_1(a, b) VALUES (1, 3);
      

      2. Add postgresql database configuration in standalone-teiid.xml

      <datasource jndi-name="java:/test_pg" pool-name="test_pg" enabled="true" use-java-context="true">
                          <connection-url>jdbc:postgresql://localhost:5432/test?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_pg configured in previous step as datasource:

      <model name="test_pg">
              <property name="importer.useFullSchemaName" value="false"/>
      	<property name="importer.tableTypes" value="TABLE,VIEW"/>
      	<property name="importer.importKeys" value="false"/>
              <source name="test_pg" translator-name="myPg" connection-jndi-name="java:/test_pg"/>
          </model>
      

      4. Configure in test-vdb.xml the following virtual views:

      <model visible = "true" type = "VIRTUAL" name = "views">
              <metadata type = "DDL"><![CDATA[
                CREATE virtual view v1 as select * from test_pg.tbl_1;
                CREATE virtual view v2 as select 1 as a, 1 as b
              ]]>
              </metadata>
      </model>
      

      5. Configure in test-vdb.xml the following virtual procedure:

      <model visible = "true" type = "VIRTUAL" name = "procs">
              <metadata type = "DDL"><![CDATA[
                create procedure pr() returns (a integer, b integer) as 
                begin
      	     select 1, 1;
                end        
              ]]>
              </metadata>
      </model>
      

      6. Run test queries mentioned in description field:

      --Run test queries and check result, which should be:
      --2
      --1
      --1
      -- result is correct
      select count(v2.b) from views.v1 join views.v2 on true group by v1.b;
      
      -- result is correct
      select count(v2.b) from views.v1 left join views.v2 on true group by v1.b;
      
      -- result is incorrect
      select count(v2.b) from views.v1 right join views.v2 on true group by v1.b;
      
      -- result is incorrect
      select count(v2.b) from views.v1 join (call procs.pr()) v2 on true group by v1.b;
      
      -- result is incorrect
      select count(v2.b) from views.v1 left join (call procs.pr()) v2 on true group by v1.b;
      
      -- result is incorrect
      select count(v2.b) from views.v1 right join (call procs.pr()) v2 on true group by v1.b;
      
      Show
      1. In postgresql create the tbl_1 table by the following script: CREATE TABLE tbl_1 ( a integer , b bigdecimal ); INSERT INTO tbl_1( a , b) VALUES (1, 1); INSERT INTO tbl_1( a , b) VALUES (1, 2); INSERT INTO tbl_1( a , b) VALUES (1, 2); INSERT INTO tbl_1( a , b) VALUES (1, 3); 2. Add postgresql database configuration in standalone-teiid.xml <datasource jndi-name= "java:/test_pg" pool-name= "test_pg" enabled= "true" use-java-context= "true" > <connection-url> jdbc:postgresql://localhost:5432/test?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_pg configured in previous step as datasource: <model name= "test_pg" > <property name= "importer.useFullSchemaName" value= "false" /> <property name= "importer.tableTypes" value= "TABLE,VIEW" /> <property name= "importer.importKeys" value= "false" /> <source name= "test_pg" translator-name= "myPg" connection-jndi-name= "java:/test_pg" /> </model> 4. Configure in test-vdb.xml the following virtual views: <model visible = "true" type = "VIRTUAL" name = "views" > <metadata type = "DDL" > <![CDATA[ CREATE virtual view v1 as select * from test_pg.tbl_1; CREATE virtual view v2 as select 1 as a, 1 as b ]]> </metadata> </model> 5. Configure in test-vdb.xml the following virtual procedure: <model visible = "true" type = "VIRTUAL" name = "procs" > <metadata type = "DDL" > <![CDATA[ create procedure pr() returns (a integer, b integer) as begin select 1, 1; end ]]> </metadata> </model> 6. Run test queries mentioned in description field: --Run test queries and check result , which should be: --2 --1 --1 -- result is correct select count (v2.b) from views.v1 join views.v2 on true group by v1.b; -- result is correct select count (v2.b) from views.v1 left join views.v2 on true group by v1.b; -- result is incorrect select count (v2.b) from views.v1 right join views.v2 on true group by v1.b; -- result is incorrect select count (v2.b) from views.v1 join ( call procs.pr()) v2 on true group by v1.b; -- result is incorrect select count (v2.b) from views.v1 left join ( call procs.pr()) v2 on true group by v1.b; -- result is incorrect select count (v2.b) from views.v1 right join ( call procs.pr()) v2 on true group by v1.b;

    Description

      Aggregation is performed incorrectly for JOIN queries, like this

      select count(v2.b) from views.v1 right join views.v2 on true group by v1.b;
      
      select count(v2.b) from views.v1 join (call procs.pr()) v2 on true group by v1.b;
      
      select count(v2.b) from views.v1 left join (call procs.pr()) v2 on true group by v1.b;
      
      select count(v2.b) from views.v1 right join (call procs.pr()) v2 on true group by v1.b;
      

      showing as a result:

      1
      1
      1
      

      though these ones work correctly:

      select count(v2.b) from views.v1 join views.v2 on true group by v1.b;
      
      select count(v2.b) from views.v1 left join views.v2 on true group by v1.b;
      

      showing

      1
      1
      2
      

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: