forked from EnterpriseDB/hdfs_fdw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhdfs_fdw.h
182 lines (149 loc) · 6.41 KB
/
hdfs_fdw.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*-------------------------------------------------------------------------
*
* hdfs_fdw.h
* Foreign-data wrapper for remote Hadoop servers
*
* Portions Copyright (c) 2012-2014, PostgreSQL Global Development Group
*
* Portions Copyright (c) 2004-2014, EnterpriseDB Corporation.
*
* IDENTIFICATION
* hdfs_fdw.h
*
*-------------------------------------------------------------------------
*/
#ifndef HADOOP_FDW_H
#define HADOOP_FDW_H
#include "libhive/jdbc/hiveclient.h"
#include "foreign/foreign.h"
#include "lib/stringinfo.h"
#include "nodes/relation.h"
#include "utils/rel.h"
#include "access/htup.h"
/* Default connection parameters */
/* Default Hive database name */
static const char* DEFAULT_DATABASE = "default";
/* Default Hive Server host */
static const char* DEFAULT_HOST = "localhost";
/* Default Hive Server port */
static const char* DEFAULT_PORT = "10000";
/*
* Options structure to store the HDFS server information */
typedef struct hdfs_opt
{
int port; /* HDFS port number */
char *host; /* HDFS server IP address */
char *username; /* HDFS user name */
char *password; /* HDFS password */
char *principal; /* HDFS kerberos principal */
char *dbname; /* HDFS database name */
char *table_name; /* HDFS table name */
CLIENT_TYPE client_type;
AUTH_TYPE auth_type;
bool use_remote_estimate;
int connect_timeout;
int receive_timeout;
int fetch_size;
bool log_remote_sql;
} hdfs_opt;
typedef struct hdfsFdwExecutionState
{
char *query;
MemoryContext batch_cxt;
bool query_executed;
int con_index;
Relation rel; /* relcache entry for the foreign table */
List *retrieved_attrs; /* list of retrieved attribute numbers */
/* for remote query execution */
int numParams; /* number of parameters passed to query */
List *param_exprs; /* executable expressions for param values */
Oid *param_types; /* type of query parameters */
int rescan_count; /* Number of times a foreign scan is restarted */
} hdfsFdwExecutionState;
/*
* FDW-specific planner information kept in RelOptInfo.fdw_private for a
* foreign table. This information is collected by postgresGetForeignRelSize.
*/
typedef struct HDFSFdwRelationInfo
{
/* baserestrictinfo clauses, broken down into safe and unsafe subsets. */
List *remote_conds;
List *local_conds;
/* Bitmap of attr numbers we need to fetch from the remote server. */
Bitmapset *attrs_used;
/* Cost and selectivity of local_conds. */
QualCost local_conds_cost;
Selectivity local_conds_sel;
/* Estimated size and cost for a scan with baserestrictinfo quals. */
double rows;
int width;
Cost startup_cost;
Cost total_cost;
/* Options extracted from catalogs. */
Cost fdw_startup_cost;
Cost fdw_tuple_cost;
/* Cached catalog information. */
ForeignTable *table;
ForeignServer *server;
UserMapping *user; /* only set in use_remote_estimate mode */
} HDFSFdwRelationInfo;
/*
* Execution state of a foreign scan using postgres_fdw.
*/
typedef struct HDFSFdwScanState
{
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 */
/* for remote query execution */
int numParams; /* number of parameters passed to query */
List *param_exprs; /* executable expressions for param values */
Oid *param_types; /* type of query parameters */
/* working memory contexts */
MemoryContext batch_cxt; /* context holding current batch of tuples */
} 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 */
} 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 */
int hdfs_get_connection(ForeignServer *server, UserMapping *user, hdfs_opt *opt);
void hdfs_rel_connection(int con_index);
/* Functions prototypes for hdfs_deparse.c file */
extern void hdfs_deparse_select(hdfs_opt *opt, StringInfo buf, PlannerInfo *root, RelOptInfo *baserel, Bitmapset *attrs_used, List **retrieved_attrs);
extern void hdfs_append_where_clause(hdfs_opt *opt, StringInfo buf, PlannerInfo *root, RelOptInfo *baserel, List *exprs, bool is_first, List **params);
extern void classifyConditions(PlannerInfo *root, RelOptInfo *baserel, List *input_conds, List **remote_conds, List **local_conds);
extern bool is_foreign_expr(PlannerInfo *root, RelOptInfo *baserel, Expr *expr);
extern void deparseAnalyzeSql(hdfs_opt *opt, StringInfo buf, Relation rel, List **retrieved_attrs);
extern void deparseStringLiteral(StringInfo buf, const char *val);
void hdfs_deparse_describe(StringInfo buf, hdfs_opt *opt);
void hdfs_deparse_explain(hdfs_opt *opt, StringInfo buf,
PlannerInfo *root, RelOptInfo *baserel,
HDFSFdwRelationInfo *fpinfo);
void hdfs_deparse_analyze(StringInfo buf, hdfs_opt *opt);
double hdfs_find_row_count(char *src);
int hdfs_get_column_count(int con_index, hdfs_opt *opt);
int hdfs_fetch(int con_index, hdfs_opt *opt);
char* hdfs_get_field_as_cstring(int con_index, hdfs_opt *opt, int idx, bool *is_null);
Datum hdfs_get_value(int con_index, hdfs_opt *opt, Oid pgtyp, int pgtypmod,
int idx, bool *is_null);
bool hdfs_query_execute(int con_index, hdfs_opt *opt, char *query);
bool hdfs_query_prepare(int con_index, hdfs_opt *opt, char *query);
bool hdfs_execute_prepared(int con_index);
bool hdfs_query_execute_utility(int con_index, hdfs_opt *opt, char *query);
void hdfs_close_result_set(int con_index, hdfs_opt *opt);
void hdfs_rewind_result_set(int con_index, hdfs_opt *opt);
double hdfs_rowcount(int con_index, hdfs_opt *opt, PlannerInfo *root,
RelOptInfo *baserel, HDFSFdwRelationInfo *fpinfo);
double hdfs_describe(int con_index, hdfs_opt *opt);
void hdfs_analyze(int con_index, hdfs_opt *opt);
bool hdfs_bind_var(int con_index, int param_index, Oid type,
Datum value, bool *isnull);
extern void _PG_init(void);
extern void _PG_fini(void);
#endif /* HADOOP_FDW_H */