Skip to content

Commit

Permalink
Fix for RM # 42861, provide a function to return code version
Browse files Browse the repository at this point in the history
Add a SQL function to return code version
The function usage is as follows:

	select hdfs_fdw_version();
	 hdfs_fdw_version
	------------------
    	        20003
	(1 row)

The purpose of code version is as follows:
If the .so file is updated and the customer
just installs the update but does not do an
ALTER EXTENSION then the \dx version will still
be older but the .so will be newer.
To detect which version of .so is being used
we need a code version.
  • Loading branch information
EC2 Default User committed Dec 15, 2017
1 parent efc59da commit 5b806f9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion hdfs_fdw--2.0.2--2.0.3.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* hdfs_fdw/hdfs_fdw--2.0.2--2.0.3.sql */

-- No new functions or definitions were added in 2.0.3
CREATE OR REPLACE FUNCTION hdfs_fdw_version()
RETURNS pg_catalog.int4 STRICT
AS 'MODULE_PATHNAME' LANGUAGE C;
4 changes: 4 additions & 0 deletions hdfs_fdw--2.0.3.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ LANGUAGE C STRICT;
CREATE FOREIGN DATA WRAPPER hdfs_fdw
HANDLER hdfs_fdw_handler
VALIDATOR hdfs_fdw_validator;

CREATE OR REPLACE FUNCTION hdfs_fdw_version()
RETURNS pg_catalog.int4 STRICT
AS 'MODULE_PATHNAME' LANGUAGE C;
18 changes: 18 additions & 0 deletions hdfs_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ PG_MODULE_MAGIC;
/* Default CPU cost to process 1 row */
#define DEFAULT_FDW_TUPLE_COST 1000.0

/*
* In PG 9.5.1 the number will be 90501,
* our version is 2.0.3 so number will be 20003
*/
#define CODE_VERSION 20003

PG_FUNCTION_INFO_V1(hdfs_fdw_handler);
PG_FUNCTION_INFO_V1(hdfs_fdw_version);

#define IS_DEBUG 0

Expand Down Expand Up @@ -100,6 +107,12 @@ static void process_query_params(int index,

static void hdfs_fdw_xact_callback(XACT_CB_SIGNATURE);

Datum
hdfs_fdw_version(PG_FUNCTION_ARGS)
{
PG_RETURN_INT32(CODE_VERSION);
}

void
_PG_init(void)
{
Expand Down Expand Up @@ -295,6 +308,8 @@ hdfsGetForeignRelSize(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid
}

baserel->rows = 1000;
fpinfo->width = 1000;
baserel->reltarget->width = fpinfo->width;

/* Get the actual number of rows from server
* if use_remote_estimate is specified in options.
Expand All @@ -311,6 +326,9 @@ hdfsGetForeignRelSize(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid
}
fpinfo->rows = baserel->tuples = baserel->rows;

fpinfo->width = 1000;
baserel->reltarget->width = fpinfo->width;

if (IS_DEBUG)
ereport(LOG, (errmsg("hdfs_fdw: hdfsGetForeignRelSize ends [%f]", baserel->rows)));
}
Expand Down

0 comments on commit 5b806f9

Please sign in to comment.