hawq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hornn <...@git.apache.org>
Subject [GitHub] incubator-hawq pull request: HAWQ-123. Add 'Partition by' descript...
Date Thu, 12 Nov 2015 00:00:47 GMT
Github user hornn commented on a diff in the pull request:

    https://github.com/apache/incubator-hawq/pull/93#discussion_r44605480
  
    --- Diff: src/bin/psql/describe.c ---
    @@ -2676,6 +2686,80 @@ add_distributed_by_footer(const char* oid, PQExpBufferData *inoutbuf,
PQExpBuffe
     }
     
     /*
    + * Add a 'partition by' description to the footer.
    + */
    +static int
    +add_partition_by_footer(const char* oid, PQExpBufferData *inoutbuf, PQExpBufferData *buf)
    +{
    +	PGresult	*result = NULL;
    +
    +	/* check if current relation is root partition, if it is root partition, at least 1
row returns */
    +	printfPQExpBuffer(buf, "SELECT parrelid FROM pg_catalog.pg_partition WHERE parrelid
= '%s'", oid);
    +	result = PSQLexec(buf->data, false);
    +
    +	if (!result)
    +		return 1;
    +	int nRows = PQntuples(result);
    +	int nPartKey = 0;
    +
    +	PQclear(result);
    +
    +	if(nRows)
    +	{
    +		/* query partition key on the root partition */
    +		printfPQExpBuffer(buf,
    +			"WITH att_arr AS (SELECT unnest(paratts) \n"
    +			"	FROM pg_catalog.pg_partition p \n"
    +			"	WHERE p.parrelid = '%s' AND p.parlevel = 0 AND p.paristemplate = false), \n"
    +			"idx_att AS (SELECT row_number() OVER() AS idx, unnest AS att_num FROM att_arr) \n"
    +			"SELECT attname FROM pg_catalog.pg_attribute, idx_att \n"
    +			"	WHERE attrelid='%s' AND attnum = att_num ORDER BY idx ",
    +			oid, oid);
    +	}
    +	else
    +	{
    +		/* query partition key on the intermediate partition */
    +		printfPQExpBuffer(buf,
    +			"WITH att_arr AS (SELECT unnest(paratts) FROM pg_catalog.pg_partition p, \n"
    +			"	(SELECT parrelid, parlevel \n"
    +			"		FROM pg_catalog.pg_partition p, pg_catalog.pg_partition_rule pr \n"
    +			"		WHERE pr.parchildrelid='%s' AND p.oid = pr.paroid) AS v \n"
    +			"	WHERE p.parrelid = v.parrelid AND p.parlevel = v.parlevel+1 AND p.paristemplate
= false), \n"
    +			"idx_att AS (SELECT row_number() OVER() AS idx, unnest AS att_num FROM att_arr) \n"
    +			"SELECT attname FROM pg_catalog.pg_attribute, idx_att \n"
    +			"	WHERE attrelid='%s' AND attnum = att_num ORDER BY idx ",
    +			oid, oid);
    +	}
    +
    +	result = PSQLexec(buf->data, false);
    +	if (!result)
    +		return 1;
    +	nPartKey = PQntuples(result);
    +
    +	if (nPartKey)
    +	{
    +		char *partColName;
    +		int i = 0;
    +		appendPQExpBuffer(inoutbuf, "Partition by: (");
    +		for (i = 0; i < nPartKey; i++)
    +		{
    +			if (i > 0)
    +				appendPQExpBuffer(inoutbuf, ", ");
    +			partColName = PQgetvalue(result, i, 0);
    +
    +			if (!partColName)
    --- End diff --
    
    if something bad happens here, maybe inoutbuf should be cleared. Otherwise a partial message
will be printed (e.g. "Partition by: x, y, "). Also perhaps clear result.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message