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

RAND function gives same results in view

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Critical
    • 10.1, 10.0.1, 9.3.6
    • 9.3.4
    • Query Engine
    • None
    • Hide

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

      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
      registerFunctionModifier(SourceSystemFunctions.RAND, new AliasModifier("random")); //$NON-NLS-1$
      

      b) add in getSupportedFunctions() method

      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
      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&gt;org.postgresql.Driver</driver-class&gt;
                          <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 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 registerFunctionModifier(SourceSystemFunctions.RAND, new AliasModifier( "random" )); //$NON-NLS-1$ b) add in getSupportedFunctions() method 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 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& gt;org.postgresql.Driver</driver- class& gt; <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.

      Attachments

        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: