Skip to content
This repository was archived by the owner on Feb 15, 2023. It is now read-only.

Commit cf24250

Browse files
committed
Merge branch '1.7' of https://github.com/jholtom-ciena/neo4j-fdw into jholtom-ciena-1.7
2 parents 528bede + 6611dec commit cf24250

File tree

7 files changed

+43
-41
lines changed

7 files changed

+43
-41
lines changed

README.adoc

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ This project is based on Multicorn, so you have to install it.
4646
NOTE: If you are using PG 9.1, you should use version 0.9.X version (`git checkout v0.9.3`)
4747
NOTE: If you are using PG 9.2, you should use version 1.0.X version (`git checkout v01.0.1`)
4848

49+
NOTE: If you are using Neo4j 1.7 drivers, you should use version 1.1.X version (`git checkout v01.1.2`)
50+
NOTE: If you are using Neo4j 4.X drivers, you should use version 1.2.X version (`git checkout v01.2`)
51+
Also, Neo4j 4.X drivers require python >= 3.5
52+
4953
----
5054
$> cd /tmp
5155
$> git clone git://github.com/Kozea/Multicorn.git

neo4jPg/neo4jfdw.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from multicorn import ForeignDataWrapper, Qual, ANY, ALL
88
from multicorn.utils import log_to_postgres, ERROR, WARNING, DEBUG, INFO
99
from neo4j import GraphDatabase, basic_auth, CypherError
10+
import neotime
1011

1112
class Neo4jForeignDataWrapper(ForeignDataWrapper):
1213
"""
@@ -283,10 +284,24 @@ def compute_table_stat(self):
283284
def convert_to_pg(self, column, value):
284285
"""
285286
Convert a value to a PG type.
286-
We do nothing for now, but can be usefull for the futur
287+
Most work implicitly, but neoTime.Time needs a helping hand when TimeZones are involved
287288
"""
288-
#log_to_postgres('Convert column:' + unicode(column), DEBUG)
289-
return value
289+
#log_to_postgres('Convert column:' + str(column), DEBUG)
290+
result = value
291+
292+
# we want a time with timezone
293+
if column.type_name == 'time with time zone':
294+
if isinstance(value, neotime.Time):
295+
try:
296+
tz = value.tzinfo # Take TimeZone directly, since str(neotime.Time) does not expose this
297+
if value.tzinfo is None :
298+
tz = pytz.utc
299+
parsed = parser.parse(str(value))
300+
result = datetime.time(parsed.hour, parsed.minute, parsed.second, parsed.microsecond, tz)
301+
302+
except ValueError as e:
303+
log_to_postgres('Value ' + str(value) + ' of type ' + str(type(value)) + ' can not be compared with a time field => ' + str(e), ERROR)
304+
return result
290305

291306
def convert_to_neo4j(self, column, value):
292307
"""

scripts/docker/postgres/Dockerfile

