Uploaded image for project: 'Apache HAWQ'
  1. Apache HAWQ
  2. HAWQ-815

KeyError while compiling PLPython function due to deletion of non-existent record from Python global dict

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Resolved
    • 2.0.0.0-incubating
    • 2.0.0.0-incubating
    • Query Execution
    • None

    Description

      It raise KeyError while compiling PLPython function due to deletion of non-existent record from Python global dict. Below are two example to reproduce the issue:

      Example 1:

      -- 1) prepare schema and data
      CREATE LANGUAGE plpythonu;
      
      CREATE TABLE gp_single_row(a int) DISTRIBUTED BY (a);
      INSERT INTO gp_single_row VALUES (1);
      
      CREATE OR REPLACE FUNCTION test_return_table(s TEXT)
      RETURNS TABLE(first TEXT, second INT4)
      AS $$
         exec('y = ' + s)
         return y
      $$ LANGUAGE plpythonu;
      
      SELECT (test_return_table('[]')).*;
      SELECT (test_return_table('[]')).*
      FROM gp_single_row;
      
      -- 2) Actual output
      SELECT (test_return_table('[]')).*;
       first | second
      -------+--------
      (0 rows)
      
      SELECT (test_return_table('[]')).*
      FROM gp_single_row;
      ERROR:  could not compile PL/Python function "test_return_table" (plpython.c:4651)  (seg5 test1:31100 pid=36826) (dispatcher.c:1801)
      DETAIL:  KeyError: 's'
      
      -- 3) Expected output
      SELECT (test_return_table('[]')).*;
       first | second
      -------+--------
      (0 rows)
      
      SELECT (test_return_table('[]')).*
      FROM gp_single_row;
       first | second
      -------+--------
      (0 rows)
      

      Example 2:

      -- 1) prepare schema and data
      CREATE LANGUAGE plpythonu;
      
      CREATE OR REPLACE FUNCTION func1(var_cause_bug int4[])
      RETURNS SETOF INT4 AS $$
      for el in var_cause_bug:
          yield el
      $$ LANGUAGE plpythonu;
      
      CREATE OR REPLACE FUNCTION func2()
      RETURNS INT4 AS $$
      return 1
      $$ LANGUAGE plpythonu;
      
      SELECT func1(ARRAY[1,2,3]), func1(ARRAY[1,2,3]);
      SELECT func2();
      
      -- 2) Actual output
      SELECT func1(ARRAY[1,2,3]), func1(ARRAY[1,2,3]);
       func1 | func1 
      -------+-------
           1 |     1
           2 |     2
           3 |     3
      (3 rows)
      
      SELECT func2();
      ERROR:  could not compile PL/Python function "func2" (plpython.c:4648)
      DETAIL:  KeyError: 'var_cause_bug'
      
      -- 3) Expected output
      SELECT func1(ARRAY[1,2,3]), func1(ARRAY[1,2,3]);
       func1 | func1
      -------+-------
           1 |     1
           2 |     2
           3 |     3
      (3 rows)
      
      SELECT func2();
       func2
      -------
           1
      (1 row)
      

      Attachments

        Issue Links

          Activity

            People

              huor Ruilong Huo
              huor Ruilong Huo
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: