hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [13/14] incubator-hawq git commit: HAWQ-894. Add feature test for polymorphism with new test framework
Date Tue, 19 Jul 2016 02:50:38 GMT
HAWQ-894. Add feature test for polymorphism with new test framework


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/0081706d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/0081706d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/0081706d

Branch: refs/heads/2.0.0.0-incubating
Commit: 0081706dcf35c81e5365929e8089f861fd37cd6c
Parents: e65d463
Author: YI JIN <yjin@pivotal.io>
Authored: Thu Jul 14 14:55:30 2016 +1000
Committer: rlei <rlei@pivotal.io>
Committed: Tue Jul 19 10:49:42 2016 +0800

----------------------------------------------------------------------
 src/test/feature/lib/sql_util.cpp               |   6 +
 src/test/feature/lib/sql_util.h                 |   7 +
 .../feature/query/ans/polimorphism-test1.ans    |  56 ++
 .../feature/query/sql/polimorphism-test1.sql    |  48 ++
 src/test/feature/query/test_polymorphism.cpp    | 497 +++++++++++++++++
 src/test/regress/expected/polymorphism.out      | 544 -------------------
 src/test/regress/known_good_schedule            |   1 -
 src/test/regress/sql/polymorphism.sql           | 377 -------------
 8 files changed, 614 insertions(+), 922 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0081706d/src/test/feature/lib/sql_util.cpp
----------------------------------------------------------------------
diff --git a/src/test/feature/lib/sql_util.cpp b/src/test/feature/lib/sql_util.cpp
index ea0c805..35e8ffe 100644
--- a/src/test/feature/lib/sql_util.cpp
+++ b/src/test/feature/lib/sql_util.cpp
@@ -62,6 +62,12 @@ string SQLUtility::execute(const string &sql, bool check) {
   return conn.get()->getLastResult();
 }
 
