Skip to content

Commit

Permalink
Merge pull request #47 from komamitsu/fix-error-on-cursor
Browse files Browse the repository at this point in the history
Avoid passing non-Node value to make_foreignscan() as 'fdw_private'
  • Loading branch information
komamitsu authored Oct 17, 2017
2 parents 784bd8e + 4392895 commit ca810df
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
15 changes: 15 additions & 0 deletions expected/treasuredata_fdw.out.erb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ SELECT COUNT(1) FROM (SELECT * FROM td_www_access LIMIT 1) x WHERE size > 0;
1
(1 row)

BEGIN;
DECLARE cur CURSOR FOR SELECT time FROM td_www_access WHERE time < 1412320911 ORDER BY time;
FETCH cur;
time
------------
1412320845
(1 row)

FETCH cur;
time
------------
1412320861
(1 row)

COMMIT;
CREATE FOREIGN TABLE td_summary_in_www_access (
code integer,
method varchar,
Expand Down
5 changes: 5 additions & 0 deletions sql/treasuredata_fdw.sql.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ SELECT COUNT(1) FROM td_www_access WHERE SUBSTRING(method, 1, 2) || SUBSTR(metho
SELECT COUNT(1) FROM td_www_access WHERE agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0.1) Gecko/20100101 Firefox/9.0.1' OR agent LIKE 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.1)%' OR agent IN ('Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)', 'Mozilla/5.0 (iPad; CPU OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3');
-- For https://github.com/komamitsu/treasuredata_fdw/issues/23
SELECT COUNT(1) FROM (SELECT * FROM td_www_access LIMIT 1) x WHERE size > 0;
BEGIN;
DECLARE cur CURSOR FOR SELECT time FROM td_www_access WHERE time < 1412320911 ORDER BY time;
FETCH cur;
FETCH cur;
COMMIT;
CREATE FOREIGN TABLE td_summary_in_www_access (
code integer,
method varchar,
Expand Down
17 changes: 7 additions & 10 deletions treasuredata_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ enum FdwScanPrivateIndex
/* SQL statement to execute remotely (as a String node) */
FdwScanPrivateSelectSql,
/* Integer list of attribute numbers retrieved by the SELECT */
FdwScanPrivateRetrievedAttrs,
FdwScanPrivateForeignTable
FdwScanPrivateRetrievedAttrs
};

/*
Expand Down Expand Up @@ -268,7 +267,7 @@ static ForeignScan *treasuredataGetForeignPlan(PlannerInfo *root,
#if PG_VERSION_NUM >= 90500
, Plan *outer_plan
#endif
);
);
static void treasuredataBeginForeignScan(ForeignScanState *node, int eflags);
static TupleTableSlot *treasuredataIterateForeignScan(ForeignScanState *node);
// static void treasuredataReScanForeignScan(ForeignScanState *node);
Expand Down Expand Up @@ -563,7 +562,7 @@ treasuredataGetForeignPlan(PlannerInfo *root,
#if PG_VERSION_NUM >= 90500
, Plan *outer_plan
#endif
)
)
{
TdFdwRelationInfo *fpinfo = (TdFdwRelationInfo *) baserel->fdw_private;
Index scan_relid = baserel->relid;
Expand Down Expand Up @@ -700,10 +699,8 @@ treasuredataGetForeignPlan(PlannerInfo *root,
* Build the fdw_private list that will be available to the executor.
* Items in the list must match enum FdwScanPrivateIndex, above.
*/
fdw_private = list_make3(makeString(sql.data),
retrieved_attrs,
fpinfo->table
);
fdw_private = list_make2(makeString(sql.data),
retrieved_attrs);

/*
* Create the ForeignScan node from target list, local filtering
Expand Down Expand Up @@ -762,9 +759,9 @@ treasuredataBeginForeignScan(ForeignScanState *node, int eflags)
FdwScanPrivateSelectSql));
fsstate->retrieved_attrs = (List *) list_nth(fsplan->fdw_private,
FdwScanPrivateRetrievedAttrs);
fsstate->table = (ForeignTable *) list_nth(fsplan->fdw_private,
FdwScanPrivateForeignTable);

/* Get info about foreign table. */
fsstate->table = GetForeignTable(RelationGetRelid(node->ss.ss_currentRelation));

/* Create contexts for batches of tuples and per-tuple temp workspace. */
#if 0
Expand Down

0 comments on commit ca810df

Please sign in to comment.