/
__init__.py
129 lines (104 loc) · 3.68 KB
/
__init__.py
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
# Copyright 2014 Cloudera Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# flake8: noqa
__version__ = '0.5.0'
from ibis.filesystems import HDFS, WebHDFS
from ibis.common import IbisError
import ibis.expr.api as api
import ibis.expr.types as ir
# __all__ is defined
from ibis.expr.api import *
import ibis.impala.api as impala
import ibis.sql.sqlite.api as sqlite
import ibis.config_init
from ibis.config import options
import ibis.util as util
# Deprecated
impala_connect = util.deprecate(impala.connect,
'impala_connect is deprecated, use'
' ibis.impala.connect instead')
def make_client(db, hdfs_client=None):
"""
Create an Ibis client from a database connection and optional additional
connections (like HDFS)
Parameters
----------
db : Connection
e.g. produced by ibis.impala.connect
hdfs_client : ibis HDFS client
Examples
--------
>>> con = ibis.impala.connect(**impala_params)
>>> hdfs = ibis.hdfs_connect(**hdfs_params)
>>> client = ibis.make_client(con, hdfs_client=hdfs)
Returns
-------
client : IbisClient
"""
db._hdfs = hdfs_client
return db
make_client = util.deprecate(
make_client, ('make_client is deprecated. '
'Use ibis.impala.connect '
' with hdfs_client=hdfs_client'))
def hdfs_connect(host='localhost', port=50070, protocol='webhdfs',
auth_mechanism='NOSASL', verify=True, **kwds):
"""
Connect to HDFS
Parameters
----------
host : string, Host name of the HDFS NameNode
port : int, NameNode's WebHDFS port (default 50070)
protocol : {'webhdfs'}
auth_mechanism : string, Set to NOSASL or PLAIN for non-secure clusters.
Set to GSSAPI or LDAP for Kerberos-secured clusters.
verify : boolean, Set to False to turn off verifying SSL certificates.
(default True)
Other keywords are forwarded to hdfs library classes
Returns
-------
client : WebHDFS
"""
import requests
session = kwds.setdefault('session', requests.Session())
session.verify = verify
if auth_mechanism in ['GSSAPI', 'LDAP']:
try:
import requests_kerberos
except ImportError:
raise IbisError(
"Unable to import requests-kerberos, which is required for "
"Kerberos HDFS support. Install it by executing `pip install "
"requests-kerberos` or `pip install hdfs[kerberos]`.")
from hdfs.ext.kerberos import KerberosClient
url = 'https://{0}:{1}'.format(host, port) # note SSL
kwds.setdefault('mutual_auth', 'OPTIONAL')
hdfs_client = KerberosClient(url, **kwds)
else:
from hdfs.client import InsecureClient
url = 'http://{0}:{1}'.format(host, port)
hdfs_client = InsecureClient(url, **kwds)
return WebHDFS(hdfs_client)
def test(impala=False):
import pytest
import ibis
import os
ibis_dir, _ = os.path.split(ibis.__file__)
args = ['--pyargs', ibis_dir]
if impala:
args.append('--impala')
pytest.main(args)
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions