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 21:04:07 UTC

incubator-madlib git commit: Utilities: Revert 60a07eb + use unquoted table names

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


Utilities: Revert 60a07eb + use unquoted table names

The previous commit (60a07eb) used pg_attribute instead of
information_schema to get column names and types. This led
to different names in the types causing issues in rest of the code. It's
better to use information_schema since it gives general (non-Postgres
specific) results, but it requires unquoted table and schema names as
input.


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

Branch: refs/heads/master
Commit: 79b50bb098683c62c1d5574e2567a4e9e391bd78
Parents: 60a07eb
Author: Rahul Iyer <ri...@pivotal.io>
Authored: Fri Jan 8 10:38:18 2016 -0800
Committer: Rahul Iyer <ri...@pivotal.io>
Committed: Fri Jan 8 10:38:18 2016 -0800

----------------------------------------------------------------------
 .../modules/utilities/validate_args.py_in       | 27 ++++++++++++++------
 1 file changed, 19 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/79b50bb0/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 07cb9fd..ed5343f 100644
--- a/src/ports/postgres/modules/utilities/validate_args.py_in
+++ b/src/ports/postgres/modules/utilities/validate_args.py_in
@@ -284,14 +284,25 @@ def get_cols_and_types(tbl):
 
     # determine the exact table_schema and table_name
     # in case that source_table only contains table_name
-    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)
+    row = plpy.execute("""
+                        SELECT
+                            nspname AS table_schema,
+                            relname AS table_name
+                        FROM
+                            pg_class AS c,
+                            pg_namespace AS nsp
+                        WHERE
+                            c.oid = '{tbl}'::regclass::oid AND
+                            c.relnamespace = nsp.oid
+                        """.format(tbl=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)
     result = plpy.execute(sql_string)[0]
     col_names = _string_to_array(result['cols'])
     col_types = _string_to_array(result['types'])