+2-17
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,14 @@ COPY . /neo4j-fdw/source
1010
RUN apt-get update \
1111
&& apt-get install -y --no-install-recommends \
1212
build-essential \
13+
postgresql-server-dev-10 \
1314
python-dev \
1415
python-setuptools \
1516
python-dev \
1617
python-pip \
18+
postgresql-plpython-10 \
1719
git \
18-
libfaketime \
19-
wget \
2020
&& rm -rf /var/lib/apt/lists/*
2121

22-
RUN cp /neo4j-fdw/source/scripts/faketime.sh /docker-entrypoint-initdb.d/
23-
24-
RUN mkdir /tmp/pgdebs \
25-
&& wget --quiet -P /tmp/pgdebs \
26-
https://atalia.postgresql.org/morgue/p/postgresql-10/postgresql-server-dev-10_10.10-1.pgdg90%2B1_amd64.deb \
27-
https://atalia.postgresql.org/morgue/p/postgresql-10/postgresql-plpython-10_10.10-1.pgdg90%2B1_amd64.deb \
28-
https://atalia.postgresql.org/morgue/p/postgresql-10/libpq5_10.10-1.pgdg90%2B1_amd64.deb \
29-
https://atalia.postgresql.org/morgue/p/postgresql-10/libpq-dev_10.10-1.pgdg90%2B1_amd64.deb \
30-
&& apt install -y --allow-downgrades \
31-
/tmp/pgdebs/postgresql-server-dev-10_10.10-1.pgdg90+1_amd64.deb \
32-
/tmp/pgdebs/postgresql-plpython-10_10.10-1.pgdg90+1_amd64.deb \
33-
/tmp/pgdebs/libpq5_10.10-1.pgdg90+1_amd64.deb \
34-
/tmp/pgdebs/libpq-dev_10.10-1.pgdg90+1_amd64.deb
35-
RUN rm -r /tmp/pgdebs
36-
3722
RUN ["chmod", "+x", "/neo4j-fdw/source/scripts/docker/postgres/init.sh"]
3823
RUN /neo4j-fdw/source/scripts/docker/postgres/init.sh

scripts/docker/postgres/init.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ if [ ! -d "/Multicorn" ]; then
88
fi
99
cd Multicorn
1010
git checkout tags/v1.3.4
11-
make && make install
11+
make PYTHON_OVERRIDE=python2.7 && make PYTHON_OVERRIDE=python2.7 install
12+
1213

1314
# Install neo4j fdw
1415
echo "~~~~~~~~~~~~~ Installing Neo4j FDW"
1516
cd /neo4j-fdw/source/
16-
make install
17+
make PYTHON=python2.7 install
18+

scripts/faketime.sh

-5
This file was deleted.

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
author_email = neo4jPg.__email__,
99
url = neo4jPg.__url__,
1010
packages = find_packages(),
11-
install_requires = [ 'neo4j-driver', 'python-dateutil' ]
11+
install_requires = [ 'neo4j-driver>=1.7,<2.0','neobolt==1.7.16', 'python-dateutil' ]
1212
)

test/expected/050_temporal_queries.out

+14-13
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
99
(0 rows)
1010
SELECT * FROM temporal WHERE temporal.my_date = (DATE '1983-03-26');
1111
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
12-
03-26-1983|12:45:30.25|12:45:30.25-07|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
12+
03-26-1983|12:45:30.25|12:45:30.25+01|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
1313
(1 row)
1414
SELECT * FROM temporal WHERE temporal.my_date < (DATE '1983-03-27');
1515
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
16-
03-26-1983|12:45:30.25|12:45:30.25-07|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
16+
03-26-1983|12:45:30.25|12:45:30.25+01|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
1717
(1 row)
1818
SELECT * FROM temporal WHERE temporal.my_date > (TIMESTAMP '1983-03-26 12:45:30');
1919
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
@@ -23,7 +23,7 @@ my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
2323
(0 rows)
2424
SELECT * FROM temporal WHERE temporal.my_date < (TIMESTAMP '1983-03-27 12:45:30');
2525
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
26-
03-26-1983|12:45:30.25|12:45:30.25-07|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
26+
03-26-1983|12:45:30.25|12:45:30.25+01|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
2727
(1 row)
2828
SELECT * FROM temporal WHERE temporal.my_date > (TIMESTAMPTZ '1983-03-26 12:45:30+01');
2929
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
@@ -33,30 +33,30 @@ my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
3333
(0 rows)
3434
SELECT * FROM temporal WHERE temporal.my_date < (TIMESTAMPTZ '1983-03-27 12:45:30+01');
3535
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
36-
03-26-1983|12:45:30.25|12:45:30.25-07|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
36+
03-26-1983|12:45:30.25|12:45:30.25+01|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
3737
(1 row)
3838
SELECT * FROM temporal WHERE temporal.my_date < (TIMESTAMPTZ '1983-03-26 20:45:30-05');
3939
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
4040
(0 rows)
4141
/* Datetime without TZ comparisons */
4242
SELECT * FROM temporal WHERE temporal.my_localdatetime > (DATE '1983-03-26');
4343
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
44-
03-26-1983|12:45:30.25|12:45:30.25-07|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
44+
03-26-1983|12:45:30.25|12:45:30.25+01|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
4545
(1 row)
4646
SELECT * FROM temporal WHERE temporal.my_localdatetime < (DATE '1983-03-27');
4747
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
48-
03-26-1983|12:45:30.25|12:45:30.25-07|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
48+
03-26-1983|12:45:30.25|12:45:30.25+01|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
4949
(1 row)
5050
SELECT * FROM temporal WHERE temporal.my_localdatetime < now();
5151
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
52-
03-26-1983|12:45:30.25|12:45:30.25-07|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
52+
03-26-1983|12:45:30.25|12:45:30.25+01|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
5353
(1 row)
5454
SELECT * FROM temporal WHERE temporal.my_localdatetime < (TIMESTAMP '1983-03-26 12:45:30');
5555
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
5656
(0 rows)
5757
SELECT * FROM temporal WHERE temporal.my_localdatetime < (TIMESTAMP '1983-03-26 12:45:31');
5858
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
59-
03-26-1983|12:45:30.25|12:45:30.25-07|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
59+
03-26-1983|12:45:30.25|12:45:30.25+01|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
6060
(1 row)
6161
SELECT * FROM temporal WHERE temporal.my_localdatetime < (TIMESTAMPTZ '1983-03-26 12:45:30+01');
6262
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
@@ -67,26 +67,26 @@ my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
6767
/* Datetime with TZ comparisons */
6868
SELECT * FROM temporal WHERE temporal.my_datetime > (DATE '1983-03-26');
6969
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
70-
03-26-1983|12:45:30.25|12:45:30.25-07|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
70+
03-26-1983|12:45:30.25|12:45:30.25+01|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
7171
(1 row)
7272
SELECT * FROM temporal WHERE temporal.my_datetime < (DATE '1983-03-26');
7373
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
7474
(0 rows)
7575
SELECT * FROM temporal WHERE temporal.my_datetime < now();
7676
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
77-
03-26-1983|12:45:30.25|12:45:30.25-07|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
77+
03-26-1983|12:45:30.25|12:45:30.25+01|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
7878
(1 row)
7979
SELECT * FROM temporal WHERE temporal.my_datetime < (TIMESTAMP '1983-03-26 12:45:30');
8080
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
81-
03-26-1983|12:45:30.25|12:45:30.25-07|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
81+
03-26-1983|12:45:30.25|12:45:30.25+01|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
8282
(1 row)
8383
SELECT * FROM temporal WHERE temporal.my_datetime < (TIMESTAMPTZ '1983-03-26 12:45:30+01');
8484
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
8585
(0 rows)
8686
/* Time with TZ comparisons */
8787
SELECT * FROM temporal WHERE temporal.my_localtime = (TIME '12:45:30.25');
8888
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
89-
03-26-1983|12:45:30.25|12:45:30.25-07|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
89+
03-26-1983|12:45:30.25|12:45:30.25+01|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
9090
(1 row)
9191
SELECT * FROM temporal WHERE temporal.my_localtime < (TIME '12:45:30.25');
9292
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
@@ -109,4 +109,5 @@ my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
109109
(0 rows)
110110
SELECT * FROM temporal WHERE temporal.my_time < (TIMETZ '13:46:30.25+01');
111111
my_date|my_localtime|my_time|my_datetime|my_localdatetime|my_duration
112-
(0 rows)
112+
03-26-1983|12:45:30.25|12:45:30.25+01|Sat Mar 26 03:45:30.25 1983 PST|Sat Mar 26 12:45:30.25 1983|@ 1 year 2 mons 10 days 12 hours 45 mins 30.25 secs
113+
(1 row)

0 commit comments

Comments
 (0)