### 簡介
> Presto是一個分布式的查詢引擎,本身并不存儲數據,但是可以接入多種數據源,并且支持跨數據源的級聯查詢。Presto是一個OLAP的工具,擅長對海量數據進行復雜的分析;但是對于OLTP場景,并不是Presto所擅長,所以不要把Presto當做數據庫來使用。
> 和大家熟悉的Mysql相比:首先Mysql是一個數據庫,具有存儲和計算分析能力,而Presto只有計算分析能力;其次數據量方面,Mysql作為傳統單點關系型數據庫不能滿足當前大數據量的需求,于是有各種大數據的存儲和分析工具產生,Presto就是這樣一個可以滿足大數據量分析計算需求的一個工具。
### 結合`SQLAlchemy`
```python
# encoding:utf-8
'''
@author: mill
@project: demos
@file: presto.py
@time: 2019/6/5 14:07
@desc:
'''
import operator
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String,Date,TIMESTAMP
from sqlalchemy.engine import create_engine
# Presto
engine = create_engine('presto://ip:port/hive/schema')
Base = declarative_base()
# df = pd.read_sql("select * from voice limit 10000",engine)
# print(df)
class Voice(Base):
__tablename__ = 'voice'
type = Column(String)
bphonenum = Column(String,primary_key=True)
dphonenum = Column(String)
starttime = Column(TIMESTAMP)
call_time = Column(String)
# yiwang=Column(String)
# shijian=Column(Date)
Session = sessionmaker(bind=engine)
session = Session()
# print(session.query(Voice).count())
# print(session.query(Voice).filter(Voice.type =='主叫').count())
result = session.query(Voice).slice(0,100).all()
for item in result:
print(item.type)
```