hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shiv...@apache.org
Subject incubator-hawq git commit: HAWQ-405. Fix to handling field access through temp table schema introduced with support for hcatalog
Date Fri, 12 Feb 2016 21:37:23 GMT
Repository: incubator-hawq
Updated Branches:
  refs/heads/master e424ad49e -> 95a5da110


HAWQ-405. Fix to handling field access through temp table schema introduced with support for
hcatalog


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

Branch: refs/heads/master
Commit: 95a5da110506f6a81acd1e89625509cc0d1fea75
Parents: e424ad4
Author: Shivram Mani <shivram.mani@gmail.com>
Authored: Fri Feb 12 13:37:18 2016 -0800
Committer: Shivram Mani <shivram.mani@gmail.com>
Committed: Fri Feb 12 13:37:18 2016 -0800

----------------------------------------------------------------------
 src/backend/catalog/namespace.c    | 39 +++++++++++++++++----------------
 src/test/regress/expected/temp.out | 29 ++++++++++++++++++++++++
 src/test/regress/sql/temp.sql      | 10 +++++++++
 3 files changed, 59 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/95a5da11/src/backend/catalog/namespace.c
----------------------------------------------------------------------
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c
index 401218c..5056327 100644
--- a/src/backend/catalog/namespace.c
+++ b/src/backend/catalog/namespace.c
@@ -1495,18 +1495,34 @@ LookupInternalNamespaceId(const char *nspname)
 Oid
 LookupNamespaceId(const char *nspname, Oid dboid)
 {
-    if(gp_upgrade_mode){
+
+    /* check for pg_temp alias */
+    if (NSPDBOID_CURRENT == dboid && strcmp(nspname, "pg_temp") == 0)
+    {
+        if (TempNamespaceValid(true))
+            return myTempNamespace;
+        /*
+         * Since this is used only for looking up existing objects, there
+         * is no point in trying to initialize the temp namespace here;
+         * and doing so might create problems for some callers.
+         * Just fall through and give the "does not exist" error.
+         */
+    }
+
+    if(gp_upgrade_mode)
+    {
         // This code is only need at hawq2.0 upgrade, in this case the old pg_namespace doesn't

         // have column nspdboid, so we report error in else clause
-        if(ObjectIdGetDatum(dboid)==NSPDBOID_CURRENT){
+        if(ObjectIdGetDatum(dboid)==NSPDBOID_CURRENT)
+        {
             return caql_getoid(
 			NULL,
 			cql("SELECT oid FROM pg_namespace "
 				" WHERE nspname = :1",
 				CStringGetDatum((char *) nspname)));
-        }else{
-            elog(ERROR, "Upgrade cann't process the namespace: %s in dbid: %i", nspname,
dboid);
         }
+        else
+        	elog(ERROR, "Upgrade cannot process the namespace: %s in dbid: %i", nspname, dboid);
     }
 	return caql_getoid(
 			NULL,
@@ -1530,21 +1546,6 @@ LookupExplicitNamespace(const char *nspname, Oid dboid)
 	Oid			namespaceId;
 	AclResult	aclresult;
 
-	/* check for pg_temp alias */
-	if (NSPDBOID_CURRENT == dboid && strcmp(nspname, "pg_temp") == 0)
-	{
-		if (TempNamespaceValid(true))
-		{
-			return myTempNamespace;
-		}
-		/*
-		 * Since this is used only for looking up existing objects, there
-		 * is no point in trying to initialize the temp namespace here;
-		 * and doing so might create problems for some callers.
-		 * Just fall through and give the "does not exist" error.
-		 */
-	}
-
 	namespaceId = LookupNamespaceId(nspname, dboid);
 
 	if (!OidIsValid(namespaceId))

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/95a5da11/src/test/regress/expected/temp.out
----------------------------------------------------------------------
diff --git a/src/test/regress/expected/temp.out b/src/test/regress/expected/temp.out
index ebedd68..64ed4d1 100755
--- a/src/test/regress/expected/temp.out
+++ b/src/test/regress/expected/temp.out
@@ -170,3 +170,32 @@ select * from whereami;
 -- you can invoke a temp function explicitly, though
 -- select pg_temp.whoami();
 drop table public.whereami;
+-- Test querying column using pg_temp schema
+create table pg_temp.test (row integer, count integer);
+insert into pg_temp.test values (1, 10), (2, 20), (3, 30);
+select avg(pg_temp.test.count) from pg_temp.test;
+ avg
+-----
+  20
+(1 row)
+
+select avg(test.count) from pg_temp.test;
+ avg
+-----
+  20
+(1 row)
+
+select avg(count) from pg_temp.test;
+ avg
+-----
+  20
+(1 row)
+
+select case when pg_temp.test.count = 30 then 30 when pg_temp.test.count = 20 then 20 else
10 end from pg_temp.test;
+ case
+------
+   10
+   20
+   30
+(3 rows)
+

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/95a5da11/src/test/regress/sql/temp.sql
----------------------------------------------------------------------
diff --git a/src/test/regress/sql/temp.sql b/src/test/regress/sql/temp.sql
index d1f25d7..685b062 100644
--- a/src/test/regress/sql/temp.sql
+++ b/src/test/regress/sql/temp.sql
@@ -151,3 +151,13 @@ select * from whereami;
 -- select pg_temp.whoami();
 
 drop table public.whereami;
+
+-- Test querying column using pg_temp schema
+create table pg_temp.test (row integer, count integer);
+insert into pg_temp.test values (1, 10), (2, 20), (3, 30);
+select avg(pg_temp.test.count) from pg_temp.test;
+select avg(test.count) from pg_temp.test;
+select avg(count) from pg_temp.test;
+
+select case when pg_temp.test.count = 30 then 30 when pg_temp.test.count = 20 then 20 else
10 end from pg_temp.test;
+


Mime
View raw message