+void SQLUtility::executeExpectErrorMsgStartWith(const std::string &sql,
+                                                const std::string &errmsg) {
+  std::string errout = execute(sql, false);
+  EXPECT_STREQ(errmsg.c_str(), errout.substr(0, errmsg.size()).c_str());
+}
+
 void SQLUtility::executeIgnore(const string &sql) {
   conn->runSQLCommand("SET SEARCH_PATH=" + schemaName + ";" + sql);
   EXPECT_NE(conn.get(), nullptr);

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0081706d/src/test/feature/lib/sql_util.h
----------------------------------------------------------------------
diff --git a/src/test/feature/lib/sql_util.h b/src/test/feature/lib/sql_util.h
index 768dfc9..ea75aa3 100644
--- a/src/test/feature/lib/sql_util.h
+++ b/src/test/feature/lib/sql_util.h
@@ -70,6 +70,13 @@ class SQLUtility {
   // Get GUC value
   std::string getGUCValue(const std::string &guc);
 
+  // execute expect error message
+  // @param sql the given sql command
+  // @param errmsg the expected sql error message
+  // @return void
+  void executeExpectErrorMsgStartWith(const std::string &sql, const std::string &errmsg);
+
+
  private:
   std::unique_ptr<hawq::test::PSQL> getConnection();
   const std::string generateSQLFile(const std::string &sqlFile);

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0081706d/src/test/feature/query/ans/polimorphism-test1.ans
----------------------------------------------------------------------
diff --git a/src/test/feature/query/ans/polimorphism-test1.ans b/src/test/feature/query/ans/polimorphism-test1.ans
new file mode 100644
index 0000000..ff2fd93
--- /dev/null
+++ b/src/test/feature/query/ans/polimorphism-test1.ans
@@ -0,0 +1,56 @@
+-- Legend:
+-----------
+-- A = type is ANY
+-- P = type is polymorphic
+-- N = type is non-polymorphic
+-- B = aggregate base type
+-- S = aggregate state type
+-- R = aggregate return type
+-- 1 = arg1 of a function
+-- 2 = arg2 of a function
+-- ag = aggregate
+-- tf = trans (state) function
+-- ff = final function
+-- rt = return type of a function
+-- -> = implies
+-- => = allowed
+-- !> = not allowed
+-- E  = exists
+-- NE = not-exists
+--
+-- Possible states:
+-- ----------------
+-- B = (A || P || N)
+--   when (B = A) -> (tf2 = NE)
+-- S = (P || N)
+-- ff = (E || NE)
+-- tf1 = (P || N)
+-- tf2 = (NE || P || N)
+-- R = (P || N)
+-- polymorphic single arg transfn
+CREATE FUNCTION stfp(anyarray) RETURNS anyarray AS 'select $1' LANGUAGE SQL;
+CREATE FUNCTION
+-- non-polymorphic single arg transfn
+CREATE FUNCTION stfnp(int[]) RETURNS int[] AS 'select $1' LANGUAGE SQL;
+CREATE FUNCTION
+-- dual polymorphic transfn
+CREATE FUNCTION tfp(anyarray,anyelement) RETURNS anyarray AS 'select $1 || $2' LANGUAGE SQL;
+CREATE FUNCTION
+-- dual non-polymorphic transfn
+CREATE FUNCTION tfnp(int[],int) RETURNS int[] AS 'select $1 || $2' LANGUAGE SQL;
+CREATE FUNCTION
+-- arg1 only polymorphic transfn
+CREATE FUNCTION tf1p(anyarray,int) RETURNS anyarray AS 'select $1' LANGUAGE SQL;
+CREATE FUNCTION
+-- arg2 only polymorphic transfn
+CREATE FUNCTION tf2p(int[],anyelement) RETURNS int[] AS 'select $1' LANGUAGE SQL;
+CREATE FUNCTION
+-- multi-arg polymorphic
+CREATE FUNCTION sum3(anyelement,anyelement,anyelement) RETURNS anyelement AS 'select $1+$2+$3' LANGUAGE SQL STRICT;
+CREATE FUNCTION
+-- finalfn polymorphic
+CREATE FUNCTION ffp(anyarray) RETURNS anyarray AS 'select $1' LANGUAGE SQL;
+CREATE FUNCTION
+-- finalfn non-polymorphic
+CREATE FUNCTION ffnp(int[]) RETURNS int[] AS 'select $1' LANGUAGE SQL;
+CREATE FUNCTION

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0081706d/src/test/feature/query/sql/polimorphism-test1.sql
----------------------------------------------------------------------
diff --git a/src/test/feature/query/sql/polimorphism-test1.sql b/src/test/feature/query/sql/polimorphism-test1.sql
new file mode 100644
index 0000000..5cdb507
--- /dev/null
+++ b/src/test/feature/query/sql/polimorphism-test1.sql
@@ -0,0 +1,48 @@
+-- Legend:
+-----------
+-- A = type is ANY
+-- P = type is polymorphic
+-- N = type is non-polymorphic
+-- B = aggregate base type
+-- S = aggregate state type
+-- R = aggregate return type
+-- 1 = arg1 of a function
+-- 2 = arg2 of a function
+-- ag = aggregate
+-- tf = trans (state) function
+-- ff = final function
+-- rt = return type of a function
+-- -> = implies
+-- => = allowed
+-- !> = not allowed
+-- E  = exists
+-- NE = not-exists
+--
+-- Possible states:
+-- ----------------
+-- B = (A || P || N)
+--   when (B = A) -> (tf2 = NE)
+-- S = (P || N)
+-- ff = (E || NE)
+-- tf1 = (P || N)
+-- tf2 = (NE || P || N)
+-- R = (P || N)
+
+-- polymorphic single arg transfn
+CREATE FUNCTION stfp(anyarray) RETURNS anyarray AS 'select $1' LANGUAGE SQL;
+-- non-polymorphic single arg transfn
+CREATE FUNCTION stfnp(int[]) RETURNS int[] AS 'select $1' LANGUAGE SQL;
+-- dual polymorphic transfn
+CREATE FUNCTION tfp(anyarray,anyelement) RETURNS anyarray AS 'select $1 || $2' LANGUAGE SQL;
+-- dual non-polymorphic transfn
+CREATE FUNCTION tfnp(int[],int) RETURNS int[] AS 'select $1 || $2' LANGUAGE SQL;
+-- arg1 only polymorphic transfn
+CREATE FUNCTION tf1p(anyarray,int) RETURNS anyarray AS 'select $1' LANGUAGE SQL;
+-- arg2 only polymorphic transfn
+CREATE FUNCTION tf2p(int[],anyelement) RETURNS int[] AS 'select $1' LANGUAGE SQL;
+-- multi-arg polymorphic
+CREATE FUNCTION sum3(anyelement,anyelement,anyelement) RETURNS anyelement AS 'select $1+$2+$3' LANGUAGE SQL STRICT;
+-- finalfn polymorphic
+CREATE FUNCTION ffp(anyarray) RETURNS anyarray AS 'select $1' LANGUAGE SQL;
+-- finalfn non-polymorphic
+CREATE FUNCTION ffnp(int[]) RETURNS int[] AS 'select $1' LANGUAGE SQL;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0081706d/src/test/feature/query/test_polymorphism.cpp
----------------------------------------------------------------------
diff --git a/src/test/feature/query/test_polymorphism.cpp b/src/test/feature/query/test_polymorphism.cpp
new file mode 100644
index 0000000..42d5a6a
--- /dev/null
+++ b/src/test/feature/query/test_polymorphism.cpp
@@ -0,0 +1,497 @@
+#include <pwd.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <vector>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <iostream>
+#include <string>
+
+#include "lib/sql_util.h"
+
+#include "gtest/gtest.h"
+
+class TestQueryPolymorphism : public ::testing::Test {
+ public:
+  TestQueryPolymorphism() {}
+  ~TestQueryPolymorphism() {}
+};
+
+
+TEST_F(TestQueryPolymorphism, Test1) {
+  hawq::test::SQLUtility util;
+
+  // prepare
+  util.execute("DROP AGGREGATE IF EXISTS myaggp01a(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp02a(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp03a(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp03b(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp04a(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp04b(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp05a(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp06a(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp07a(anyelement) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp08a(anyelement) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp09a(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp09b(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp10a(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp10b(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp11a(anyelement) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp11b(anyelement) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp12a(anyelement) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp12b(anyelement) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp13a(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp14a(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp15a(anyelement) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp16a(anyelement) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp17a(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp17b(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp18a(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp18b(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp19a(anyelement) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp19b(anyelement) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp20a(anyelement) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp20b(anyelement) CASCADE");
+
+  util.execute("DROP AGGREGATE IF EXISTS myaggn01a(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn01b(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn02a(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn02b(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn03a(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn04a(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn05a(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn05b(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn06a(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn06b(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn07a(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn07b(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn08a(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn08b(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn09a(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn10a(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn11a(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn12a(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn13a(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn13b(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn14a(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn14b(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn15a(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn15b(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn16a(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn16b(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn17a(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn18a(int) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn19a(*) CASCADE");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn20a(*) CASCADE");
+
+  util.execute("DROP AGGREGATE IF EXISTS mysum2(anyelement,anyelement) CASCADE");
+
+  util.execute("DROP FUNCTION IF EXISTS stfp(anyarray) CASCADE");
+  util.execute("DROP FUNCTION IF EXISTS stfnp(int[]) CASCADE");
+  util.execute("DROP FUNCTION IF EXISTS tfp(anyarray,anyelement) CASCADE");
+  util.execute("DROP FUNCTION IF EXISTS tfnp(int[],int) CASCADE");
+  util.execute("DROP FUNCTION IF EXISTS tf1p(anyarray,int) CASCADE");
+  util.execute("DROP FUNCTION IF EXISTS tf2p(int[],anyelement) CASCADE");
+  util.execute("DROP FUNCTION IF EXISTS sum3(anyelement,anyelement,anyelement) CASCADE");
+  util.execute("DROP FUNCTION IF EXISTS ffp(anyarray) CASCADE");
+  util.execute("DROP FUNCTION IF EXISTS ffnp(int[]) CASCADE");
+
+  util.execute("DROP TABLE IF EXISTS t");
+
+  // test starts here
+
+  util.execSQLFile("query/sql/polimorphism-test1.sql",
+		  	  	   "query/ans/polimorphism-test1.ans");
+
+  // Legend:
+  // -----------
+  // A = type is ANY
+  // P = type is polymorphic
+  // N = type is non-polymorphic
+  // B = aggregate base type
+  // S = aggregate state type
+  // R = aggregate return type
+  // 1 = arg1 of a function
+  // 2 = arg2 of a function
+  // ag = aggregate
+  // tf = trans (state) function
+  // ff = final function
+  // rt = return type of a function
+  // -> = implies
+  // => = allowed
+  // !> = not allowed
+  // E  = exists
+  // NE = not-exists
+  // --
+  // Possible states:
+  // ----------------
+  // B = (A || P || N)
+  //   when (B = A) -> (tf2 = NE)
+  // S = (P || N)
+  // ff = (E || NE)
+  // tf1 = (P || N)
+  // tf2 = (NE || P || N)
+  // R = (P || N)
+
+  // Try to cover all the possible states:
+  //
+  // Note: in Cases 1 & 2, we are trying to return P. Therefore, if the transfn
+  // is stfnp, tfnp, or tf2p, we must use ffp as finalfn, because stfnp, tfnp,
+  // and tf2p do not return P. Conversely, in Cases 3 & 4, we are trying to
+  // return N. Therefore, if the transfn is stfp, tfp, or tf1p, we must use ffnp
+  // as finalfn, because stfp, tfp, and tf1p do not return N.
+  //
+  //     Case1 (R = P) && (B = A)
+  //     ------------------------
+  //     S    tf1
+  //     -------
+  //     N    N
+
+  util.execute("CREATE AGGREGATE myaggp01a(*) "
+		       "(SFUNC = stfnp, STYPE = int4[], FINALFUNC = ffp, INITCOND = '{}')");
+  //     P    N
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggp02a(*) (SFUNC = stfnp, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}')",
+      "ERROR:  cannot determine transition data type");
+  //     N    P
+  util.execute("CREATE AGGREGATE myaggp03a(*) "
+		       "(SFUNC = stfp, STYPE = int4[], FINALFUNC = ffp, INITCOND = '{}')");
+  util.execute("CREATE AGGREGATE myaggp03b(*) "
+               "(SFUNC = stfp, STYPE = int4[], INITCOND = '{}')");
+
+  //     P    P
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggp04a(*) (SFUNC = stfp, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}')",
+      "ERROR:  cannot determine transition data type");
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggp04b(*) (SFUNC = stfp, STYPE = anyarray, INITCOND = '{}')",
+      "ERROR:  cannot determine transition data type");
+
+  // --    Case2 (R = P) && ((B = P) || (B = N))
+  // --    -------------------------------------
+  // --    S    tf1      B    tf2
+  // --    -----------------------
+  // --    N    N        N    N
+  util.execute("CREATE AGGREGATE myaggp05a"
+      "(BASETYPE = int, SFUNC = tfnp, STYPE = int[], FINALFUNC = ffp, INITCOND = '{}')");
+  // --    N    N        N    P
+  util.execute("CREATE AGGREGATE myaggp06a"
+      "(BASETYPE = int, SFUNC = tf2p, STYPE = int[], FINALFUNC = ffp, INITCOND = '{}')");
+  // --    N    N        P    N
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggp07a"
+      "(BASETYPE = anyelement, SFUNC = tfnp, STYPE = int[], FINALFUNC = ffp, INITCOND = '{}')",
+      "ERROR:  function tfnp(integer[], anyelement) does not exist");
+  // --    N    N        P    P
+  util.execute("CREATE AGGREGATE myaggp08a"
+               "(BASETYPE = anyelement, SFUNC = tf2p, STYPE = int[], FINALFUNC = ffp, INITCOND = '{}')");
+  // --    N    P        N    N
+  util.execute("CREATE AGGREGATE myaggp09a"
+               "(BASETYPE = int, SFUNC = tf1p, STYPE = int[], FINALFUNC = ffp, INITCOND = '{}')");
+  util.execute("CREATE AGGREGATE myaggp09b"
+               "(BASETYPE = int, SFUNC = tf1p, STYPE = int[], INITCOND = '{}')");
+  // --    N    P        N    P
+  util.execute("CREATE AGGREGATE myaggp10a"
+               "(BASETYPE = int, SFUNC = tfp, STYPE = int[], FINALFUNC = ffp, INITCOND = '{}')");
+  util.execute("CREATE AGGREGATE myaggp10b"
+               "(BASETYPE = int, SFUNC = tfp, STYPE = int[], INITCOND = '{}')");
+  // --    N    P        P    N
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggp11a"
+      "(BASETYPE = anyelement, SFUNC = tf1p, STYPE = int[], FINALFUNC = ffp, INITCOND = '{}')",
+      "ERROR:  function tf1p(integer[], anyelement) does not exist");
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggp11b"
+      "(BASETYPE = anyelement, SFUNC = tf1p, STYPE = int[], INITCOND = '{}')",
+      "ERROR:  function tf1p(integer[], anyelement) does not exist");
+  // --    N    P        P    P
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggp12a"
+      "(BASETYPE = anyelement, SFUNC = tfp, STYPE = int[], FINALFUNC = ffp, INITCOND = '{}')",
+      "ERROR:  function tfp(integer[], anyelement) does not exist");
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggp12b"
+      "(BASETYPE = anyelement, SFUNC = tfp, STYPE = int[], INITCOND = '{}')",
+      "ERROR:  function tfp(integer[], anyelement) does not exist");
+  // --    P    N        N    N
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggp13a"
+      "(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}')",
+      "ERROR:  cannot determine transition data type");
+  // --    P    N        N    P
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggp14a"
+      "(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}')",
+      "ERROR:  cannot determine transition data type");
+  // --    P    N        P    N
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggp15a"
+      "(BASETYPE = anyelement, SFUNC = tfnp, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}')",
+      "ERROR:  function tfnp(anyarray, anyelement) does not exist");
+  // --    P    N        P    P
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggp16a"
+      "(BASETYPE = anyelement, SFUNC = tf2p, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}')",
+      "ERROR:  function tf2p(anyarray, anyelement) does not exist");
+  // --    P    P        N    N
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggp17a"
+      "(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}')",
+      "ERROR:  cannot determine transition data type");
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggp17b"
+      "(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray, INITCOND = '{}')",
+      "ERROR:  cannot determine transition data type");
+  // --    P    P        N    P
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggp18a"
+      "(BASETYPE = int, SFUNC = tfp, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}')",
+      "ERROR:  cannot determine transition data type");
+
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggp18b"
+      "(BASETYPE = int, SFUNC = tfp, STYPE = anyarray, INITCOND = '{}')",
+      "ERROR:  cannot determine transition data type");
+  // --    P    P        P    N
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggp19a"
+      "(BASETYPE = anyelement, SFUNC = tf1p, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}')",
+      "ERROR:  function tf1p(anyarray, anyelement) does not exist");
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggp19b"
+      "(BASETYPE = anyelement, SFUNC = tf1p, STYPE = anyarray, INITCOND = '{}')",
+      "ERROR:  function tf1p(anyarray, anyelement) does not exist");
+  // --    P    P        P    P
+  util.execute("CREATE AGGREGATE myaggp20a"
+      "(BASETYPE = anyelement, SFUNC = tfp, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}')");
+
+  util.execute("CREATE AGGREGATE myaggp20b"
+      "(BASETYPE = anyelement, SFUNC = tfp, STYPE = anyarray, INITCOND = '{}')");
+
+  // --     Case3 (R = N) && (B = A)
+  // --     ------------------------
+  // --     S    tf1
+  // --     -------
+  // --     N    N
+  util.execute("CREATE AGGREGATE myaggn01a(*) "
+		       "(SFUNC = stfnp, STYPE = int4[], FINALFUNC = ffnp, INITCOND = '{}')");
+  util.execute("CREATE AGGREGATE myaggn01b(*) "
+		       "(SFUNC = stfnp, STYPE = int4[], INITCOND = '{}');");
+  // --     P    N
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn02a(*) "
+      "(SFUNC = stfnp, STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}')",
+      "ERROR:  cannot determine transition data type");
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn02b(*) "
+      "(SFUNC = stfnp, STYPE = anyarray, INITCOND = '{}')",
+      "ERROR:  cannot determine transition data type");
+  // --     N    P
+  util.execute("CREATE AGGREGATE myaggn03a(*) "
+		       "(SFUNC = stfp, STYPE = int4[], FINALFUNC = ffnp, INITCOND = '{}')");
+  // --     P    P
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn04a(*) "
+      "(SFUNC = stfp, STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}')",
+      "ERROR:  cannot determine transition data type");
+
+  // --    Case4 (R = N) && ((B = P) || (B = N))
+  // --    -------------------------------------
+  // --    S    tf1      B    tf2
+  // --    -----------------------
+  // --    N    N        N    N
+  util.execute("CREATE AGGREGATE myaggn05a"
+		       "(BASETYPE = int, SFUNC = tfnp, STYPE = int[], FINALFUNC = ffnp, INITCOND = '{}')");
+  util.execute("CREATE AGGREGATE myaggn05b"
+               "(BASETYPE = int, SFUNC = tfnp, STYPE = int[], INITCOND = '{}')");
+  // --    N    N        N    P
+  util.execute("CREATE AGGREGATE myaggn06a"
+		       "(BASETYPE = int, SFUNC = tf2p, STYPE = int[], FINALFUNC = ffnp, INITCOND = '{}')");
+  util.execute("CREATE AGGREGATE myaggn06b"
+		       "(BASETYPE = int, SFUNC = tf2p, STYPE = int[], INITCOND = '{}')");
+  // --    N    N        P    N
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn07a "
+      "(BASETYPE = anyelement, SFUNC = tfnp, STYPE = int[], FINALFUNC = ffnp, INITCOND = '{}')",
+      "ERROR:  function tfnp(integer[], anyelement) does not exist");
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn07b "
+      "(BASETYPE = anyelement, SFUNC = tfnp, STYPE = int[], INITCOND = '{}')",
+      "ERROR:  function tfnp(integer[], anyelement) does not exist");
+  // --    N    N        P    P
+  util.execute("CREATE AGGREGATE myaggn08a"
+               "(BASETYPE = anyelement, SFUNC = tf2p, STYPE = int[], FINALFUNC = ffnp, INITCOND = '{}')");
+  util.execute("CREATE AGGREGATE myaggn08b"
+		       "(BASETYPE = anyelement, SFUNC = tf2p, STYPE = int[], INITCOND = '{}')");
+  // --    N    P        N    N
+  util.execute("CREATE AGGREGATE myaggn09a"
+		       "(BASETYPE = int, SFUNC = tf1p, STYPE = int[], FINALFUNC = ffnp, INITCOND = '{}')");
+  // --    N    P        N    P
+  util.execute("CREATE AGGREGATE myaggn10a"
+		       "(BASETYPE = int, SFUNC = tfp, STYPE = int[], FINALFUNC = ffnp, INITCOND = '{}')");
+  // --    N    P        P    N
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn11a"
+      "(BASETYPE = anyelement, SFUNC = tf1p, STYPE = int[], FINALFUNC = ffnp, INITCOND = '{}')",
+      "ERROR:  function tf1p(integer[], anyelement) does not exist");
+  // --    N    P        P    P
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn12a"
+      "(BASETYPE = anyelement, SFUNC = tfp, STYPE = int[], FINALFUNC = ffnp, INITCOND = '{}')",
+      "ERROR:  function tfp(integer[], anyelement) does not exist");
+  // --    P    N        N    N
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn13a"
+      "(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}')",
+      "ERROR:  cannot determine transition data type");
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn13b"
+      "(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray, INITCOND = '{}')",
+      "ERROR:  cannot determine transition data type");
+  // --    P    N        N    P
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn14a"
+      "(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}')",
+      "ERROR:  cannot determine transition data type");
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn14b"
+      "(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray, INITCOND = '{}')",
+      "ERROR:  cannot determine transition data type");
+  // --    P    N        P    N
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn15a"
+      "(BASETYPE = anyelement, SFUNC = tfnp, STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}')",
+      "ERROR:  function tfnp(anyarray, anyelement) does not exist");
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn15b"
+      "(BASETYPE = anyelement, SFUNC = tfnp, STYPE = anyarray, INITCOND = '{}')",
+      "ERROR:  function tfnp(anyarray, anyelement) does not exist");
+  // --    P    N        P    P
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn16a"
+      "(BASETYPE = anyelement, SFUNC = tf2p, STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}')",
+      "ERROR:  function tf2p(anyarray, anyelement) does not exist");
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn16b"
+      "(BASETYPE = anyelement, SFUNC = tf2p, STYPE = anyarray, INITCOND = '{}')",
+      "ERROR:  function tf2p(anyarray, anyelement) does not exist");
+  // --    P    P        N    N
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn17a"
+      "(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}')",
+      "ERROR:  cannot determine transition data type");
+  // --    P    P        N    P
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn18a"
+      "(BASETYPE = int, SFUNC = tfp, STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}')",
+      "ERROR:  cannot determine transition data type");
+  // --    P    P        P    N
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn19a"
+      "(BASETYPE = anyelement, SFUNC = tf1p, STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}')",
+      "ERROR:  function tf1p(anyarray, anyelement) does not exist");
+  // --    P    P        P    P
+  util.executeExpectErrorMsgStartWith(
+      "CREATE AGGREGATE myaggn20a"
+      "(BASETYPE = anyelement, SFUNC = tfp, STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}')",
+      "ERROR:  function ffnp(anyarray) does not exist");
+
+  // multi-arg polymorphic
+  util.execute("CREATE AGGREGATE mysum2(anyelement,anyelement) "
+		       "(SFUNC = sum3, STYPE = anyelement, INITCOND = '0')");
+
+  util.execute("CREATE TABLE t (f1 int, f2 int[], f3 text)");
+  util.execute("INSERT INTO t VALUES(1,array[1],'a')");
+  util.execute("INSERT INTO t VALUES(2,array[11],'b')");
+  util.execute("INSERT INTO t VALUES(3,array[111],'c')");
+  util.execute("INSERT INTO t VALUES(4,array[2],'a')");
+  util.execute("INSERT INTO t VALUES(5,array[22],'b')");
+  util.execute("INSERT INTO t VALUES(6,array[222],'c')");
+  util.execute("INSERT INTO t VALUES(7,array[3],'a')");
+  util.execute("INSERT INTO t VALUES(8,array[3],'b')");
+
+  util.execSQLFile("query/sql/polimorphism-test1-query.sql",
+		  	  	   "query/ans/polimorphism-test1-query.ans");
+
+  // clean up
+  util.execute("DROP TABLE t");
+
+  util.execute("DROP AGGREGATE myaggp01a(*)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp02a(*)");
+  util.execute("DROP AGGREGATE myaggp03a(*)");
+  util.execute("DROP AGGREGATE myaggp03b(*)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp04a(*)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp04b(*)");
+  util.execute("DROP AGGREGATE myaggp05a(int)");
+  util.execute("DROP AGGREGATE myaggp06a(int)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp07a(anyelement)");
+  util.execute("DROP AGGREGATE myaggp08a(anyelement)");
+  util.execute("DROP AGGREGATE myaggp09a(int)");
+  util.execute("DROP AGGREGATE myaggp09b(int)");
+  util.execute("DROP AGGREGATE myaggp10a(int)");
+  util.execute("DROP AGGREGATE myaggp10b(int)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp11a(anyelement)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp11b(anyelement)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp12a(anyelement)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp12b(anyelement)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp13a(int)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp14a(int)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp15a(anyelement)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp16a(anyelement)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp17a(int)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp17b(int)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp18a(int)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp18b(int)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp19a(anyelement)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggp19b(anyelement)");
+  util.execute("DROP AGGREGATE myaggp20a(anyelement)");
+  util.execute("DROP AGGREGATE myaggp20b(anyelement)");
+
+  util.execute("DROP AGGREGATE myaggn01a(*)");
+  util.execute("DROP AGGREGATE myaggn01b(*)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn02a(*)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn02b(*)");
+  util.execute("DROP AGGREGATE myaggn03a(*)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn04a(*)");
+  util.execute("DROP AGGREGATE myaggn05a(int)");
+  util.execute("DROP AGGREGATE myaggn05b(int)");
+  util.execute("DROP AGGREGATE myaggn06a(int)");
+  util.execute("DROP AGGREGATE myaggn06b(int)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn07a(*)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn07b(*)");
+  util.execute("DROP AGGREGATE myaggn08a(anyelement)");
+  util.execute("DROP AGGREGATE myaggn08b(anyelement)");
+  util.execute("DROP AGGREGATE myaggn09a(int)");
+  util.execute("DROP AGGREGATE myaggn10a(int)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn11a(*)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn12a(*)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn13a(int)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn13b(int)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn14a(int)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn14b(int)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn15a(*)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn15b(*)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn16a(*)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn16b(*)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn17a(int)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn18a(int)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn19a(*)");
+  util.execute("DROP AGGREGATE IF EXISTS myaggn20a(*)");
+
+  util.execute("DROP AGGREGATE mysum2(anyelement,anyelement)");
+
+  util.execute("DROP FUNCTION IF EXISTS stfp(anyarray)");
+  util.execute("DROP FUNCTION IF EXISTS stfnp(int[])");
+  util.execute("DROP FUNCTION IF EXISTS tfp(anyarray,anyelement)");
+  util.execute("DROP FUNCTION IF EXISTS tfnp(int[],int)");
+  util.execute("DROP FUNCTION IF EXISTS tf1p(anyarray,int)");
+  util.execute("DROP FUNCTION IF EXISTS tf2p(int[],anyelement)");
+  util.execute("DROP FUNCTION IF EXISTS sum3(anyelement,anyelement,anyelement)");
+  util.execute("DROP FUNCTION IF EXISTS ffp(anyarray)");
+  util.execute("DROP FUNCTION IF EXISTS ffnp(int[])");
+}
+
+TEST_F(TestQueryPolymorphism, Test2) {
+  hawq::test::SQLUtility util;
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0081706d/src/test/regress/expected/polymorphism.out
----------------------------------------------------------------------
diff --git a/src/test/regress/expected/polymorphism.out b/src/test/regress/expected/polymorphism.out
deleted file mode 100755
index 3a3f6a4..0000000
--- a/src/test/regress/expected/polymorphism.out
+++ /dev/null
@@ -1,544 +0,0 @@
--- Currently this tests polymorphic aggregates and indirectly does some
--- testing of polymorphic SQL functions.  It ought to be extended.
--- Legend:
------------
--- A = type is ANY
--- P = type is polymorphic
--- N = type is non-polymorphic
--- B = aggregate base type
--- S = aggregate state type
--- R = aggregate return type
--- 1 = arg1 of a function
--- 2 = arg2 of a function
--- ag = aggregate
--- tf = trans (state) function
--- ff = final function
--- rt = return type of a function
--- -> = implies
--- => = allowed
--- !> = not allowed
--- E  = exists
--- NE = not-exists
--- 
--- Possible states:
--- ----------------
--- B = (A || P || N)
---   when (B = A) -> (tf2 = NE)
--- S = (P || N)
--- ff = (E || NE)
--- tf1 = (P || N)
--- tf2 = (NE || P || N)
--- R = (P || N)
--- create functions for use as tf and ff with the needed combinations of
--- argument polymorphism, but within the constraints of valid aggregate
--- functions, i.e. tf arg1 and tf return type must match
--- polymorphic single arg transfn
-CREATE FUNCTION stfp(anyarray) RETURNS anyarray AS
-'select $1' LANGUAGE SQL;
--- non-polymorphic single arg transfn
-CREATE FUNCTION stfnp(int[]) RETURNS int[] AS
-'select $1' LANGUAGE SQL;
--- dual polymorphic transfn
-CREATE FUNCTION tfp(anyarray,anyelement) RETURNS anyarray AS
-'select $1 || $2' LANGUAGE SQL;
--- dual non-polymorphic transfn
-CREATE FUNCTION tfnp(int[],int) RETURNS int[] AS
-'select $1 || $2' LANGUAGE SQL;
--- arg1 only polymorphic transfn
-CREATE FUNCTION tf1p(anyarray,int) RETURNS anyarray AS
-'select $1' LANGUAGE SQL;
--- arg2 only polymorphic transfn
-CREATE FUNCTION tf2p(int[],anyelement) RETURNS int[] AS
-'select $1' LANGUAGE SQL;
--- multi-arg polymorphic
-CREATE FUNCTION sum3(anyelement,anyelement,anyelement) returns anyelement AS
-'select $1+$2+$3' language sql strict;
--- finalfn polymorphic
-CREATE FUNCTION ffp(anyarray) RETURNS anyarray AS
-'select $1' LANGUAGE SQL;
--- finalfn non-polymorphic
-CREATE FUNCTION ffnp(int[]) returns int[] as
-'select $1' LANGUAGE SQL;
--- Try to cover all the possible states:
--- 
--- Note: in Cases 1 & 2, we are trying to return P. Therefore, if the transfn
--- is stfnp, tfnp, or tf2p, we must use ffp as finalfn, because stfnp, tfnp,
--- and tf2p do not return P. Conversely, in Cases 3 & 4, we are trying to
--- return N. Therefore, if the transfn is stfp, tfp, or tf1p, we must use ffnp
--- as finalfn, because stfp, tfp, and tf1p do not return N.
---
---     Case1 (R = P) && (B = A)
---     ------------------------
---     S    tf1
---     -------
---     N    N
--- should CREATE
-CREATE AGGREGATE myaggp01a(*) (SFUNC = stfnp, STYPE = int4[],
-  FINALFUNC = ffp, INITCOND = '{}');
---     P    N
--- should ERROR: stfnp(anyarray) not matched by stfnp(int[])
-CREATE AGGREGATE myaggp02a(*) (SFUNC = stfnp, STYPE = anyarray,
-  FINALFUNC = ffp, INITCOND = '{}');
-ERROR:  cannot determine transition data type
-DETAIL:  An aggregate using "anyarray" or "anyelement" as transition type must have at least one argument of either type.
---     N    P
--- should CREATE
-CREATE AGGREGATE myaggp03a(*) (SFUNC = stfp, STYPE = int4[],
-  FINALFUNC = ffp, INITCOND = '{}');
-CREATE AGGREGATE myaggp03b(*) (SFUNC = stfp, STYPE = int4[],
-  INITCOND = '{}');
---     P    P
--- should ERROR: we have no way to resolve S
-CREATE AGGREGATE myaggp04a(*) (SFUNC = stfp, STYPE = anyarray,
-  FINALFUNC = ffp, INITCOND = '{}');
-ERROR:  cannot determine transition data type
-DETAIL:  An aggregate using "anyarray" or "anyelement" as transition type must have at least one argument of either type.
-CREATE AGGREGATE myaggp04b(*) (SFUNC = stfp, STYPE = anyarray,
-  INITCOND = '{}');
-ERROR:  cannot determine transition data type
-DETAIL:  An aggregate using "anyarray" or "anyelement" as transition type must have at least one argument of either type.
---    Case2 (R = P) && ((B = P) || (B = N))
---    -------------------------------------
---    S    tf1      B    tf2
---    -----------------------
---    N    N        N    N
--- should CREATE
-CREATE AGGREGATE myaggp05a(BASETYPE = int, SFUNC = tfnp, STYPE = int[],
-  FINALFUNC = ffp, INITCOND = '{}');
---    N    N        N    P
--- should CREATE
-CREATE AGGREGATE myaggp06a(BASETYPE = int, SFUNC = tf2p, STYPE = int[],
-  FINALFUNC = ffp, INITCOND = '{}');
---    N    N        P    N
--- should ERROR: tfnp(int[], anyelement) not matched by tfnp(int[], int)
-CREATE AGGREGATE myaggp07a(BASETYPE = anyelement, SFUNC = tfnp, STYPE = int[],
-  FINALFUNC = ffp, INITCOND = '{}');
-ERROR:  function tfnp(integer[], anyelement) does not exist
---    N    N        P    P
--- should CREATE
-CREATE AGGREGATE myaggp08a(BASETYPE = anyelement, SFUNC = tf2p, STYPE = int[],
-  FINALFUNC = ffp, INITCOND = '{}');
---    N    P        N    N
--- should CREATE
-CREATE AGGREGATE myaggp09a(BASETYPE = int, SFUNC = tf1p, STYPE = int[],
-  FINALFUNC = ffp, INITCOND = '{}');
-CREATE AGGREGATE myaggp09b(BASETYPE = int, SFUNC = tf1p, STYPE = int[],
-  INITCOND = '{}');
---    N    P        N    P
--- should CREATE
-CREATE AGGREGATE myaggp10a(BASETYPE = int, SFUNC = tfp, STYPE = int[],
-  FINALFUNC = ffp, INITCOND = '{}');
-CREATE AGGREGATE myaggp10b(BASETYPE = int, SFUNC = tfp, STYPE = int[],
-  INITCOND = '{}');
---    N    P        P    N
--- should ERROR: tf1p(int[],anyelement) not matched by tf1p(anyarray,int)
-CREATE AGGREGATE myaggp11a(BASETYPE = anyelement, SFUNC = tf1p, STYPE = int[],
-  FINALFUNC = ffp, INITCOND = '{}');
-ERROR:  function tf1p(integer[], anyelement) does not exist
-CREATE AGGREGATE myaggp11b(BASETYPE = anyelement, SFUNC = tf1p, STYPE = int[],
-  INITCOND = '{}');
-ERROR:  function tf1p(integer[], anyelement) does not exist
---    N    P        P    P
--- should ERROR: tfp(int[],anyelement) not matched by tfp(anyarray,anyelement)
-CREATE AGGREGATE myaggp12a(BASETYPE = anyelement, SFUNC = tfp, STYPE = int[],
-  FINALFUNC = ffp, INITCOND = '{}');
-ERROR:  function tfp(integer[], anyelement) does not exist
-CREATE AGGREGATE myaggp12b(BASETYPE = anyelement, SFUNC = tfp, STYPE = int[],
-  INITCOND = '{}');
-ERROR:  function tfp(integer[], anyelement) does not exist
---    P    N        N    N
--- should ERROR: tfnp(anyarray, int) not matched by tfnp(int[],int)
-CREATE AGGREGATE myaggp13a(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray,
-  FINALFUNC = ffp, INITCOND = '{}');
-ERROR:  cannot determine transition data type
-DETAIL:  An aggregate using "anyarray" or "anyelement" as transition type must have at least one argument of either type.
---    P    N        N    P
--- should ERROR: tf2p(anyarray, int) not matched by tf2p(int[],anyelement)
-CREATE AGGREGATE myaggp14a(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray,
-  FINALFUNC = ffp, INITCOND = '{}');
-ERROR:  cannot determine transition data type
-DETAIL:  An aggregate using "anyarray" or "anyelement" as transition type must have at least one argument of either type.
---    P    N        P    N
--- should ERROR: tfnp(anyarray, anyelement) not matched by tfnp(int[],int)
-CREATE AGGREGATE myaggp15a(BASETYPE = anyelement, SFUNC = tfnp,
-  STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');
-ERROR:  function tfnp(anyarray, anyelement) does not exist
---    P    N        P    P
--- should ERROR: tf2p(anyarray, anyelement) not matched by tf2p(int[],anyelement)
-CREATE AGGREGATE myaggp16a(BASETYPE = anyelement, SFUNC = tf2p,
-  STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');
-ERROR:  function tf2p(anyarray, anyelement) does not exist
---    P    P        N    N
--- should ERROR: we have no way to resolve S
-CREATE AGGREGATE myaggp17a(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray,
-  FINALFUNC = ffp, INITCOND = '{}');
-ERROR:  cannot determine transition data type
-DETAIL:  An aggregate using "anyarray" or "anyelement" as transition type must have at least one argument of either type.
-CREATE AGGREGATE myaggp17b(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray,
-  INITCOND = '{}');
-ERROR:  cannot determine transition data type
-DETAIL:  An aggregate using "anyarray" or "anyelement" as transition type must have at least one argument of either type.
---    P    P        N    P
--- should ERROR: tfp(anyarray, int) not matched by tfp(anyarray, anyelement)
-CREATE AGGREGATE myaggp18a(BASETYPE = int, SFUNC = tfp, STYPE = anyarray,
-  FINALFUNC = ffp, INITCOND = '{}');
-ERROR:  cannot determine transition data type
-DETAIL:  An aggregate using "anyarray" or "anyelement" as transition type must have at least one argument of either type.
-CREATE AGGREGATE myaggp18b(BASETYPE = int, SFUNC = tfp, STYPE = anyarray,
-  INITCOND = '{}');
-ERROR:  cannot determine transition data type
-DETAIL:  An aggregate using "anyarray" or "anyelement" as transition type must have at least one argument of either type.
---    P    P        P    N
--- should ERROR: tf1p(anyarray, anyelement) not matched by tf1p(anyarray, int)
-CREATE AGGREGATE myaggp19a(BASETYPE = anyelement, SFUNC = tf1p,
-  STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');
-ERROR:  function tf1p(anyarray, anyelement) does not exist
-CREATE AGGREGATE myaggp19b(BASETYPE = anyelement, SFUNC = tf1p,
-  STYPE = anyarray, INITCOND = '{}');
-ERROR:  function tf1p(anyarray, anyelement) does not exist
---    P    P        P    P
--- should CREATE
-CREATE AGGREGATE myaggp20a(BASETYPE = anyelement, SFUNC = tfp,
-  STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');
-CREATE AGGREGATE myaggp20b(BASETYPE = anyelement, SFUNC = tfp,
-  STYPE = anyarray, INITCOND = '{}');
---     Case3 (R = N) && (B = A)
---     ------------------------
---     S    tf1
---     -------
---     N    N
--- should CREATE
-CREATE AGGREGATE myaggn01a(*) (SFUNC = stfnp, STYPE = int4[],
-  FINALFUNC = ffnp, INITCOND = '{}');
-CREATE AGGREGATE myaggn01b(*) (SFUNC = stfnp, STYPE = int4[],
-  INITCOND = '{}');
---     P    N
--- should ERROR: stfnp(anyarray) not matched by stfnp(int[])
-CREATE AGGREGATE myaggn02a(*) (SFUNC = stfnp, STYPE = anyarray,
-  FINALFUNC = ffnp, INITCOND = '{}');
-ERROR:  cannot determine transition data type
-DETAIL:  An aggregate using "anyarray" or "anyelement" as transition type must have at least one argument of either type.
-CREATE AGGREGATE myaggn02b(*) (SFUNC = stfnp, STYPE = anyarray,
-  INITCOND = '{}');
-ERROR:  cannot determine transition data type
-DETAIL:  An aggregate using "anyarray" or "anyelement" as transition type must have at least one argument of either type.
---     N    P
--- should CREATE
-CREATE AGGREGATE myaggn03a(*) (SFUNC = stfp, STYPE = int4[],
-  FINALFUNC = ffnp, INITCOND = '{}');
---     P    P
--- should ERROR: ffnp(anyarray) not matched by ffnp(int[])
-CREATE AGGREGATE myaggn04a(*) (SFUNC = stfp, STYPE = anyarray,
-  FINALFUNC = ffnp, INITCOND = '{}');
-ERROR:  cannot determine transition data type
-DETAIL:  An aggregate using "anyarray" or "anyelement" as transition type must have at least one argument of either type.
---    Case4 (R = N) && ((B = P) || (B = N))
---    -------------------------------------
---    S    tf1      B    tf2
---    -----------------------
---    N    N        N    N
--- should CREATE
-CREATE AGGREGATE myaggn05a(BASETYPE = int, SFUNC = tfnp, STYPE = int[],
-  FINALFUNC = ffnp, INITCOND = '{}');
-CREATE AGGREGATE myaggn05b(BASETYPE = int, SFUNC = tfnp, STYPE = int[],
-  INITCOND = '{}');
---    N    N        N    P
--- should CREATE
-CREATE AGGREGATE myaggn06a(BASETYPE = int, SFUNC = tf2p, STYPE = int[],
-  FINALFUNC = ffnp, INITCOND = '{}');
-CREATE AGGREGATE myaggn06b(BASETYPE = int, SFUNC = tf2p, STYPE = int[],
-  INITCOND = '{}');
---    N    N        P    N
--- should ERROR: tfnp(int[], anyelement) not matched by tfnp(int[], int)
-CREATE AGGREGATE myaggn07a(BASETYPE = anyelement, SFUNC = tfnp, STYPE = int[],
-  FINALFUNC = ffnp, INITCOND = '{}');
-ERROR:  function tfnp(integer[], anyelement) does not exist
-CREATE AGGREGATE myaggn07b(BASETYPE = anyelement, SFUNC = tfnp, STYPE = int[],
-  INITCOND = '{}');
-ERROR:  function tfnp(integer[], anyelement) does not exist
---    N    N        P    P
--- should CREATE
-CREATE AGGREGATE myaggn08a(BASETYPE = anyelement, SFUNC = tf2p, STYPE = int[],
-  FINALFUNC = ffnp, INITCOND = '{}');
-CREATE AGGREGATE myaggn08b(BASETYPE = anyelement, SFUNC = tf2p, STYPE = int[],
-  INITCOND = '{}');
---    N    P        N    N
--- should CREATE
-CREATE AGGREGATE myaggn09a(BASETYPE = int, SFUNC = tf1p, STYPE = int[],
-  FINALFUNC = ffnp, INITCOND = '{}');
---    N    P        N    P
--- should CREATE
-CREATE AGGREGATE myaggn10a(BASETYPE = int, SFUNC = tfp, STYPE = int[],
-  FINALFUNC = ffnp, INITCOND = '{}');
---    N    P        P    N
--- should ERROR: tf1p(int[],anyelement) not matched by tf1p(anyarray,int)
-CREATE AGGREGATE myaggn11a(BASETYPE = anyelement, SFUNC = tf1p, STYPE = int[],
-  FINALFUNC = ffnp, INITCOND = '{}');
-ERROR:  function tf1p(integer[], anyelement) does not exist
---    N    P        P    P
--- should ERROR: tfp(int[],anyelement) not matched by tfp(anyarray,anyelement)
-CREATE AGGREGATE myaggn12a(BASETYPE = anyelement, SFUNC = tfp, STYPE = int[],
-  FINALFUNC = ffnp, INITCOND = '{}');
-ERROR:  function tfp(integer[], anyelement) does not exist
---    P    N        N    N
--- should ERROR: tfnp(anyarray, int) not matched by tfnp(int[],int)
-CREATE AGGREGATE myaggn13a(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray,
-  FINALFUNC = ffnp, INITCOND = '{}');
-ERROR:  cannot determine transition data type
-DETAIL:  An aggregate using "anyarray" or "anyelement" as transition type must have at least one argument of either type.
-CREATE AGGREGATE myaggn13b(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray,
-  INITCOND = '{}');
-ERROR:  cannot determine transition data type
-DETAIL:  An aggregate using "anyarray" or "anyelement" as transition type must have at least one argument of either type.
---    P    N        N    P
--- should ERROR: tf2p(anyarray, int) not matched by tf2p(int[],anyelement)
-CREATE AGGREGATE myaggn14a(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray,
-  FINALFUNC = ffnp, INITCOND = '{}');
-ERROR:  cannot determine transition data type
-DETAIL:  An aggregate using "anyarray" or "anyelement" as transition type must have at least one argument of either type.
-CREATE AGGREGATE myaggn14b(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray,
-  INITCOND = '{}');
-ERROR:  cannot determine transition data type
-DETAIL:  An aggregate using "anyarray" or "anyelement" as transition type must have at least one argument of either type.
---    P    N        P    N
--- should ERROR: tfnp(anyarray, anyelement) not matched by tfnp(int[],int)
-CREATE AGGREGATE myaggn15a(BASETYPE = anyelement, SFUNC = tfnp,
-  STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}');
-ERROR:  function tfnp(anyarray, anyelement) does not exist
-CREATE AGGREGATE myaggn15b(BASETYPE = anyelement, SFUNC = tfnp,
-  STYPE = anyarray, INITCOND = '{}');
-ERROR:  function tfnp(anyarray, anyelement) does not exist
---    P    N        P    P
--- should ERROR: tf2p(anyarray, anyelement) not matched by tf2p(int[],anyelement)
-CREATE AGGREGATE myaggn16a(BASETYPE = anyelement, SFUNC = tf2p,
-  STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}');
-ERROR:  function tf2p(anyarray, anyelement) does not exist
-CREATE AGGREGATE myaggn16b(BASETYPE = anyelement, SFUNC = tf2p,
-  STYPE = anyarray, INITCOND = '{}');
-ERROR:  function tf2p(anyarray, anyelement) does not exist
---    P    P        N    N
--- should ERROR: ffnp(anyarray) not matched by ffnp(int[])
-CREATE AGGREGATE myaggn17a(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray,
-  FINALFUNC = ffnp, INITCOND = '{}');
-ERROR:  cannot determine transition data type
-DETAIL:  An aggregate using "anyarray" or "anyelement" as transition type must have at least one argument of either type.
---    P    P        N    P
--- should ERROR: tfp(anyarray, int) not matched by tfp(anyarray, anyelement)
-CREATE AGGREGATE myaggn18a(BASETYPE = int, SFUNC = tfp, STYPE = anyarray,
-  FINALFUNC = ffnp, INITCOND = '{}');
-ERROR:  cannot determine transition data type
-DETAIL:  An aggregate using "anyarray" or "anyelement" as transition type must have at least one argument of either type.
---    P    P        P    N
--- should ERROR: tf1p(anyarray, anyelement) not matched by tf1p(anyarray, int)
-CREATE AGGREGATE myaggn19a(BASETYPE = anyelement, SFUNC = tf1p,
-  STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}');
-ERROR:  function tf1p(anyarray, anyelement) does not exist
---    P    P        P    P
--- should ERROR: ffnp(anyarray) not matched by ffnp(int[])
-CREATE AGGREGATE myaggn20a(BASETYPE = anyelement, SFUNC = tfp,
-  STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}');
-ERROR:  function ffnp(anyarray) does not exist
--- multi-arg polymorphic
-CREATE AGGREGATE mysum2(anyelement,anyelement) (SFUNC = sum3,
-  STYPE = anyelement, INITCOND = '0');
--- create test data for polymorphic aggregates
-create temp table t(f1 int, f2 int[], f3 text);
-insert into t values(1,array[1],'a');
-insert into t values(2,array[11],'b');
-insert into t values(3,array[111],'c');
-insert into t values(4,array[2],'a');
-insert into t values(5,array[22],'b');
-insert into t values(6,array[222],'c');
-insert into t values(7,array[3],'a');
-insert into t values(8,array[3],'b');
--- test the successfully created polymorphic aggregates
-select f3, myaggp01a(*) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggp01a
-----+-----------
- a  | {}
- b  | {}
- c  | {}
-(3 rows)
-
-select f3, myaggp03a(*) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggp03a
-----+-----------
- a  | {}
- b  | {}
- c  | {}
-(3 rows)
-
-select f3, myaggp03b(*) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggp03b
-----+-----------
- a  | {}
- b  | {}
- c  | {}
-(3 rows)
-
-select f3, myaggp05a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggp05a
-----+-----------
- a  | {1,4,7}
- b  | {5,2,8}
- c  | {3,6}
-(3 rows)
-
-select f3, myaggp06a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggp06a
-----+-----------
- a  | {}
- b  | {}
- c  | {}
-(3 rows)
-
-select f3, myaggp08a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggp08a
-----+-----------
- a  | {}
- b  | {}
- c  | {}
-(3 rows)
-
-select f3, myaggp09a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggp09a
-----+-----------
- a  | {}
- b  | {}
- c  | {}
-(3 rows)
-
-select f3, myaggp09b(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggp09b
-----+-----------
- a  | {}
- b  | {}
- c  | {}
-(3 rows)
-
-select f3, myaggp10a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggp10a
-----+-----------
- a  | {1,4,7}
- b  | {5,2,8}
- c  | {3,6}
-(3 rows)
-
-select f3, myaggp10b(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggp10b
-----+-----------
- a  | {1,4,7}
- b  | {5,2,8}
- c  | {3,6}
-(3 rows)
-
-select f3, myaggp20a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggp20a
-----+-----------
- a  | {1,4,7}
- b  | {5,2,8}
- c  | {3,6}
-(3 rows)
-
-select f3, myaggp20b(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggp20b
-----+-----------
- a  | {1,4,7}
- b  | {5,2,8}
- c  | {3,6}
-(3 rows)
-
-select f3, myaggn01a(*) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggn01a
-----+-----------
- a  | {}
- b  | {}
- c  | {}
-(3 rows)
-
-select f3, myaggn01b(*) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggn01b
-----+-----------
- a  | {}
- b  | {}
- c  | {}
-(3 rows)
-
-select f3, myaggn03a(*) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggn03a
-----+-----------
- a  | {}
- b  | {}
- c  | {}
-(3 rows)
-
-select f3, myaggn05a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggn05a
-----+-----------
- a  | {1,4,7}
- b  | {5,2,8}
- c  | {3,6}
-(3 rows)
-
-select f3, myaggn05b(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggn05b
-----+-----------
- a  | {1,4,7}
- b  | {5,2,8}
- c  | {3,6}
-(3 rows)
-
-select f3, myaggn06a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggn06a
-----+-----------
- a  | {}
- b  | {}
- c  | {}
-(3 rows)
-
-select f3, myaggn06b(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggn06b
-----+-----------
- a  | {}
- b  | {}
- c  | {}
-(3 rows)
-
-select f3, myaggn08a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggn08a
-----+-----------
- a  | {}
- b  | {}
- c  | {}
-(3 rows)
-
-select f3, myaggn08b(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggn08b
-----+-----------
- a  | {}
- b  | {}
- c  | {}
-(3 rows)
-
-select f3, myaggn09a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggn09a
-----+-----------
- a  | {}
- b  | {}
- c  | {}
-(3 rows)
-
-select f3, myaggn10a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
- f3 | myaggn10a
-----+-----------
- a  | {1,4,7}
- b  | {5,2,8}
- c  | {3,6}
-(3 rows)
-
-select mysum2(f1, f1 + 1) from t;
- mysum2
---------
-     80
-(1 row)
-

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0081706d/src/test/regress/known_good_schedule
----------------------------------------------------------------------
diff --git a/src/test/regress/known_good_schedule b/src/test/regress/known_good_schedule
index 58608ce..71564b9 100755
--- a/src/test/regress/known_good_schedule
+++ b/src/test/regress/known_good_schedule
@@ -128,7 +128,6 @@ ignore: without_oid
 ignore: conversion
 ignore: truncate
 ignore: alter_table
-test: polymorphism
 test: rowtypes
 ignore: returning
 ignore: stats

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0081706d/src/test/regress/sql/polymorphism.sql
----------------------------------------------------------------------
diff --git a/src/test/regress/sql/polymorphism.sql b/src/test/regress/sql/polymorphism.sql
deleted file mode 100644
index 5d07f9e..0000000
--- a/src/test/regress/sql/polymorphism.sql
+++ /dev/null
@@ -1,377 +0,0 @@
--- Currently this tests polymorphic aggregates and indirectly does some
--- testing of polymorphic SQL functions.  It ought to be extended.
-
-
--- Legend:
------------
--- A = type is ANY
--- P = type is polymorphic
--- N = type is non-polymorphic
--- B = aggregate base type
--- S = aggregate state type
--- R = aggregate return type
--- 1 = arg1 of a function
--- 2 = arg2 of a function
--- ag = aggregate
--- tf = trans (state) function
--- ff = final function
--- rt = return type of a function
--- -> = implies
--- => = allowed
--- !> = not allowed
--- E  = exists
--- NE = not-exists
--- 
--- Possible states:
--- ----------------
--- B = (A || P || N)
---   when (B = A) -> (tf2 = NE)
--- S = (P || N)
--- ff = (E || NE)
--- tf1 = (P || N)
--- tf2 = (NE || P || N)
--- R = (P || N)
-
--- create functions for use as tf and ff with the needed combinations of
--- argument polymorphism, but within the constraints of valid aggregate
--- functions, i.e. tf arg1 and tf return type must match
-
--- polymorphic single arg transfn
-CREATE FUNCTION stfp(anyarray) RETURNS anyarray AS
-'select $1' LANGUAGE SQL;
--- non-polymorphic single arg transfn
-CREATE FUNCTION stfnp(int[]) RETURNS int[] AS
-'select $1' LANGUAGE SQL;
-
--- dual polymorphic transfn
-CREATE FUNCTION tfp(anyarray,anyelement) RETURNS anyarray AS
-'select $1 || $2' LANGUAGE SQL;
--- dual non-polymorphic transfn
-CREATE FUNCTION tfnp(int[],int) RETURNS int[] AS
-'select $1 || $2' LANGUAGE SQL;
-
--- arg1 only polymorphic transfn
-CREATE FUNCTION tf1p(anyarray,int) RETURNS anyarray AS
-'select $1' LANGUAGE SQL;
--- arg2 only polymorphic transfn
-CREATE FUNCTION tf2p(int[],anyelement) RETURNS int[] AS
-'select $1' LANGUAGE SQL;
-
--- multi-arg polymorphic
-CREATE FUNCTION sum3(anyelement,anyelement,anyelement) returns anyelement AS
-'select $1+$2+$3' language sql strict;
-
--- finalfn polymorphic
-CREATE FUNCTION ffp(anyarray) RETURNS anyarray AS
-'select $1' LANGUAGE SQL;
--- finalfn non-polymorphic
-CREATE FUNCTION ffnp(int[]) returns int[] as
-'select $1' LANGUAGE SQL;
-
--- Try to cover all the possible states:
--- 
--- Note: in Cases 1 & 2, we are trying to return P. Therefore, if the transfn
--- is stfnp, tfnp, or tf2p, we must use ffp as finalfn, because stfnp, tfnp,
--- and tf2p do not return P. Conversely, in Cases 3 & 4, we are trying to
--- return N. Therefore, if the transfn is stfp, tfp, or tf1p, we must use ffnp
--- as finalfn, because stfp, tfp, and tf1p do not return N.
---
---     Case1 (R = P) && (B = A)
---     ------------------------
---     S    tf1
---     -------
---     N    N
--- should CREATE
-CREATE AGGREGATE myaggp01a(*) (SFUNC = stfnp, STYPE = int4[],
-  FINALFUNC = ffp, INITCOND = '{}');
-
---     P    N
--- should ERROR: stfnp(anyarray) not matched by stfnp(int[])
-CREATE AGGREGATE myaggp02a(*) (SFUNC = stfnp, STYPE = anyarray,
-  FINALFUNC = ffp, INITCOND = '{}');
-
---     N    P
--- should CREATE
-CREATE AGGREGATE myaggp03a(*) (SFUNC = stfp, STYPE = int4[],
-  FINALFUNC = ffp, INITCOND = '{}');
-CREATE AGGREGATE myaggp03b(*) (SFUNC = stfp, STYPE = int4[],
-  INITCOND = '{}');
-
---     P    P
--- should ERROR: we have no way to resolve S
-CREATE AGGREGATE myaggp04a(*) (SFUNC = stfp, STYPE = anyarray,
-  FINALFUNC = ffp, INITCOND = '{}');
-CREATE AGGREGATE myaggp04b(*) (SFUNC = stfp, STYPE = anyarray,
-  INITCOND = '{}');
-
-
---    Case2 (R = P) && ((B = P) || (B = N))
---    -------------------------------------
---    S    tf1      B    tf2
---    -----------------------
---    N    N        N    N
--- should CREATE
-CREATE AGGREGATE myaggp05a(BASETYPE = int, SFUNC = tfnp, STYPE = int[],
-  FINALFUNC = ffp, INITCOND = '{}');
-
---    N    N        N    P
--- should CREATE
-CREATE AGGREGATE myaggp06a(BASETYPE = int, SFUNC = tf2p, STYPE = int[],
-  FINALFUNC = ffp, INITCOND = '{}');
-
---    N    N        P    N
--- should ERROR: tfnp(int[], anyelement) not matched by tfnp(int[], int)
-CREATE AGGREGATE myaggp07a(BASETYPE = anyelement, SFUNC = tfnp, STYPE = int[],
-  FINALFUNC = ffp, INITCOND = '{}');
-
---    N    N        P    P
--- should CREATE
-CREATE AGGREGATE myaggp08a(BASETYPE = anyelement, SFUNC = tf2p, STYPE = int[],
-  FINALFUNC = ffp, INITCOND = '{}');
-
---    N    P        N    N
--- should CREATE
-CREATE AGGREGATE myaggp09a(BASETYPE = int, SFUNC = tf1p, STYPE = int[],
-  FINALFUNC = ffp, INITCOND = '{}');
-CREATE AGGREGATE myaggp09b(BASETYPE = int, SFUNC = tf1p, STYPE = int[],
-  INITCOND = '{}');
-
---    N    P        N    P
--- should CREATE
-CREATE AGGREGATE myaggp10a(BASETYPE = int, SFUNC = tfp, STYPE = int[],
-  FINALFUNC = ffp, INITCOND = '{}');
-CREATE AGGREGATE myaggp10b(BASETYPE = int, SFUNC = tfp, STYPE = int[],
-  INITCOND = '{}');
-
---    N    P        P    N
--- should ERROR: tf1p(int[],anyelement) not matched by tf1p(anyarray,int)
-CREATE AGGREGATE myaggp11a(BASETYPE = anyelement, SFUNC = tf1p, STYPE = int[],
-  FINALFUNC = ffp, INITCOND = '{}');
-CREATE AGGREGATE myaggp11b(BASETYPE = anyelement, SFUNC = tf1p, STYPE = int[],
-  INITCOND = '{}');
-
---    N    P        P    P
--- should ERROR: tfp(int[],anyelement) not matched by tfp(anyarray,anyelement)
-CREATE AGGREGATE myaggp12a(BASETYPE = anyelement, SFUNC = tfp, STYPE = int[],
-  FINALFUNC = ffp, INITCOND = '{}');
-CREATE AGGREGATE myaggp12b(BASETYPE = anyelement, SFUNC = tfp, STYPE = int[],
-  INITCOND = '{}');
-
---    P    N        N    N
--- should ERROR: tfnp(anyarray, int) not matched by tfnp(int[],int)
-CREATE AGGREGATE myaggp13a(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray,
-  FINALFUNC = ffp, INITCOND = '{}');
-
---    P    N        N    P
--- should ERROR: tf2p(anyarray, int) not matched by tf2p(int[],anyelement)
-CREATE AGGREGATE myaggp14a(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray,
-  FINALFUNC = ffp, INITCOND = '{}');
-
---    P    N        P    N
--- should ERROR: tfnp(anyarray, anyelement) not matched by tfnp(int[],int)
-CREATE AGGREGATE myaggp15a(BASETYPE = anyelement, SFUNC = tfnp,
-  STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');
-
---    P    N        P    P
--- should ERROR: tf2p(anyarray, anyelement) not matched by tf2p(int[],anyelement)
-CREATE AGGREGATE myaggp16a(BASETYPE = anyelement, SFUNC = tf2p,
-  STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');
-
---    P    P        N    N
--- should ERROR: we have no way to resolve S
-CREATE AGGREGATE myaggp17a(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray,
-  FINALFUNC = ffp, INITCOND = '{}');
-CREATE AGGREGATE myaggp17b(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray,
-  INITCOND = '{}');
-
---    P    P        N    P
--- should ERROR: tfp(anyarray, int) not matched by tfp(anyarray, anyelement)
-CREATE AGGREGATE myaggp18a(BASETYPE = int, SFUNC = tfp, STYPE = anyarray,
-  FINALFUNC = ffp, INITCOND = '{}');
-CREATE AGGREGATE myaggp18b(BASETYPE = int, SFUNC = tfp, STYPE = anyarray,
-  INITCOND = '{}');
-
---    P    P        P    N
--- should ERROR: tf1p(anyarray, anyelement) not matched by tf1p(anyarray, int)
-CREATE AGGREGATE myaggp19a(BASETYPE = anyelement, SFUNC = tf1p,
-  STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');
-CREATE AGGREGATE myaggp19b(BASETYPE = anyelement, SFUNC = tf1p,
-  STYPE = anyarray, INITCOND = '{}');
-
---    P    P        P    P
--- should CREATE
-CREATE AGGREGATE myaggp20a(BASETYPE = anyelement, SFUNC = tfp,
-  STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');
-CREATE AGGREGATE myaggp20b(BASETYPE = anyelement, SFUNC = tfp,
-  STYPE = anyarray, INITCOND = '{}');
-
---     Case3 (R = N) && (B = A)
---     ------------------------
---     S    tf1
---     -------
---     N    N
--- should CREATE
-CREATE AGGREGATE myaggn01a(*) (SFUNC = stfnp, STYPE = int4[],
-  FINALFUNC = ffnp, INITCOND = '{}');
-CREATE AGGREGATE myaggn01b(*) (SFUNC = stfnp, STYPE = int4[],
-  INITCOND = '{}');
-
---     P    N
--- should ERROR: stfnp(anyarray) not matched by stfnp(int[])
-CREATE AGGREGATE myaggn02a(*) (SFUNC = stfnp, STYPE = anyarray,
-  FINALFUNC = ffnp, INITCOND = '{}');
-CREATE AGGREGATE myaggn02b(*) (SFUNC = stfnp, STYPE = anyarray,
-  INITCOND = '{}');
-
---     N    P
--- should CREATE
-CREATE AGGREGATE myaggn03a(*) (SFUNC = stfp, STYPE = int4[],
-  FINALFUNC = ffnp, INITCOND = '{}');
-
---     P    P
--- should ERROR: ffnp(anyarray) not matched by ffnp(int[])
-CREATE AGGREGATE myaggn04a(*) (SFUNC = stfp, STYPE = anyarray,
-  FINALFUNC = ffnp, INITCOND = '{}');
-
-
---    Case4 (R = N) && ((B = P) || (B = N))
---    -------------------------------------
---    S    tf1      B    tf2
---    -----------------------
---    N    N        N    N
--- should CREATE
-CREATE AGGREGATE myaggn05a(BASETYPE = int, SFUNC = tfnp, STYPE = int[],
-  FINALFUNC = ffnp, INITCOND = '{}');
-CREATE AGGREGATE myaggn05b(BASETYPE = int, SFUNC = tfnp, STYPE = int[],
-  INITCOND = '{}');
-
---    N    N        N    P
--- should CREATE
-CREATE AGGREGATE myaggn06a(BASETYPE = int, SFUNC = tf2p, STYPE = int[],
-  FINALFUNC = ffnp, INITCOND = '{}');
-CREATE AGGREGATE myaggn06b(BASETYPE = int, SFUNC = tf2p, STYPE = int[],
-  INITCOND = '{}');
-
---    N    N        P    N
--- should ERROR: tfnp(int[], anyelement) not matched by tfnp(int[], int)
-CREATE AGGREGATE myaggn07a(BASETYPE = anyelement, SFUNC = tfnp, STYPE = int[],
-  FINALFUNC = ffnp, INITCOND = '{}');
-CREATE AGGREGATE myaggn07b(BASETYPE = anyelement, SFUNC = tfnp, STYPE = int[],
-  INITCOND = '{}');
-
---    N    N        P    P
--- should CREATE
-CREATE AGGREGATE myaggn08a(BASETYPE = anyelement, SFUNC = tf2p, STYPE = int[],
-  FINALFUNC = ffnp, INITCOND = '{}');
-CREATE AGGREGATE myaggn08b(BASETYPE = anyelement, SFUNC = tf2p, STYPE = int[],
-  INITCOND = '{}');
-
---    N    P        N    N
--- should CREATE
-CREATE AGGREGATE myaggn09a(BASETYPE = int, SFUNC = tf1p, STYPE = int[],
-  FINALFUNC = ffnp, INITCOND = '{}');
-
---    N    P        N    P
--- should CREATE
-CREATE AGGREGATE myaggn10a(BASETYPE = int, SFUNC = tfp, STYPE = int[],
-  FINALFUNC = ffnp, INITCOND = '{}');
-
---    N    P        P    N
--- should ERROR: tf1p(int[],anyelement) not matched by tf1p(anyarray,int)
-CREATE AGGREGATE myaggn11a(BASETYPE = anyelement, SFUNC = tf1p, STYPE = int[],
-  FINALFUNC = ffnp, INITCOND = '{}');
-
---    N    P        P    P
--- should ERROR: tfp(int[],anyelement) not matched by tfp(anyarray,anyelement)
-CREATE AGGREGATE myaggn12a(BASETYPE = anyelement, SFUNC = tfp, STYPE = int[],
-  FINALFUNC = ffnp, INITCOND = '{}');
-
---    P    N        N    N
--- should ERROR: tfnp(anyarray, int) not matched by tfnp(int[],int)
-CREATE AGGREGATE myaggn13a(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray,
-  FINALFUNC = ffnp, INITCOND = '{}');
-CREATE AGGREGATE myaggn13b(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray,
-  INITCOND = '{}');
-
---    P    N        N    P
--- should ERROR: tf2p(anyarray, int) not matched by tf2p(int[],anyelement)
-CREATE AGGREGATE myaggn14a(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray,
-  FINALFUNC = ffnp, INITCOND = '{}');
-CREATE AGGREGATE myaggn14b(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray,
-  INITCOND = '{}');
-
---    P    N        P    N
--- should ERROR: tfnp(anyarray, anyelement) not matched by tfnp(int[],int)
-CREATE AGGREGATE myaggn15a(BASETYPE = anyelement, SFUNC = tfnp,
-  STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}');
-CREATE AGGREGATE myaggn15b(BASETYPE = anyelement, SFUNC = tfnp,
-  STYPE = anyarray, INITCOND = '{}');
-
---    P    N        P    P
--- should ERROR: tf2p(anyarray, anyelement) not matched by tf2p(int[],anyelement)
-CREATE AGGREGATE myaggn16a(BASETYPE = anyelement, SFUNC = tf2p,
-  STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}');
-CREATE AGGREGATE myaggn16b(BASETYPE = anyelement, SFUNC = tf2p,
-  STYPE = anyarray, INITCOND = '{}');
-
---    P    P        N    N
--- should ERROR: ffnp(anyarray) not matched by ffnp(int[])
-CREATE AGGREGATE myaggn17a(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray,
-  FINALFUNC = ffnp, INITCOND = '{}');
-
---    P    P        N    P
--- should ERROR: tfp(anyarray, int) not matched by tfp(anyarray, anyelement)
-CREATE AGGREGATE myaggn18a(BASETYPE = int, SFUNC = tfp, STYPE = anyarray,
-  FINALFUNC = ffnp, INITCOND = '{}');
-
---    P    P        P    N
--- should ERROR: tf1p(anyarray, anyelement) not matched by tf1p(anyarray, int)
-CREATE AGGREGATE myaggn19a(BASETYPE = anyelement, SFUNC = tf1p,
-  STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}');
-
---    P    P        P    P
--- should ERROR: ffnp(anyarray) not matched by ffnp(int[])
-CREATE AGGREGATE myaggn20a(BASETYPE = anyelement, SFUNC = tfp,
-  STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}');
-
--- multi-arg polymorphic
-CREATE AGGREGATE mysum2(anyelement,anyelement) (SFUNC = sum3,
-  STYPE = anyelement, INITCOND = '0');
-
--- create test data for polymorphic aggregates
-create temp table t(f1 int, f2 int[], f3 text);
-insert into t values(1,array[1],'a');
-insert into t values(2,array[11],'b');
-insert into t values(3,array[111],'c');
-insert into t values(4,array[2],'a');
-insert into t values(5,array[22],'b');
-insert into t values(6,array[222],'c');
-insert into t values(7,array[3],'a');
-insert into t values(8,array[3],'b');
-
--- test the successfully created polymorphic aggregates
-select f3, myaggp01a(*) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggp03a(*) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggp03b(*) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggp05a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggp06a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggp08a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggp09a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggp09b(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggp10a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggp10b(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggp20a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggp20b(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggn01a(*) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggn01b(*) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggn03a(*) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggn05a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggn05b(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggn06a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggn06b(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggn08a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggn08b(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggn09a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select f3, myaggn10a(f1) from (select * from t order by f1 limit 10) as foo group by f3 order by f3;
-select mysum2(f1, f1 + 1) from t;
-


Mime
View raw message