Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

header clean up

  • Loading branch information...
commit 77cf10ea235f40dfb781474dc2acc766937dbca8 1 parent 71247f5
@ZhengYang authored
Showing with 162 additions and 141 deletions.
  1. +2 −141 couchdb_fdw.c
  2. +160 −0 couchdb_fdw.h
View
143 couchdb_fdw.c
@@ -42,6 +42,8 @@
#include <yajl/yajl_common.h>
#include <yajl/yajl_gen.h>
+#include "couchdb_fdw.h"
+
PG_MODULE_MAGIC;
#define PROCID_TEXTEQ 67
@@ -52,99 +54,7 @@ PG_MODULE_MAGIC;
static int BUFFER_SIZE = 5;
-/*
- * information for ForeignScanState.fdw_state
- */
-typedef struct CouchDBFdwExecutionState
-{
- /* A index pointing to current id to retrieve */
- int cursor;
- AttInMetadata *attinmeta;
- char *address;
- int port;
- char *database;
- char *username;
- char *password;
- int buffer_size;
- StringInfoData *id_buffer;
- StringInfoData *columns;
- int num_of_columns;
- long long int total_rows;
- long long int offset;
- List *qual_list;
- bool qual_scanned;
-} CouchDBFdwExecutionState;
-
-/*
- * Context used to
- */
-typedef struct context
-{
- int level;
- int current_index;
- char *map_key;
- /*
- * TODO: change it to enum.
- * This stores which RESTful service are we sending,
- * so that diff parsing rules will be applied in the call back
- */
- int request_type;
-} context;
-
-typedef struct dbsize_context
-{
- long int doc_count;
- char *map_key;
-} dbsize_context;
-
-typedef struct alldocs_context
-{
- char *map_key;
- long long int total_rows;
- long long int offset;
- int counter;
- StringInfoData *ids;
-} alldocs_context;
-
-typedef struct doc_context
-{
- int depth;
- int column_index;
- int num_of_columns;
- char *map_key;
- StringInfoData *column_list;
- StringInfoData *column_data;
- yajl_gen gen;
- yajl_gen doc_gen;
- yajl_alloc_funcs *funcs;
-} doc_context;
-
-typedef struct couch_doc
-{
- char *doc_id;
- char *doc_rev;
- char *doc;
-} couch_doc;
-
-typedef struct curl_data
-{
- char *doc;
- yajl_handle *handle;
-} curl_data;
-
-
-
-
-
-/*
- * FDW option
- */
-struct CouchDBFdwOption
-{
- const char *optname;
- Oid optcontext;
-};
/*
* Array of valid options, the rest will be assumed as column->json attribute mapping.
@@ -178,56 +88,7 @@ PG_FUNCTION_INFO_V1(couchdb_fdw_validator);
static void couchdbGetDatabaseSize(const char *address, const int port, const char *database,
const char *username, const char *password, int *dbsize);
-/*
- * FDW callback routines
- */
-static FdwPlan *couchdbPlanForeignScan(Oid foreigntableid, PlannerInfo *root, RelOptInfo *baserel);
-static void couchdbExplainForeignScan(ForeignScanState *node, ExplainState *es);
-static void couchdbBeginForeignScan(ForeignScanState *node, int eflags);
-static TupleTableSlot *couchdbIterateForeignScan(ForeignScanState *node);
-static void couchdbReScanForeignScan(ForeignScanState *node);
-static void couchdbEndForeignScan(ForeignScanState *node);
-
-/*
- * helper function
- */
-void* palloc_wrapper (void *ctx, size_t sz);
-void* repalloc_wrapper (void *ctx, void *ptr, size_t sz);
-void pfree_wrapper(void *ctx, void *ptr);
-static void couchdbGetQual(Node *node, TupleDesc tupdesc, List *col_mapping_list, char **key, char **value, bool *pushdown);
-static bool couchdbIsValidOption(const char *option, Oid context);
-
-/*
- * couchdb API wrappers
- */
-static int dbsize_handle_number(void * ctx, const char * s, size_t l);
-static int dbsize_handle_map_key(void * ctx, const unsigned char * stringVal, size_t stringLen);
-static size_t couchdbsize_writer(void *buffer, size_t size, size_t nmemb, void *userp);
-static void couchdbGetDoc(const char *address, const int port, const char *database,
- const char *username, const char *password, const char *id, const char *rev,
- StringInfoData *columns, const int col_size, StringInfoData **column_data);
-static size_t couchdbdoc_writer(void *buffer, size_t size, size_t nmemb, void *userp);
-static int alldocs_handle_map_key(void * ctx, const unsigned char * stringVal, size_t stringLen);
-static int alldocs_handle_string(void * ctx, const unsigned char * stringVal, size_t stringLen);
-static int alldocs_handle_number(void * ctx, const char * s, size_t l);
-static size_t alldocs_writer(void *buffer, size_t size, size_t nmemb, void *userp);
-static void couchdbGetAllDocs(const char *address, const int port, const char *database, const char *username, const char *password,
- const int limit, const char *startkey, const bool descending, StringInfoData *ids[],
- long long int *total_rows, long long int *offset);
-static int doc_handle_null(void * ctx);
-static int doc_handle_boolean(void * ctx, int boolean);
-static int doc_handle_integer(void *ctx, long long integerVal);
-static int doc_handle_double(void *ctx, double doubleVal);
-static int doc_handle_number(void * ctx, const char * s, size_t l);
-static int doc_handle_string(void * ctx, const unsigned char * stringVal,
- size_t stringLen);
-static int doc_handle_start_map (void *ctx);
-static int doc_handle_map_key(void *ctx, const unsigned char * stringVal,
- size_t stringLen);
-static int doc_handle_end_map(void * ctx);
-static int doc_handle_start_array(void * ctx);
-static int doc_handle_end_array(void * ctx);
void* palloc_wrapper (void *ctx, size_t sz)
{
View
160 couchdb_fdw.h
@@ -0,0 +1,160 @@
+/*----------------------------------------------------------
+ *
+ * foreign-data wrapper for CouchDB
+ *
+ * Copyright (c) 2011, PostgreSQL Global Development Group
+ *
+ * This software is released under the PostgreSQL Licence.
+ *
+ * Author: Zheng Yang <zhengyang4k@gmail.com>
+ *
+ * IDENTIFICATION
+ * couchdb_fdw/couchdb_fdw.h
+ *
+ *----------------------------------------------------------
+ */
+
+/*
+ * information for ForeignScanState.fdw_state
+ */
+
+typedef struct CouchDBFdwExecutionState
+{
+ /* A index pointing to current id to retrieve */
+ int cursor;
+ AttInMetadata *attinmeta;
+ char *address;
+ int port;
+ char *database;
+ char *username;
+ char *password;
+ int buffer_size;
+ StringInfoData *id_buffer;
+ StringInfoData *columns;
+ int num_of_columns;
+ long long int total_rows;
+ long long int offset;
+ List *qual_list;
+ bool qual_scanned;
+} CouchDBFdwExecutionState;
+
+/*
+ * Context used to
+ */
+typedef struct context
+{
+ int level;
+ int current_index;
+ char *map_key;
+ /*
+ * TODO: change it to enum.
+ * This stores which RESTful service are we sending,
+ * so that diff parsing rules will be applied in the call back
+ */
+ int request_type;
+} context;
+
+typedef struct dbsize_context
+{
+ long int doc_count;
+ char *map_key;
+} dbsize_context;
+
+typedef struct alldocs_context
+{
+ char *map_key;
+ long long int total_rows;
+ long long int offset;
+ int counter;
+ StringInfoData *ids;
+} alldocs_context;
+
+typedef struct doc_context
+{
+ int depth;
+ int column_index;
+ int num_of_columns;
+ char *map_key;
+ StringInfoData *column_list;
+ StringInfoData *column_data;
+ yajl_gen gen;
+ yajl_gen doc_gen;
+ yajl_alloc_funcs *funcs;
+} doc_context;
+
+typedef struct couch_doc
+{
+ char *doc_id;
+ char *doc_rev;
+ char *doc;
+} couch_doc;
+
+typedef struct curl_data
+{
+ char *doc;
+ yajl_handle *handle;
+} curl_data;
+
+
+
+
+
+/*
+ * FDW option
+ */
+struct CouchDBFdwOption
+{
+ const char *optname;
+ Oid optcontext;
+};
+
+/*
+ * FDW callback routines
+ */
+static FdwPlan *couchdbPlanForeignScan(Oid foreigntableid, PlannerInfo *root, RelOptInfo *baserel);
+static void couchdbExplainForeignScan(ForeignScanState *node, ExplainState *es);
+static void couchdbBeginForeignScan(ForeignScanState *node, int eflags);
+static TupleTableSlot *couchdbIterateForeignScan(ForeignScanState *node);
+static void couchdbReScanForeignScan(ForeignScanState *node);
+static void couchdbEndForeignScan(ForeignScanState *node);
+
+/*
+ * helper function
+ */
+void* palloc_wrapper (void *ctx, size_t sz);
+void* repalloc_wrapper (void *ctx, void *ptr, size_t sz);
+void pfree_wrapper(void *ctx, void *ptr);
+static void couchdbGetQual(Node *node, TupleDesc tupdesc, List *col_mapping_list, char **key, char **value, bool *pushdown);
+static bool couchdbIsValidOption(const char *option, Oid context);
+
+/*
+ * couchdb API wrappers
+ */
+
+static int dbsize_handle_number(void * ctx, const char * s, size_t l);
+static int dbsize_handle_map_key(void * ctx, const unsigned char * stringVal, size_t stringLen);
+static size_t couchdbsize_writer(void *buffer, size_t size, size_t nmemb, void *userp);
+static void couchdbGetDoc(const char *address, const int port, const char *database,
+ const char *username, const char *password, const char *id, const char *rev,
+ StringInfoData *columns, const int col_size, StringInfoData **column_data);
+static size_t couchdbdoc_writer(void *buffer, size_t size, size_t nmemb, void *userp);
+static int alldocs_handle_map_key(void * ctx, const unsigned char * stringVal, size_t stringLen);
+static int alldocs_handle_string(void * ctx, const unsigned char * stringVal, size_t stringLen);
+static int alldocs_handle_number(void * ctx, const char * s, size_t l);
+static size_t alldocs_writer(void *buffer, size_t size, size_t nmemb, void *userp);
+static void couchdbGetAllDocs(const char *address, const int port, const char *database, const char *username, const char *password,
+ const int limit, const char *startkey, const bool descending, StringInfoData *ids[],
+ long long int *total_rows, long long int *offset);
+static int doc_handle_null(void * ctx);
+static int doc_handle_boolean(void * ctx, int boolean);
+static int doc_handle_integer(void *ctx, long long integerVal);
+static int doc_handle_double(void *ctx, double doubleVal);
+static int doc_handle_number(void * ctx, const char * s, size_t l);
+static int doc_handle_string(void * ctx, const unsigned char * stringVal,
+ size_t stringLen);
+static int doc_handle_start_map (void *ctx);
+static int doc_handle_map_key(void *ctx, const unsigned char * stringVal,
+ size_t stringLen);
+static int doc_handle_end_map(void * ctx);
+static int doc_handle_start_array(void * ctx);
+static int doc_handle_end_array(void * ctx);
Please sign in to comment.
Something went wrong with that request. Please try again.