mirror of
https://github.com/tencentmusic/cube-studio.git
synced 2024-11-27 05:33:10 +08:00
feat(jupyter-notebook):add hive and impyla examples to bigdata
This commit is contained in:
parent
7952ee7eb3
commit
52dfc9707e
@ -0,0 +1,62 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "2e9ff853-1e15-4889-beb6-58a5c00ed0b1",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 介绍\n",
|
||||
"Python连接Impala\n",
|
||||
"### 安装依赖\n",
|
||||
"```\n",
|
||||
"pip install impyla\n",
|
||||
"```"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "64b7006b-fd16-4957-814a-ef9231338733",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from impala.dbapi import connect\n",
|
||||
"conn = connect(host='10.0.2.21',port = 10000,auth_mechanism='NOSASL')\n",
|
||||
"cur=conn.cursor()\n",
|
||||
"cur.execute('show databases')\n",
|
||||
"print(cur.fetchall())\n",
|
||||
"cur.close()\n",
|
||||
"conn.close()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "72c28438-0355-47a6-82be-e321b4f358fc",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.14"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "22ad6278-a725-4892-8da6-8bb1083cfad0",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"source": [
|
||||
"### 1.介绍\n",
|
||||
"使用pyhive连接远程hiveserver2\n",
|
||||
"\n",
|
||||
"### 2.安装依赖\n",
|
||||
"```\n",
|
||||
"pip install pyhive thrift sasl thrift_sasl\n",
|
||||
"```\n",
|
||||
"### 3.使用模式\n",
|
||||
"```\n",
|
||||
"NOSASL\n",
|
||||
"```\n",
|
||||
"### 4.配置hive-site.yml\n",
|
||||
"```xml\n",
|
||||
"<property>\n",
|
||||
" <name>hive.server2.authentication</name>\n",
|
||||
" <value>NOSASL</value>\n",
|
||||
" <description>\n",
|
||||
" Expects one of [nosasl, none, ldap, kerberos, pam, custom].\n",
|
||||
" Client authentication types.\n",
|
||||
" NONE: no authentication check\n",
|
||||
" LDAP: LDAP/AD based authentication\n",
|
||||
" KERBEROS: Kerberos/GSSAPI authentication\n",
|
||||
" CUSTOM: Custom authentication provider\n",
|
||||
" (Use with property hive.server2.custom.authentication.class)\n",
|
||||
" PAM: Pluggable authentication module\n",
|
||||
" NOSASL: Raw transport\n",
|
||||
" </description>\n",
|
||||
"</property>\n",
|
||||
"```"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f1c59347-83ac-4604-88cd-d11f0b306130",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pyhive\n",
|
||||
"from pyhive import hive\n",
|
||||
"import pandas as pd"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "c3244a4a-816f-4df9-89d0-ae1ec68e0e31",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"conn = hive.Connection(host = \"10.0.2.21\",port = 10000,database='default',auth='NOSASL')\n",
|
||||
"result = pd.read_sql(\"show tables\",conn)\n",
|
||||
"result"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "ff7d4567-a1ac-4133-a8f9-a83e36c1ed05",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cursor = conn.cursor()\n",
|
||||
"sql = \"create table tbl(id int,age int)\"\n",
|
||||
"cursor.execute(sql)\n",
|
||||
"result = cursor.fetchall()\n",
|
||||
"print(result)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "cbec08cb-3aec-42e0-9aac-0ef06dafb622",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"sql = \" select * from tbl\"\n",
|
||||
"cursor.execute(sql)\n",
|
||||
"result = cursor.fetchall()\n",
|
||||
"print(result)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "65028b92-f3b8-4853-8905-1632ea907253",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cursor.close()\n",
|
||||
"conn.close()"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.14"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
Loading…
Reference in New Issue
Block a user