Ejemplo n.º 1
0
/*
 * twitterBegin
 *   Query search API and setup result
 */
static void
twitterBegin(ForeignScanState *node, int eflags)
{
	CURL		   *curl;
	int				ret;
	json_parser		parser;
	json_parser_dom helper;
	ResultRoot	   *root;
	Relation		rel;
	AttInMetadata  *attinmeta;
	TwitterReply   *reply;
	StringInfoData	url;
	char		   *param_q = NULL;

	/*
	 * Do nothing in EXPLAIN
	 */
	if (eflags & EXEC_FLAG_EXPLAIN_ONLY)
		return;

	initStringInfo(&url);
	appendStringInfoString(&url, "http://search.twitter.com/search.json");

	if (node->ss.ps.plan->qual)
	{
		bool		param_first = true;
		ListCell   *lc;
		List	   *quals = list_copy(node->ss.ps.qual);

		foreach (lc, quals)
		{
			ExprState	   *state = lfirst(lc);

			char *param = twitter_param((Node *) state->expr,
							node->ss.ss_currentRelation->rd_att);
			if (param)
			{
				if (param_first)
					appendStringInfoChar(&url, '?');
				else
					appendStringInfoChar(&url, '&');
				appendStringInfoString(&url, param);
				if (param[0] == 'q' && param[1] == '=')
					param_q = &param[2];

				/* take it from original qual */
				node->ss.ps.qual = list_delete(node->ss.ps.qual, (void *) state);
			}
//			else
//				elog(ERROR, "Unknown qual");
		}
Ejemplo n.º 2
0
/*
 * @return fdw_private data
 */
static List *
extract_twitter_conditions(List *conditions, TupleDesc tupdesc)
{
	List		   *result;
	ListCell	   *l;
	StringInfoData	url;
	char		   *param_q;
	int			   *handle_clauses;
	int				clause_count;
	bool			param_first;

	result = NIL;
	initStringInfo(&url);
	appendStringInfoString(&url, SEARCH_ENDPOINT);
	param_q = NULL;
	handle_clauses = (int *) palloc0(sizeof(int) * list_length(conditions));
	clause_count = -1;
	param_first = true;
	foreach (l, conditions)
	{
		RestrictInfo	   *cond = (RestrictInfo *) lfirst(l);
		char	   *param;

		param = twitter_param((Node *) cond->clause, tupdesc);
		if (param)
		{
			if (param_first)
				appendStringInfoChar(&url, '?');
			else
				appendStringInfoChar(&url, '&');
			appendStringInfoString(&url, param);
			param_first = false;
			if (param[0] == 'q' && param[1] == '=')
			{
				param_q = &param[2];
			}
			/* add more, if any */

			handle_clauses[++clause_count] = PUSHDOWN;
		}
		else
			handle_clauses[++clause_count] = FILTER_LOCALLY;
	}