prestogres 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/ChangeLog +7 -0
- data/README.md +8 -28
- data/VERSION +1 -1
- data/pgpool2/pool_query_context.c +16 -4
- data/pgsql/presto_client.py +9 -4
- data/pgsql/prestogres.py +6 -2
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjJjMjIxNzdkNjI5MWVlZjJkNmUzNTUyNWMxMmJmZWZhZmIwZjRkMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmY0NDlkZjM4N2ZlODg3MjFmNGNiNzcyYmUyMTk2NmQ3NjcxYTlhNQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2YyOGIwZjVjNDUwNjFhMzViMjdkYTI5YWIxODhiZTJhZDM2ODA0NjNhNTE1
|
10
|
+
NTg5YWYzMzE5N2U1ODI2ZTYxOGFjODRmOTQ3OTQ5ZGI0Y2U5YmRmZjhmYWI2
|
11
|
+
ZTI4Nzk5NDU1MmI5NDc0ZDgwZmJmNjcxYWVhOThlNmM2MzBhMWE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzRkOWQ5NjFiNjNlYzg1Y2E5NmQ1ZjE4NzdmYmJhODNjZjVmMTgyMWU0ZjFh
|
14
|
+
ZmY0YWY0ZmZiZmE0OGM1NzY1YjJmZjMzMDlhZmY2MTc5NzEzMDcwNzQ0YzM1
|
15
|
+
OGM4MDgwZWNkNzJjMjFlN2ZmY2Q4NmRjZTQwMzkwMTlhODBjYTM=
|
data/ChangeLog
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
|
2
|
+
2014-05-12 version 0.4.4:
|
3
|
+
|
4
|
+
* Send session variable 'timezone' to Presto using X-Presto-Time-Zone HTTP
|
5
|
+
header introduced by Presto 0.66 so that Presto uses the same time zone
|
6
|
+
setting with PostgreSQL.
|
7
|
+
|
8
|
+
|
2
9
|
2014-04-22 version 0.4.3:
|
3
10
|
|
4
11
|
* Updated default parameters related to connections so that pgpool-II can
|
data/README.md
CHANGED
@@ -36,7 +36,7 @@ Prestogres also offers password-based authentication and SSL.
|
|
36
36
|
## How it works?
|
37
37
|
|
38
38
|
Prestogres uses modified **[pgpool-II](http://www.pgpool.net/)** to rewrite queries before sending them to PostgreSQL.
|
39
|
-
pgpool-II is originally an open-source middleware to provide connection pool and other features to PostgreSQL. For regular SQL query, patched pgpool-II wraps it in **
|
39
|
+
pgpool-II is originally an open-source middleware to provide connection pool and other features to PostgreSQL. For regular SQL query, patched pgpool-II wraps it in **run_presto_as_temp_table(..., 'SELECT ... FROM ...')** function. This function sends the query to Presto:
|
40
40
|
|
41
41
|
![Regular SQL](https://gist.github.com/frsyuki/9012980/raw/2782f51cd3c708254ac64c4c30b7bff0e7894640/figure1.png)
|
42
42
|
|
@@ -188,14 +188,12 @@ See [sample pool_hba.conf file](https://github.com/treasure-data/prestogres/blob
|
|
188
188
|
|
189
189
|
```conf
|
190
190
|
# TYPE DATABASE USER CIDR-ADDRESS METHOD OPTIONS
|
191
|
-
host postgres pg 127.0.0.1/32 trust
|
192
|
-
host postgres pg 127.0.0.1/32,192.168.0.0/16 prestogres_md5
|
193
|
-
host altdb pg 0.0.0.0/0 prestogres_md5 server:localhost:8190,
|
194
|
-
host all all 0.0.0.0/0 prestogres_external auth_prog:/opt/prestogres/auth.py
|
191
|
+
host postgres pg 127.0.0.1/32 trust pg_database:postgres,pg_user:pg
|
192
|
+
host postgres pg 127.0.0.1/32,192.168.0.0/16 prestogres_md5 pg_database:postgres,pg_user:pg
|
193
|
+
host altdb pg 0.0.0.0/0 prestogres_md5 pg_database:postgres,pg_user:pg,server:localhost:8190,
|
194
|
+
host all all 0.0.0.0/0 prestogres_external pg_database:postgres,pg_user:pg,auth_prog:/opt/prestogres/auth.py
|
195
195
|
```
|
196
196
|
|
197
|
-
See also *Creating database* section.
|
198
|
-
|
199
197
|
#### prestogres_md5 method
|
200
198
|
|
201
199
|
This authentication method uses a password file **\<data_dir\>/pgpool2/pool_passwd** to authenticate an user. You can use `prestogres passwd` command to add an user to this file:
|
@@ -211,13 +209,13 @@ In pool_hba.conf file, you can set following options to OPTIONS field:
|
|
211
209
|
* **catalog**: Catalog (connector) name of Presto, which overwrites `presto_catalog` parameter in pgpool.conf.
|
212
210
|
* **schema**: Default schema name of Presto. By default, Prestogres uses the same name with the database name used to login to pgpool-II. Following `pg_database` parameter doesn't overwrite affect this parameter.
|
213
211
|
* **user**: User name to run queries on Presto. By default, Prestogres uses the same user name used to login to pgpool-II. Following `pg_user` parameter doesn't overwrite affect this parameter.
|
214
|
-
* **pg_database**: Overwrite database to connect to PostgreSQL.
|
215
|
-
* **pg_user**: Overwrite user name to connect to PostgreSQL.
|
212
|
+
* **pg_database**: Overwrite database to connect to PostgreSQL. The value should be `postgres` in most of cases.
|
213
|
+
* **pg_user**: Overwrite user name to connect to PostgreSQL. This value should be `pg` in most of cases.
|
216
214
|
|
217
215
|
|
218
216
|
#### prestogres_external method
|
219
217
|
|
220
|
-
This authentication method uses an external
|
218
|
+
This authentication method uses an external program to authentication an user.
|
221
219
|
|
222
220
|
- Note: This method is still experimental (because performance is slow). Interface could be changed.
|
223
221
|
- Note: This method requires clients to send password in clear text. It's recommended to enable SSL in pgpool.conf.
|
@@ -248,24 +246,6 @@ See *pgool.conf file* section for available parameters.
|
|
248
246
|
|
249
247
|
If you want to reject this connection, the program exists with non-0 status code.
|
250
248
|
|
251
|
-
### Creating database on PostgreSQL
|
252
|
-
|
253
|
-
Prestogres setups a database named *postgres* on PostgreSQL by default. But you may want to create other databases
|
254
|
-
to take advantage of above authentication mechanism.
|
255
|
-
|
256
|
-
To create new databases:
|
257
|
-
|
258
|
-
1. Create a new PostgreSQL database using `createdb` command. Port number is **6432** because you login to PostgreSQL directly:
|
259
|
-
```
|
260
|
-
$ createdb -h localhost -p 6432 -U pg newdb
|
261
|
-
```
|
262
|
-
|
263
|
-
2. Initialize the database using statements shown by `prestogres show_init_sql` command:
|
264
|
-
```
|
265
|
-
$ prestogres show_init_sql | psql -h localhost -p 6432 -U pg newdb
|
266
|
-
```
|
267
|
-
|
268
|
-
|
269
249
|
### prestogres command
|
270
250
|
|
271
251
|
Usage of `prestogres` command:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.4
|
@@ -410,6 +410,14 @@ static void rewrite_error_query(POOL_QUERY_CONTEXT* query_context, char *message
|
|
410
410
|
/* 20 is for escape characters */
|
411
411
|
const size_t static_length = strlen("do $$ begin raise exception '%', E'' using errcode = E'XXXXX'; end $$ language plpgsql") + 20;
|
412
412
|
|
413
|
+
if (message == NULL) {
|
414
|
+
message = "Unknown exception";
|
415
|
+
}
|
416
|
+
|
417
|
+
if (errcode == NULL) {
|
418
|
+
message = "XX000"; /* Internal Error */
|
419
|
+
}
|
420
|
+
|
413
421
|
if (sizeof(rewrite_query_string_buffer) < strlen(message) + static_length) {
|
414
422
|
message[sizeof(rewrite_query_string_buffer) - static_length - 3] = '.';
|
415
423
|
message[sizeof(rewrite_query_string_buffer) - static_length - 2] = '.';
|
@@ -453,10 +461,12 @@ static void run_and_rewrite_system_catalog_query(POOL_SESSION_CONTEXT* session_c
|
|
453
461
|
rewrite_query_string_buffer, &res, MAJOR(backend), &errmsg, &errcode);
|
454
462
|
free_select_result(res);
|
455
463
|
|
456
|
-
if (errmsg != NULL) {
|
464
|
+
if (errmsg != NULL || errcode != NULL) {
|
457
465
|
rewrite_error_query(query_context, errmsg, errcode);
|
466
|
+
return;
|
458
467
|
} else if (status != POOL_CONTINUE) {
|
459
468
|
rewrite_error_query_static(query_context, "Unknown execution error", NULL);
|
469
|
+
return;
|
460
470
|
}
|
461
471
|
|
462
472
|
/* build run_system_catalog_as_temp_table query */
|
@@ -487,10 +497,12 @@ static void run_and_rewrite_system_catalog_query(POOL_SESSION_CONTEXT* session_c
|
|
487
497
|
rewrite_query_string_buffer, &res, MAJOR(backend), &errmsg, &errcode);
|
488
498
|
free_select_result(res);
|
489
499
|
|
490
|
-
if (errmsg != NULL) {
|
500
|
+
if (errmsg != NULL || errcode != NULL) {
|
491
501
|
rewrite_error_query(query_context, errmsg, errcode);
|
502
|
+
return;
|
492
503
|
} else if (status != POOL_CONTINUE) {
|
493
504
|
rewrite_error_query_static(query_context, "Unknown execution error", NULL);
|
505
|
+
return;
|
494
506
|
}
|
495
507
|
|
496
508
|
/* rewrite query */
|
@@ -631,7 +643,7 @@ static void run_and_rewrite_presto_query(POOL_SESSION_CONTEXT* session_context,
|
|
631
643
|
rewrite_query_string_buffer, &res, MAJOR(backend), &errmsg, &errcode);
|
632
644
|
free_select_result(res);
|
633
645
|
|
634
|
-
if (errmsg != NULL) {
|
646
|
+
if (errmsg != NULL || errcode != NULL) {
|
635
647
|
rewrite_error_query(query_context, errmsg, errcode);
|
636
648
|
return;
|
637
649
|
} else if (status != POOL_CONTINUE) {
|
@@ -663,7 +675,7 @@ void pool_where_to_send(POOL_QUERY_CONTEXT *query_context, char *query, Node *no
|
|
663
675
|
POOL_CONNECTION_POOL *backend;
|
664
676
|
int i;
|
665
677
|
|
666
|
-
const char* static_error_message;
|
678
|
+
const char* static_error_message = "";
|
667
679
|
enum {
|
668
680
|
REWRITE_CLEAR,
|
669
681
|
REWRITE_SYSTEM_CATALOG,
|
data/pgsql/presto_client.py
CHANGED
@@ -159,6 +159,8 @@ class PrestoHeaders(object):
|
|
159
159
|
PRESTO_SOURCE = "X-Presto-Source"
|
160
160
|
PRESTO_CATALOG = "X-Presto-Catalog"
|
161
161
|
PRESTO_SCHEMA = "X-Presto-Schema"
|
162
|
+
PRESTO_TIME_ZONE = "X-Presto-Time-Zone"
|
163
|
+
PRESTO_LANGUAGE = "X-Presto-Language"
|
162
164
|
|
163
165
|
PRESTO_CURRENT_STATE = "X-Presto-Current-State"
|
164
166
|
PRESTO_MAX_WAIT = "X-Presto-Max-Wait"
|
@@ -191,6 +193,10 @@ class StatementClient(object):
|
|
191
193
|
headers[PrestoHeaders.PRESTO_CATALOG] = self.options["catalog"]
|
192
194
|
if self.options.get("schema") is not None:
|
193
195
|
headers[PrestoHeaders.PRESTO_SCHEMA] = self.options["schema"]
|
196
|
+
if self.options.get("time_zone") is not None:
|
197
|
+
headers[PrestoHeaders.PRESTO_TIME_ZONE] = self.options["time_zone"]
|
198
|
+
if self.options.get("language") is not None:
|
199
|
+
headers[PrestoHeaders.PRESTO_LANGUAGE] = self.options["language"]
|
194
200
|
|
195
201
|
self.http_client.request("POST", "/v1/statement", self.query, headers)
|
196
202
|
response = self.http_client.getresponse()
|
@@ -273,8 +279,8 @@ class Query(object):
|
|
273
279
|
self.client = client
|
274
280
|
|
275
281
|
def _wait_for_data(self):
|
276
|
-
while self.client.
|
277
|
-
|
282
|
+
while self.client.results.data is None and self.client.advance():
|
283
|
+
pass
|
278
284
|
|
279
285
|
def columns(self):
|
280
286
|
self._wait_for_data()
|
@@ -300,10 +306,9 @@ class Query(object):
|
|
300
306
|
for row in client.results.data:
|
301
307
|
yield row
|
302
308
|
|
303
|
-
if not
|
309
|
+
if not client.advance():
|
304
310
|
break
|
305
311
|
|
306
|
-
client.advance()
|
307
312
|
if client.results.data is None:
|
308
313
|
break
|
309
314
|
|
data/pgsql/prestogres.py
CHANGED
@@ -149,6 +149,10 @@ class SchemaCache(object):
|
|
149
149
|
self.expire_time = expire_time
|
150
150
|
self.query_cache = {}
|
151
151
|
|
152
|
+
def _get_session_time_zone():
|
153
|
+
rows = plpy.execute("show timezone")
|
154
|
+
return rows[0].values()[0]
|
155
|
+
|
152
156
|
QueryResult = namedtuple("QueryResult", ("column_names", "column_types", "result"))
|
153
157
|
|
154
158
|
OidToTypeNameMapping = {}
|
@@ -170,7 +174,7 @@ SchemaCacheEntry = SchemaCache()
|
|
170
174
|
|
171
175
|
def run_presto_as_temp_table(server, user, catalog, schema, result_table, query):
|
172
176
|
try:
|
173
|
-
client = presto_client.Client(server=server, user=user, catalog=catalog, schema=schema)
|
177
|
+
client = presto_client.Client(server=server, user=user, catalog=catalog, schema=schema, time_zone=_get_session_time_zone())
|
174
178
|
|
175
179
|
create_sql = "create temporary table %s (\n " % plpy.quote_ident(result_table)
|
176
180
|
insert_sql = "insert into %s (\n " % plpy.quote_ident(result_table)
|
@@ -208,7 +212,7 @@ def run_presto_as_temp_table(server, user, catalog, schema, result_table, query)
|
|
208
212
|
|
209
213
|
def run_system_catalog_as_temp_table(server, user, catalog, schema, result_table, query):
|
210
214
|
try:
|
211
|
-
client = presto_client.Client(server=server, user=user, catalog=catalog, schema=schema)
|
215
|
+
client = presto_client.Client(server=server, user=user, catalog=catalog, schema=schema, time_zone=_get_session_time_zone())
|
212
216
|
|
213
217
|
# create SQL statements which put data to system catalogs
|
214
218
|
if SchemaCacheEntry.is_cached(server, user, catalog, schema, time.time()):
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prestogres
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sadayuki Furuhashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -484,4 +484,3 @@ signing_key:
|
|
484
484
|
specification_version: 4
|
485
485
|
summary: Presto PostgreSQL protocol gateway
|
486
486
|
test_files: []
|
487
|
-
has_rdoc: false
|