You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@madlib.apache.org by ri...@apache.org on 2016/01/08 01:29:15 UTC

incubator-madlib git commit: Utilities: Use pg_attribute to get cols and types

Repository: incubator-madlib
Updated Branches:
  refs/heads/master ba5fc1ead -> 60a07ebd9


Utilities: Use pg_attribute to get cols and types


Project: http://git-wip-us.apache.org/repos/asf/incubator-madlib/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-madlib/commit/60a07ebd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-madlib/tree/60a07ebd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-madlib/diff/60a07ebd

Branch: refs/heads/master
Commit: 60a07ebd9d1fc0f7042caebf9be19228808d64dd
Parents: ba5fc1e
Author: Rahul Iyer <ri...@pivotal.io>
Authored: Thu Jan 7 16:22:08 2016 -0800
Committer: Rahul Iyer <ri...@pivotal.io>
Committed: Thu Jan 7 16:22:08 2016 -0800

----------------------------------------------------------------------
 .../modules/utilities/validate_args.py_in       | 30 ++++++--------------
 1 file changed, 9 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/60a07ebd/src/ports/postgres/modules/utilities/validate_args.py_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/utilities/validate_args.py_in b/src/ports/postgres/modules/utilities/validate_args.py_in
index fc4d142..07cb9fd 100644
--- a/src/ports/postgres/modules/utilities/validate_args.py_in
+++ b/src/ports/postgres/modules/utilities/validate_args.py_in
@@ -282,28 +282,16 @@ def get_cols_and_types(tbl):
     if tbl is None or tbl.lower() == 'null':
         plpy.error('Input error: Table name (NULL) is invalid')
 
-   # determine the exact table_schema and table_name
+    # determine the exact table_schema and table_name
     # in case that source_table only contains table_name
-    row = plpy.execute("""
-                        SELECT
-                            quote_ident(nspname) AS table_schema,
-                            quote_ident(relname) AS table_name
-                        FROM
-                            pg_class AS c,
-                            pg_namespace AS nsp
-                        WHERE
-                            c.oid = '{source_table}'::regclass::oid AND
-                            c.relnamespace = nsp.oid
-                        """.format(source_table=tbl))
-    schema = row[0]['table_schema']
-    table = row[0]['table_name']
-
-    sql_string = """SELECT array_agg(quote_ident(column_name)::varchar) AS cols,
-                           array_agg(data_type::varchar) AS types
-                    FROM information_schema.columns
-                    WHERE table_name = '{table}'
-                    AND table_schema = '{schema}'
-                """.format(table=table, schema=schema)
+    sql_string = """SELECT
+                        array_agg(quote_ident(attname)::varchar ORDER BY attnum) AS cols,
+                        array_agg(quote_ident(typname)::varchar ORDER BY attnum) AS types
+                    FROM pg_attribute, pg_type
+                    WHERE attrelid = '{tbl}'::regclass
+                      AND pg_attribute.atttypid = pg_type.oid
+                      AND NOT attisdropped
+                      AND attnum > 0""".format(tbl=tbl)
     result = plpy.execute(sql_string)[0]
     col_names = _string_to_array(result['cols'])
     col_types = _string_to_array(result['types'])