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

RAND function gives same results in view

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Critical
    • Resolution: Done
    • Affects Version/s: 9.3.4
    • Fix Version/s: 10.1, 10.0.1, 9.3.6
    • Component/s: Query Engine
    • Labels:
      None
    • Environment:

      teiid-9.3.4 on WildFly Full 10.0.0.Final (WildFly Core 2.0.10.Final)

    • Steps to Reproduce:
      Hide

      1. Change (or patch) PostgreSQLExecutionFactory adding the following lines:
      a) add in start() method

      registerFunctionModifier(SourceSystemFunctions.RAND, new AliasModifier("random")); //$NON-NLS-1$
      

      b) add in getSupportedFunctions() method

      supportedFunctions.add(SourceSystemFunctions.RAND);
      

      2. In postgresql create the test_a table by the following script:

      CREATE TABLE public.test_a
      (
        a integer,
        b integer
      );
      INSERT INTO public.test_a(a, b) VALUES (1, 1);
      INSERT INTO public.test_a(a, b) VALUES (1, 2);
      INSERT INTO public.test_a(a, b) VALUES (2, 1);
      INSERT INTO public.test_a(a, b) VALUES (2, 2);
      INSERT INTO public.test_a(a, b) VALUES (3, 2);
      INSERT INTO public.test_a(a, b) VALUES (3, 10);
      

      3. 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>
      

      4. 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>
      

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

      <model visible = "true" type = "VIRTUAL" name = "views">
              <metadata type = "DDL"><![CDATA[
                CREATE virtual view v1 as select rand() from test_pg.test_a
              ]]>
              </metadata>
          </model>
      

      6. Run the following queries and compare them:

      select rand() from test_pg.test_a;;
      

      and

      select * from views.v1;;
      

      the first one will return 6 different values but the second one will return 6 absolutely identical values.

      Show
      1. Change (or patch) PostgreSQLExecutionFactory adding the following lines: a) add in start() method registerFunctionModifier(SourceSystemFunctions.RAND, new AliasModifier("random")); //$NON-NLS-1$ b) add in getSupportedFunctions() method supportedFunctions.add(SourceSystemFunctions.RAND); 2. In postgresql create the test_a table by the following script: CREATE TABLE public .test_a ( a integer , b integer ); INSERT INTO public .test_a(a, b) VALUES (1, 1); INSERT INTO public .test_a(a, b) VALUES (1, 2); INSERT INTO public .test_a(a, b) VALUES (2, 1); INSERT INTO public .test_a(a, b) VALUES (2, 2); INSERT INTO public .test_a(a, b) VALUES (3, 2); INSERT INTO public .test_a(a, b) VALUES (3, 10); 3. 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> 4. 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> 5. Configure in the test-vdb.xml the following virtual view: < model visible = "true" type = "VIRTUAL" name = "views" > < metadata type = "DDL" > <![CDATA[ CREATE virtual view v1 as select rand() from test_pg.test_a ]]> </ metadata > </ model > 6. Run the following queries and compare them: select rand() from test_pg.test_a;; and select * from views.v1;; the first one will return 6 different values but the second one will return 6 absolutely identical values.

      Description

      When using patched PostgreSQLExecutionFactory class to push down RAND function it starts to give the same values in a view. I wanted to push down RAND function in PostgreSQL for a while and noticed the bug related to identical values when using RAND function through a select in a view.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                shawkins Steven Hawkins
                Reporter:
                dalex005 dalex dalex
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: