hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odiache...@apache.org
Subject incubator-hawq git commit: HAWQ-546. Implemented call of pxf_get_object_fields for Hive on psql. [Forced Update!]
Date Wed, 30 Mar 2016 20:49:16 GMT
Repository: incubator-hawq
Updated Branches:
  refs/heads/HAWQ-546 d56fbcf85 -> 884b197b9 (forced update)


HAWQ-546. Implemented call of pxf_get_object_fields for Hive on psql.


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

Branch: refs/heads/HAWQ-546
Commit: 884b197b9b72a2a3de0f8d024ef92f4987077173
Parents: cac5e17
Author: Oleksandr Diachenko <odiachenko@pivotal.io>
Authored: Tue Mar 29 14:44:05 2016 -0700
Committer: Oleksandr Diachenko <odiachenko@pivotal.io>
Committed: Wed Mar 30 13:49:08 2016 -0700

----------------------------------------------------------------------
 src/bin/psql/describe.c                        | 97 +++++++++++++++++----
 src/test/regress/input/hcatalog_lookup.source  |  2 +
 src/test/regress/output/hcatalog_lookup.source |  3 +
 3 files changed, 85 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/884b197b/src/bin/psql/describe.c
----------------------------------------------------------------------
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 1672e64..f3de6a4 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -42,12 +42,16 @@ static bool describeOneTSConfig(const char *oid, const char *nspname,
 static void printACLColumn(PQExpBuffer buf, const char *colname);
 static bool isGPDB(void);
 static bool isGPDB4200OrLater(void);
-static bool describeHcatalogTable(const char *pattern, bool verbose);
+static bool describePxfTable(const char *profile, const char *pattern, bool verbose);
+static void parsePxfPattern(const char *user_pattern, char **pattern);
 
 /* GPDB 3.2 used PG version 8.2.10, and we've moved the minor number up since then for each
release,  4.1 = 8.2.15 */
 /* Allow for a couple of future releases.  If the version isn't in this range, we are talking
to PostgreSQL, not GPDB */
 #define mightBeGPDB() (pset.sversion >= 80210 && pset.sversion < 80222)
 
+#define HiveProfileName "Hive"
+#define HcatalogSourceName "hcatalog"
+
 static bool isGPDB(void)
 {
 	static enum { gpdb_maybe, gpdb_yes, gpdb_no } talking_to_gpdb;
@@ -1152,12 +1156,15 @@ describeTableDetails(const char *pattern, bool verbose, bool showSystem)
 	PQExpBufferData buf;
 	PGresult   *res;
 	int			i;
-	char const *hcatalog = "hcatalog";
 
+	//Hive hook in this method
+	if(strncmp(pattern, HcatalogSourceName, strlen(HcatalogSourceName)) == 0)
+	{
+		char *pxf_pattern = "*";
+		parsePxfPattern(pattern, &pxf_pattern);
+		return describePxfTable(HiveProfileName, pxf_pattern, verbose);
+	}
 
-	//Hcatalog hook in this method
-	if(strncmp(pattern, hcatalog, strlen(hcatalog)) == 0)
-		return describeHcatalogTable(pattern, verbose);
 
 	initPQExpBuffer(&buf);
 
@@ -4223,40 +4230,96 @@ printACLColumn(PQExpBuffer buf, const char *colname)
 
 
 static void
-parseExternalPattern(const char *user_pattern, char **profile, char **pattern)
+parsePxfPattern(const char *user_pattern, char **pattern)
 {
-
-	*profile = strtok(user_pattern, ".");
+	strtok(strdup(user_pattern), ".");
 	*pattern = strtok(NULL, "/0");
-
 }
 
 static bool
-describeHcatalogTable(const char *pattern, bool verbose)
+describePxfTable(const char *profile, const char *pattern, bool verbose)
 {
 	PQExpBufferData buf;
+	PQExpBufferData title;
 	PGresult *res;
 	printQueryOpt myopt = pset.popt;
-	char *pxf_profile = "*";
-	char *pxf_pattern = "*";
-
-	parseExternalPattern(pattern, &pxf_profile, &pattern);
+	printTableContent cont;
+	int			cols = 0;
+	int			total_numrows = 0;
+	char	   *headers[2];
+	bool		printTableInitialized = false;
 
 	initPQExpBuffer(&buf);
 
 	printfPQExpBuffer(&buf, "SELECT * FROM\n"
-			"pxf_get_object_fields('%s', '%s') \n", pxf_profile, pxf_pattern);
+			"pxf_get_item_fields('%s', '%s') \n", profile, pattern);
 
 	res = PSQLexec(buf.data, false);
+	total_numrows = PQntuples(res);
 	termPQExpBuffer(&buf);
 	if (!res)
 		return false;
 
 	myopt.nullPrint = NULL;
-	myopt.title = _("List of Hcatalog tables");
+	myopt.title = _("List of Hive tables");
 	myopt.translate_header = true;
 
-	printQuery(res, &myopt, pset.queryFout, pset.logfile);
+
+	/* Header */
+	headers[0] = gettext_noop("Column");
+	headers[1] = gettext_noop("Type");
+	cols = 2;
+
+	char *previous_path = NULL;
+	char *previous_itemname = NULL;
+
+
+	for (int i = 0; i < total_numrows; i++)
+	{
+
+		/* First row for current table*/
+		if (previous_itemname == NULL || strncmp(previous_itemname, PQgetvalue(res, i, 1), strlen(previous_itemname))
!= 0)
+		{
+
+			if (previous_itemname != NULL)
+				printTable(&cont, pset.queryFout, pset.logfile);
+
+			/* Do clean-up for previous tables if any*/
+			if (printTableInitialized)
+			{
+				printTableCleanup(&cont);
+				termPQExpBuffer(&title);
+				printTableInitialized = false;
+			}
+
+			/* Initialize */
+			initPQExpBuffer(&title);
+
+			printfPQExpBuffer(&title, _("PXF %s Table \"%s.%s\""), profile, PQgetvalue(res, i,
0), PQgetvalue(res, i, 1));
+			printTableInit(&cont, &myopt, title.data, cols, total_numrows);
+
+			for (int j = 0; j < cols; j++)
+				printTableAddHeader(&cont, headers[j], true, 'l');
+		}
+
+		/* Column */
+		printTableAddCell(&cont, PQgetvalue(res, i, 2), false, false);
+
+		/* Type */
+		printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false);
+
+		previous_path = PQgetvalue(res, i, 0);
+		previous_itemname = PQgetvalue(res, i, 1);
+
+	}
+
+	printTable(&cont, pset.queryFout, pset.logfile);
+
+	if (printTableInitialized)
+	{
+		printTableCleanup(&cont);
+		termPQExpBuffer(&title);
+	}
 
 	PQclear(res);
 	return true;

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/884b197b/src/test/regress/input/hcatalog_lookup.source
----------------------------------------------------------------------
diff --git a/src/test/regress/input/hcatalog_lookup.source b/src/test/regress/input/hcatalog_lookup.source
index 3d7279f..8e43e3c 100644
--- a/src/test/regress/input/hcatalog_lookup.source
+++ b/src/test/regress/input/hcatalog_lookup.source
@@ -7,11 +7,13 @@ SET hcatalog_enable = false;
 SELECT * from hcatalog.db.t;
 
 SELECT * FROM pxf_get_item_fields('Hive', '*');
+ \d hcatalog.*.*
 
 -- enable GUC
 SET hcatalog_enable = true;
 
 SELECT * FROM pxf_get_item_fields('Hive', '*abc*abc*');
+\d hcatalog.*abc*.*abc*
 
 -- Create function to insert and scan in-memory data to pg_class
 CREATE OR REPLACE FUNCTION convert_to_hcatalog_schema(schemaName text) RETURNS text

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/884b197b/src/test/regress/output/hcatalog_lookup.source
----------------------------------------------------------------------
diff --git a/src/test/regress/output/hcatalog_lookup.source b/src/test/regress/output/hcatalog_lookup.source
index ed4a7ef..4db3125 100644
--- a/src/test/regress/output/hcatalog_lookup.source
+++ b/src/test/regress/output/hcatalog_lookup.source
@@ -9,6 +9,8 @@ LINE 1: SELECT * from hcatalog.db.t;
                       ^
 SELECT * FROM pxf_get_item_fields('Hive', '*');
 ERROR:  HCatalog querying is not enabled
+\d hcatalog.*.*
+ERROR:  HCatalog querying is not enabled
 -- enable GUC
 SET hcatalog_enable = true;
 SELECT * FROM pxf_get_item_fields('Hive', '*abc*abc*');
@@ -16,6 +18,7 @@ SELECT * FROM pxf_get_item_fields('Hive', '*abc*abc*');
 ------+----------+-----------+-----------
 (0 rows)
 
+\d hcatalog.*abc*.*abc*
 -- Create function to insert and scan in-memory data to pg_class
 CREATE OR REPLACE FUNCTION convert_to_hcatalog_schema(schemaName text) RETURNS text
   AS '@abs_builddir@/regress@DLSUFFIX@', 'convert_to_hcatalog_schema'


Mime
View raw message