Skip to content

Commit c0e266b

Browse files
committed
Test fixes
- add a build that dynamically pulls latest packages - pin CDH in all other builds - move more of setup to script so it's easier to test outside Travis - move Hive warehouse to a persistent directory - switch hive-cdh5 with hive-hadoop2, since the former is deprecated - sleep after metastore installation to fix CDH 5.11 build - fix compatibility with latest Presto
1 parent e3ecad1 commit c0e266b

File tree

10 files changed

+76
-47
lines changed

10 files changed

+76
-47
lines changed

.travis.yml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,23 @@ language: python
33
matrix:
44
include:
55
# https://docs.python.org/devguide/#status-of-python-branches
6-
# newest dependencies + a few python versions
6+
# One build pulls latest versions dynamically
77
- python: 3.6
8-
env: CDH=cdh5 PRESTO=0.147 SQLALCHEMY=1.0.12
8+
env: CDH=cdh5 CDH_VERSION=5 PRESTO=RELEASE SQLALCHEMY=sqlalchemy
9+
# Others use pinned versions.
910
- python: 3.5
10-
env: CDH=cdh5 PRESTO=0.147 SQLALCHEMY=1.0.12
11+
env: CDH=cdh5 CDH_VERSION=5.10.1 PRESTO=0.147 SQLALCHEMY=sqlalchemy==1.0.12
1112
- python: 3.4
12-
env: CDH=cdh5 PRESTO=0.147 SQLALCHEMY=1.0.12
13+
env: CDH=cdh5 CDH_VERSION=5.10.1 PRESTO=0.147 SQLALCHEMY=sqlalchemy==1.0.12
1314
- python: 2.7
14-
env: CDH=cdh5 PRESTO=0.147 SQLALCHEMY=1.0.12
15+
env: CDH=cdh5 CDH_VERSION=5.10.1 PRESTO=0.147 SQLALCHEMY=sqlalchemy==1.0.12
1516
# stale stuff we're still using / supporting
1617
- python: 2.7
17-
env: CDH=cdh5 PRESTO=0.147 SQLALCHEMY=0.5.8
18+
env: CDH=cdh5 CDH_VERSION=5.10.1 PRESTO=0.147 SQLALCHEMY=sqlalchemy==0.5.8
1819
# exclude: python 3 against old libries
19-
before_install:
20+
install:
2021
- ./scripts/travis-install.sh
2122
- pip install codecov
22-
install:
23-
- pip install -e .
24-
- pip install sqlalchemy==$SQLALCHEMY
25-
- pip install -r dev_requirements.txt
2623
# sleep so Presto has time to start up. Otherwise we might get 'No nodes available to run query'
2724
script: sleep 10 && py.test -v
2825
after_success: codecov

pyhive/sqlalchemy_hive.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from sqlalchemy import exc
1515
from sqlalchemy import types
1616
from sqlalchemy import util
17+
# TODO shouldn't use mysql type
1718
from sqlalchemy.databases import mysql
1819
from sqlalchemy.engine import default
1920
import decimal

pyhive/sqlalchemy_presto.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from sqlalchemy import exc
1414
from sqlalchemy import types
1515
from sqlalchemy import util
16+
# TODO shouldn't use mysql type
17+
from sqlalchemy.databases import mysql
1618
from sqlalchemy.engine import default
1719
from sqlalchemy.sql import compiler
1820
import re
@@ -34,9 +36,12 @@ class PrestoIdentifierPreparer(compiler.IdentifierPreparer):
3436
except ImportError:
3537
from sqlalchemy.databases.mysql import MSBigInteger as BigInteger
3638
_type_map = {
37-
'bigint': BigInteger,
38-
'integer': types.Integer,
3939
'boolean': types.Boolean,
40+
'tinyint': mysql.MSTinyInteger,
41+
'smallint': types.SmallInteger,
42+
'integer': types.Integer,
43+
'bigint': BigInteger,
44+
'real': types.Float,
4045
'double': types.Float,
4146
'varchar': types.String,
4247
'timestamp': types.TIMESTAMP,
@@ -150,8 +155,16 @@ def get_indexes(self, connection, table_name, schema=None, **kw):
150155
col_names = []
151156
for row in rows:
152157
part_key = 'Partition Key'
153-
# Newer Presto moved this information from a column to the comment
154-
if (part_key in row and row[part_key]) or row['Comment'].startswith(part_key):
158+
# Presto puts this information in one of 3 places depending on version
159+
# - a boolean column named "Partition Key"
160+
# - a string in the "Comment" column
161+
# - a string in the "Extra" column
162+
is_partition_key = (
163+
(part_key in row and row[part_key])
164+
or row['Comment'].startswith(part_key)
165+
or ('Extra' in row and 'partition key' in row['Extra'])
166+
)
167+
if is_partition_key:
155168
col_names.append(row['Column'])
156169
if col_names:
157170
return [{'name': 'partition', 'column_names': col_names, 'unique': False}]

pyhive/tests/test_presto.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from __future__ import unicode_literals
99

1010
import contextlib
11+
import os
1112

1213
from pyhive import exc
1314
from pyhive import presto
@@ -44,13 +45,22 @@ def test_complex(self, cursor):
4445
for row in cursor.description:
4546
description.append((row[0], row[1].replace('<', '(').replace('>', ')')) + row[2:])
4647
# TODO Presto drops the union field
48+
if os.environ.get('PRESTO') == '0.147':
49+
tinyint_type = 'integer'
50+
smallint_type = 'integer'
51+
float_type = 'double'
52+
else:
53+
# some later version made these map to more specific types
54+
tinyint_type = 'tinyint'
55+
smallint_type = 'smallint'
56+
float_type = 'real'
4757
self.assertEqual(description, [
4858
('boolean', 'boolean', None, None, None, None, True),
49-
('tinyint', 'integer', None, None, None, None, True),
50-
('smallint', 'integer', None, None, None, None, True),
59+
('tinyint', tinyint_type, None, None, None, None, True),
60+
('smallint', smallint_type, None, None, None, None, True),
5161
('int', 'integer', None, None, None, None, True),
5262
('bigint', 'bigint', None, None, None, None, True),
53-
('float', 'double', None, None, None, None, True),
63+
('float', float_type, None, None, None, None, True),
5464
('double', 'double', None, None, None, None, True),
5565
('string', 'varchar', None, None, None, None, True),
5666
('timestamp', 'timestamp', None, None, None, None, True),
@@ -90,7 +100,7 @@ def test_cancel(self, cursor):
90100
"FROM many_rows a "
91101
"CROSS JOIN many_rows b "
92102
)
93-
self.assertIn(cursor.poll()['stats']['state'], ('PLANNING', 'RUNNING'))
103+
self.assertIn(cursor.poll()['stats']['state'], ('STARTING', 'PLANNING', 'RUNNING'))
94104
cursor.cancel()
95105
self.assertIsNone(cursor.poll())
96106

pyhive/tests/test_sqlalchemy_hive.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import contextlib
1616
import datetime
1717
import decimal
18-
import os
1918
import sqlalchemy.types
2019
import unittest
2120

@@ -170,7 +169,7 @@ def test_insert_select(self, engine, connection):
170169
expected = [(1,)]
171170
self.assertEqual(result, expected)
172171

173-
@unittest.skipIf(os.environ.get('SQLALCHEMY') == '0.5.8', "not supported on old sqlalchemy")
172+
@unittest.skipIf(sqlalchemy.__version__ == '0.5.8', "not supported on old sqlalchemy")
174173
@with_engine_connection
175174
def test_insert_values(self, engine, connection):
176175
table = Table('insert_test', MetaData(bind=engine),

scripts/travis-conf/hive/hive-site-ldap.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313
<name>fs.defaultFS</name>
1414
<value>file:///</value>
1515
</property>
16+
<!--
17+
TODO tests rely having result set column names unprefixed
18+
This could be improved by having an option to strip out prefixes when it would not result in
19+
ambiguity.
20+
-->
1621
<property>
17-
<name>hive.metastore.warehouse.dir</name>
18-
<value>/tmp/hive/warehouse</value>
22+
<name>hive.resultset.use.unique.column.names</name>
23+
<value>false</value>
1924
</property>
2025
<property>
2126
<name>hive.server2.authentication</name>
@@ -33,8 +38,4 @@
3338
<name>hive.server2.authentication.ldap.guidKey</name>
3439
<value>cn</value>
3540
</property>
36-
<property>
37-
<name>hive.resultset.use.unique.column.names</name>
38-
<value>false</value>
39-
</property>
4041
</configuration>

scripts/travis-conf/hive/hive-site.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
<name>fs.defaultFS</name>
1414
<value>file:///</value>
1515
</property>
16-
<property>
17-
<name>hive.metastore.warehouse.dir</name>
18-
<value>/tmp/hive/warehouse</value>
19-
</property>
2016
<!--
2117
TODO tests rely having result set column names unprefixed
2218
This could be improved by having an option to strip out prefixes when it would not result in
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
connector.name=hive-%CDH%
1+
connector.name=hive-hadoop2
22
hive.metastore.uri=thrift://localhost:9083

scripts/travis-install.sh

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#!/bin/bash -eux
22

3-
# FIXME cdh 5.11 broken for some reason
4-
echo 'deb [arch=amd64] https://archive.cloudera.com/cdh5/ubuntu/precise/amd64/cdh precise-cdh5.10.1 contrib
5-
deb-src https://archive.cloudera.com/cdh5/ubuntu/precise/amd64/cdh precise-cdh5.10.1 contrib' | sudo tee /etc/apt/sources.list.d/cloudera.list
6-
# sudo wget "http://archive.cloudera.com/$CDH/ubuntu/precise/amd64/cdh/cloudera.list" \
7-
# -O /etc/apt/sources.list.d/cloudera.list
3+
echo "deb [arch=amd64] https://archive.cloudera.com/${CDH}/ubuntu/precise/amd64/cdh precise-cdh${CDH_VERSION} contrib
4+
deb-src https://archive.cloudera.com/${CDH}/ubuntu/precise/amd64/cdh precise-cdh${CDH_VERSION} contrib" | sudo tee /etc/apt/sources.list.d/cloudera.list
85
sudo apt-get update
96

7+
sudo apt-get install -y oracle-java8-installer python-dev g++ libsasl2-dev maven
8+
sudo update-java-alternatives -s java-8-oracle
9+
1010
#
1111
# LDAP
1212
#
1313
sudo apt-get -y --no-install-suggests --no-install-recommends --force-yes install ldap-utils slapd
14-
sudo mkdir /tmp/slapd
14+
sudo mkdir -p /tmp/slapd
1515
sudo slapd -f $(dirname $0)/ldap_config/slapd.conf -h ldap://localhost:3389 &
1616
sleep 10
1717
sudo ldapadd -h localhost:3389 -D cn=admin,dc=example,dc=com -w test -f $(dirname $0)/../pyhive/tests/ldif_data/base.ldif
@@ -22,24 +22,36 @@ sudo ldapadd -h localhost:3389 -D cn=admin,dc=example,dc=com -w test -f $(dirnam
2222
#
2323

2424
sudo apt-get install -y --force-yes hive
25+
sudo mkdir -p /user/hive
26+
sudo chown hive:hive /user/hive
2527
sudo cp $(dirname $0)/travis-conf/hive/hive-site.xml /etc/hive/conf/hive-site.xml
26-
sudo -u hive mkdir /tmp/hive && sudo chmod 777 /tmp/hive
2728
sudo apt-get install -y --force-yes hive-metastore hive-server2
2829

30+
sleep 5
31+
2932
sudo -Eu hive $(dirname $0)/make_test_tables.sh
3033

3134
#
3235
# Presto
3336
#
3437

3538
sudo apt-get install -y python # Use python2 for presto server
36-
sudo apt-get install -y oracle-java8-installer
37-
sudo update-java-alternatives -s java-8-oracle
3839

39-
curl https://repo1.maven.org/maven2/com/facebook/presto/presto-server/$PRESTO/presto-server-$PRESTO.tar.gz \
40-
| tar zxf -
40+
mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.0:copy \
41+
-Dartifact=com.facebook.presto:presto-server:${PRESTO}:tar.gz \
42+
-DoutputDirectory=.
43+
tar -x -v -z -f presto-server-*.tar.gz
44+
rm -rf presto-server
45+
mv presto-server-*/ presto-server
4146

42-
cp -r $(dirname $0)/travis-conf/presto presto-server-$PRESTO/etc
43-
sed -i s/%CDH%/$CDH/g presto-server-$PRESTO/etc/catalog/hive.properties
47+
cp -r $(dirname $0)/travis-conf/presto presto-server/etc
48+
49+
/usr/bin/python2.7 presto-server/bin/launcher.py start
50+
51+
#
52+
# Python
53+
#
4454

45-
/usr/bin/python2.7 presto-server-$PRESTO/bin/launcher.py start
55+
pip install $SQLALCHEMY
56+
pip install -e .
57+
pip install -r dev_requirements.txt

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ flake8-max-line-length = 100
1111
flake8-ignore =
1212
TCLIService/*.py ALL
1313
pyhive/sqlalchemy_backports.py ALL
14-
presto-server-*/** ALL
14+
presto-server/** ALL
1515
pyhive/hive.py F405
1616
pyhive/presto.py F405

0 commit comments

Comments
 (0)