美文网首页
presto 的安装与使用

presto 的安装与使用

作者: 一个懒散的人 | 来源:发表于2021-05-11 14:44 被阅读0次

    相关说明:

    Presto官网: Presto | Distributed SQL Query Engine for Big Data (prestodb.io)

    DeltaLake官网: Delta Lake - Reliable Data Lakes at Scale

    安装Presto:

    1. 安装文档链接如下:
      Deploying Presto — Presto 0.252 Documentation (prestodb.io)

    2. 中文描述:
      a. 下载presto-server-0.252.tar.gz,上传到Linux 服务器并重命名为presto
      b. 进入到presto目录,创建etc目录,命令如下:

    cd presto
    mkdir etc
    mkdir etc/catalog
    touch etc/node.properties
    touch etc/jvm.config
    touch etc/config.properties
    

    c. 添加属性

    1. node.properties添加以下属性,当然也可以根据官网的提示进行修改:
    node.environment=production  #节点名字,集群中这个名字要一样
    node.id=ffffffff-ffff-ffff-ffff-ffffffffffff #唯一标识,可以为其他的数字
    node.data-dir=/var/presto/data #数据目录
    
    1. jvm.config添加以下属性:
    -server
    -Xmx16G
    -XX:+UseG1GC
    -XX:G1HeapRegionSize=32M
    -XX:+UseGCOverheadLimit
    -XX:+ExplicitGCInvokesConcurrent
    -XX:+HeapDumpOnOutOfMemoryError
    -XX:+ExitOnOutOfMemoryError
    
    1. config.properties添加以下属性(这个是单机版的属性,如果是集群请参考官网):
    coordinator=true
    node-scheduler.include-coordinator=true
    http-server.http.port=8080
    query.max-memory=5GB
    query.max-memory-per-node=1GB
    query.max-total-memory-per-node=2GB
    discovery-server.enabled=true
    discovery.uri=http://example.net:8080
    
    1. catalog目录下是放置的连接器配置,需要根据自己的需要进行配置,连接器配置链接如下:
      Connectors — Presto 0.252 Documentation (prestodb.io)

    d. 下载 presto-cli-0.252-executable.jar 客户端jar包,上传到Linux服务器,并将jar包变为可执行环境,命令如下:

    chmod +x  presto-cli-0.252-executable.jar
    

    启动Presto

    1. 进入到presto/bin目录下,执行以下命令:
    bin/launcher start
    
    1. 客户端登录服务器,执行
    presto --server localhost:8080 --catalog hive --schema default
    # catalog 是catalog目录的连接器文件名,而非配置名称,很重要。
    # schema 相当于数据库,但并非是真正的数据库
    # 8080 是config.properties中配置的端口,自己根据需要改
    

    Presto整合Deltalake

    详细整合的步骤链接:Presto and Athena to Delta Lake integration — Delta Lake Documentation

    中文简化版Presto与DeltaLake整合过程如下:
    Step1. 通过SQL, Scala, Java, Python 其中之一生成Mainfest文件,具体如下:

    #SQL 生成方式
    GENERATE symlink_format_manifest FOR TABLE delta.`<path-to-delta-table>`
    
     #Scala 生成方式
    val deltaTable = DeltaTable.forPath(<path-to-delta-table>)
    deltaTable.generate("symlink_format_manifest")
    
    #Java生成方式
    DeltaTable deltaTable = DeltaTable.forPath(<path-to-delta-table>);
    deltaTable.generate("symlink_format_manifest");
    
    #Python生成方式
    deltaTable = DeltaTable.forPath(<path-to-delta-table>)
    deltaTable.generate("symlink_format_manifest")
    
    #注意:forPath 是要整合的数据路径,"symlink_format_manifest" 是固定的,不可更改
    

    Step2. 生成Presto表

    CREATE EXTERNAL TABLE mytable ([(col_name1 col_datatype1, ...)])
    [PARTITIONED BY (col_name2 col_datatype2, ...)]
    ROW FORMAT SERDE 'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'
    STORED AS INPUTFORMAT 'org.apache.hadoop.hive.ql.io.SymlinkTextInputFormat'
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
    LOCATION '<path-to-delta-table>/_symlink_format_manifest/'  -- location of the generated manifest
    

    注意1:Presto是无法生成外部表的,需要在Hive或者Spark中进行生成,生成的语句就是上面的语句,但是Athena 是可以直接生成外部表的

    注意2:在通过以上语句在Hive或者Spark中生成的表,可以直接在Presto直接使用,但在Hive中查出来的是为Null

    ===============================================================
    2021-06-16 更新

    通过以下命令进入到presto

    ./prestocli --server IP:Port --catalog hive
    # ip:安装有presto的地址
    # port:/etc/config.properties 中 http-server.http.port=port 的端口配置
    # catalog: /etc/catalog 下的hive.properties的文件名
    

    进入之后进行相关的操作需要指定schema,查看有多少个schema,使用以下命令

    show schemas;
    
    #显示结果如下:
    default            
    information_schema 
    test               
    (3 rows)
    Query 20210616_023139_00010_prehn, FINISHED, 3 nodes
    Splits: 36 total, 36 done (100.00%)
    0:00 [3 rows, 68B] [12 rows/s, 170B/s]
    

    相关文章

      网友评论

          本文标题:presto 的安装与使用

          本文链接:https://www.haomeiwen.com/subject/ogggdltx.html