Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrarahmad committed Aug 28, 2015
1 parent 27f7a81 commit 5ae4f77
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 65 deletions.
2 changes: 1 addition & 1 deletion autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# autogen.sh
# Foreign-data wrapper for remote Hadoop/Hive servers
#
# Portions Copyright (c) 2004-2014, EnterpriseDB Corporation.
# Portions Copyright (c) 2004-2015, EnterpriseDB Corporation.
#
# IDENTIFICATION
# autogen.sh
Expand Down
14 changes: 6 additions & 8 deletions hdfs_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* hdfs_client.c
* Foreign-data wrapper for remote Hadoop servers
*
* Portions Copyright (c) 2012-2014, PostgreSQL Global Development Group
*
* Portions Copyright (c) 2004-2014, EnterpriseDB Corporation.
*
* IDENTIFICATION
Expand Down Expand Up @@ -59,12 +57,12 @@ hdfs_get_field_data_len(hdfs_opt *opt, HiveResultSet *rs, int col)
char *
hdfs_get_field_as_cstring(hdfs_opt *opt, HiveResultSet *rs, int idx, bool *is_null, int len)
{
size_t bs;
char *value;
int isnull = 0;
char err_buf[512];
size_t bs;
char *value = NULL;
int isnull = 0;
char err_buf[512];

value = (char*)palloc(len);
value = (char*) palloc(len);
if (DBGetFieldAsCString(rs, idx, value, len, &bs, &isnull, err_buf, sizeof(err_buf)) == HIVE_ERROR)
ereport(ERROR,
(errcode(ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION),
Expand All @@ -79,7 +77,7 @@ hdfs_get_field_as_cstring(hdfs_opt *opt, HiveResultSet *rs, int idx, bool *is_nu
HiveResultSet*
hdfs_query_execute(hdfs_opt *opt, char *query)
{
HiveResultSet *rs;
HiveResultSet *rs = NULL;
char err_buf[512];
if (DBExecute(opt->conn, query, &rs, 1000, err_buf, sizeof(err_buf)) == HIVE_ERROR)
ereport(ERROR,
Expand Down
4 changes: 2 additions & 2 deletions hdfs_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Portions Copyright (c) 2004-2014, EnterpriseDB Corporation.
*
* IDENTIFICATION
* connection.c
* hdfs_connection.c
*
*-------------------------------------------------------------------------
*/
Expand Down Expand Up @@ -107,7 +107,7 @@ hdfs_get_connection(ForeignServer *server, UserMapping *user, hdfs_opt *opt)

/*
* cleanup_connection:
* Delete all the cache entries on backend exists.
* Delete all the cache entries on backend exists.
*/
void
hdfs_cleanup_connection(void)
Expand Down
11 changes: 2 additions & 9 deletions hdfs_deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ foreign_expr_walker(Node *node,
{
case T_Var:
{
Var *var = (Var *) node;
Var *var = (Var *) node;

/*
* If the Var is from the foreign table, we consider its
Expand Down Expand Up @@ -249,7 +249,7 @@ foreign_expr_walker(Node *node,
break;
case T_Const:
{
Const *c = (Const *) node;
Const *c = (Const *) node;

/*
* If the constant has nondefault collation, either it's of a
Expand Down Expand Up @@ -701,13 +701,6 @@ hdfs_deparse_select(hdfs_opt *opt,
heap_close(rel, NoLock);
}

/*
* Emit a target list that retrieves the columns specified in attrs_used.
* This is used for both SELECT and RETURNING targetlists.
*
* The tlist text is appended to buf, and we also create an integer List
* of the columns being retrieved, which is returned to *retrieved_attrs.
*/
static void
deparseTargetList(StringInfo buf,
PlannerInfo *root,
Expand Down
31 changes: 16 additions & 15 deletions hdfs_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
PG_MODULE_MAGIC;

/* Default CPU cost to start up a foreign query. */
#define DEFAULT_FDW_STARTUP_COST 100.0
#define DEFAULT_FDW_STARTUP_COST 100.0

/* Default CPU cost to process 1 row */
#define DEFAULT_FDW_TUPLE_COST 0.01
#define DEFAULT_FDW_TUPLE_COST 0.01

extern void _PG_init(void);

Expand Down Expand Up @@ -144,7 +144,7 @@ static void
hdfsGetForeignRelSize(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid)
{
HDFSFdwRelationInfo *fpinfo = NULL;
ListCell *lc = NULL;
ListCell *lc = NULL;
hdfs_opt *options = NULL;

/*
Expand Down Expand Up @@ -202,8 +202,8 @@ static void
hdfsGetForeignPaths(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid)
{
HDFSFdwRelationInfo *fpinfo = (HDFSFdwRelationInfo *) baserel->fdw_private;
int total_cost = 0;
ForeignPath *path = NULL;
int total_cost = 0;
ForeignPath *path = NULL;

total_cost = fpinfo->fdw_tuple_cost * baserel->rows;

Expand Down Expand Up @@ -237,7 +237,7 @@ hdfsGetForeignPlan(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid,
List *retrieved_attrs;
StringInfoData sql;
ListCell *lc = NULL;
hdfs_opt *options = NULL;
hdfs_opt *options = NULL;

/* Get the options */
options = GetOptions(foreigntableid);
Expand Down Expand Up @@ -320,7 +320,7 @@ static void
hdfsBeginForeignScan(ForeignScanState *node, int eflags)
{
ForeignScan *fsplan = (ForeignScan *) node->ss.ps.plan;
hdfsFdwExecutionState *festate = NULL;
hdfsFdwExecutionState *festate = NULL;
Oid foreigntableid = RelationGetRelid(node->ss.ss_currentRelation);

GetOptions(foreigntableid);
Expand All @@ -340,13 +340,13 @@ hdfsIterateForeignScan(ForeignScanState *node)
char *value = NULL;
unsigned int len = 0;
int attid;
hdfs_opt *options = NULL;
hdfs_opt *options = NULL;
ListCell *lc = NULL;
AttInMetadata *attinmeta = NULL;
Oid foreigntableid = RelationGetRelid(node->ss.ss_currentRelation);
Oid foreigntableid = RelationGetRelid(node->ss.ss_currentRelation);
hdfsFdwExecutionState *festate = (hdfsFdwExecutionState *) node->fdw_state;
TupleTableSlot *slot = node->ss.ss_ScanTupleSlot;
TupleDesc tupdesc = node->ss.ss_currentRelation->rd_att;
TupleTableSlot *slot = node->ss.ss_ScanTupleSlot;
TupleDesc tupdesc = node->ss.ss_currentRelation->rd_att;

values = palloc0(tupdesc->natts * sizeof(char*));

Expand Down Expand Up @@ -411,11 +411,12 @@ hdfsAcquireSampleRowsFunc(Relation relation, int elevel,
static bool
hdfsAnalyzeForeignTable(Relation relation, AcquireSampleRowsFunc *func, BlockNumber *totalpages)
{
long ts = 0;
hdfs_opt *options = NULL;
Oid foreigntableid = RelationGetRelid(relation);
long ts = 0;
hdfs_opt *options = NULL;
Oid foreigntableid = RelationGetRelid(relation);

*func = hdfsAcquireSampleRowsFunc;

/* Get the options */
options = GetOptions(foreigntableid);

Expand All @@ -431,7 +432,7 @@ hdfsEndForeignScan(ForeignScanState *node)
{
hdfsFdwExecutionState *festate = (hdfsFdwExecutionState *) node->fdw_state;
hdfs_opt *options = NULL;
Oid foreigntableid = RelationGetRelid(node->ss.ss_currentRelation);
Oid foreigntableid = RelationGetRelid(node->ss.ss_currentRelation);

/* Get the options */
options = GetOptions(foreigntableid);
Expand Down
50 changes: 24 additions & 26 deletions hdfs_fdw.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ typedef struct HDFSFdwRelationInfo
Selectivity local_conds_sel;

/* Estimated size and cost for a scan with baserestrictinfo quals. */
double rows;
int width;
Cost startup_cost;
Cost total_cost;
double rows;
int width;
Cost startup_cost;
Cost total_cost;

/* Options extracted from catalogs. */
bool use_remote_estimate;
Cost fdw_startup_cost;
Cost fdw_tuple_cost;

/* Cached catalog information. */
ForeignTable *table;
ForeignTable *table;
ForeignServer *server;
UserMapping *user; /* only set in use_remote_estimate mode */
UserMapping *user; /* only set in use_remote_estimate mode */
} HDFSFdwRelationInfo;


Expand All @@ -95,46 +95,44 @@ typedef struct HDFSFdwRelationInfo
*/
typedef struct HDFSFdwScanState
{
Relation rel; /* relcache entry for the foreign table */
Relation rel; /* relcache entry for the foreign table */

/* extracted fdw_private data */
char *query; /* text of SELECT command */
List *retrieved_attrs; /* list of retrieved attribute numbers */
char *query; /* text of SELECT command */
List *retrieved_attrs; /* list of retrieved attribute numbers */

/* for remote query execution */
unsigned int cursor_number; /* quasi-unique ID for my cursor */
bool cursor_exists; /* have we created the cursor? */
int numParams; /* number of parameters passed to query */
FmgrInfo *param_flinfo; /* output conversion functions for them */
List *param_exprs; /* executable expressions for param values */
const char **param_values; /* textual values of query parameters */
unsigned int cursor_number; /* quasi-unique ID for my cursor */
bool cursor_exists; /* have we created the cursor? */
int numParams; /* number of parameters passed to query */
FmgrInfo *param_flinfo; /* output conversion functions for them */
List *param_exprs; /* executable expressions for param values */
const char **param_values; /* textual values of query parameters */

/* for storing result tuples */
HeapTuple *tuples; /* array of currently-retrieved tuples */
int num_tuples; /* # of tuples in array */
int next_tuple; /* index of next one to return */
HeapTuple *tuples; /* array of currently-retrieved tuples */
int num_tuples; /* # of tuples in array */
int next_tuple; /* index of next one to return */

/* batch-level state, for optimizing rewinds and avoiding useless fetch */
int fetch_ct_2; /* Min(# of fetches done, 2) */
bool eof_reached; /* true if last fetch reached EOF */
int fetch_ct_2; /* Min(# of fetches done, 2) */
bool eof_reached; /* true if last fetch reached EOF */

/* working memory contexts */
MemoryContext batch_cxt; /* context holding current batch of tuples */
MemoryContext temp_cxt; /* context for per-tuple temporary data */
MemoryContext batch_cxt; /* context holding current batch of tuples */
MemoryContext temp_cxt; /* context for per-tuple temporary data */
} HDFSFdwScanState;

/* Callback argument for ec_member_matches_foreign */
typedef struct
{
Expr *current; /* current expr, or NULL if not yet found */
List *already_used; /* expressions already dealt with */
Expr *current; /* current expr, or NULL if not yet found */
List *already_used; /* expressions already dealt with */
} ec_member_foreign_arg;


/* Functions prototypes for hdfs_option.c file */
hdfs_opt* hdfs_get_options(Oid foreigntableid);


/* Functions prototypes for hdfs_connection.c file */
HiveConnection *hdfs_get_connection(ForeignServer *server, UserMapping *user, hdfs_opt *opt);
void hdfs_cleanup_connection(void);
Expand Down
2 changes: 1 addition & 1 deletion hdfs_option.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Portions Copyright (c) 2004-2014, EnterpriseDB Corporation.
*
* IDENTIFICATION
* hdfs.c
* hdfs_option.c
*
*-------------------------------------------------------------------------
*/
Expand Down
6 changes: 3 additions & 3 deletions hdfs_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ hdfs_rowcount(hdfs_opt *opt, PlannerInfo *root, RelOptInfo *baserel, HDFSFdwRela
{
HiveResultSet* rs = NULL;
size_t len = 0;
bool is_null;
bool is_null;
char *value = NULL;
int idx = 0;
double rows = 0;
StringInfoData sql;
StringInfoData sql;

initStringInfo(&sql);
hdfs_deparse_explain(opt, &sql, root, baserel, fpinfo);
Expand All @@ -49,7 +49,7 @@ void
hdfs_analyze(hdfs_opt *opt)
{
HiveResultSet* rs = NULL;
StringInfoData sql;
StringInfoData sql;

initStringInfo(&sql);
hdfs_deparse_analyze(&sql, opt);
Expand Down

0 comments on commit 5ae4f77

Please sign in to comment.