Trino 源码剖析

这篇具有很好参考价值的文章主要介绍了Trino 源码剖析。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

Build

prerequisites

  • Java 17.0.4+, 64-bit
./mvnw clean package -DskipTests

或者

mvn clean package -DskipTests

Functions

function 反射和注册

io.trino.operator.scalar.annotations.ScalarFromAnnotationsParser

这里是提取注解元素的方法
String baseName = scalarFunction.value().isEmpty() ? camelToSnake(annotatedName(annotated)) : scalarFunction.value();

这里如果 scalarFunction 的注解没有没有值,直接对函数名进行snake命名法

一般程序设计中,有两种变量命名规范:Snake方式和Camel方式。

  • Snake方式是指单词用小写字母,单词间下划线(“_”)代替空格;
  • Camel方式是指相邻单词首字母用大写表示,对单词加以区分。

例如,你想定义一个变量表示一个数组数字之和,并且用英文“sum of array”。我们使用Snake方式的变量名为:sum_of_array;用Camel命名方式的变量名为:sumOfArray。

  public static List<ScalarImplementationHeader> fromAnnotatedElement(AnnotatedElement annotated)
    {
        ScalarFunction scalarFunction = annotated.getAnnotation(ScalarFunction.class);
        ScalarOperator scalarOperator = annotated.getAnnotation(ScalarOperator.class);
        Optional<String> description = parseDescription(annotated);

        ImmutableList.Builder<ScalarImplementationHeader> builder = ImmutableList.builder();

        if (scalarFunction != null) {
            String baseName = scalarFunction.value().isEmpty() ? camelToSnake(annotatedName(annotated)) : scalarFunction.value();
            builder.add(new ScalarImplementationHeader(baseName, new ScalarHeader(description, scalarFunction.hidden(), scalarFunction.deterministic())));

            for (String alias : scalarFunction.alias()) {
                builder.add(new ScalarImplementationHeader(alias, new ScalarHeader(description, scalarFunction.hidden(), scalarFunction.deterministic())));
            }
        }

        if (scalarOperator != null) {
            builder.add(new ScalarImplementationHeader(scalarOperator.value(), new ScalarHeader(description, true, true)));
        }

        List<ScalarImplementationHeader> result = builder.build();
        checkArgument(!result.isEmpty());
        return result;
    }

io.trino.operator.scalar.annotations.ScalarImplementationHeader
Trino 源码剖析,spark,spark,大数据

private static String annotatedName(AnnotatedElement annotatedElement)
    {
        if (annotatedElement instanceof Class<?>) {
            return ((Class<?>) annotatedElement).getSimpleName();
        }
        if (annotatedElement instanceof Method) {
            return ((Method) annotatedElement).getName();
        }

        checkArgument(false, "Only Classes and Methods are supported as annotated elements.");
        return null;
    }

由上可得 method 也是一种 AnnotatedElement

trino 中的 snake 命名法

io.trino.operator.scalar.annotations.ScalarImplementationHeader

private static String camelToSnake(String name)
    {
        return LOWER_CAMEL.to(LOWER_UNDERSCORE, name);
    }

com.google.common.base.CaseFormat

  /**
   * Converts the specified {@code String str} from this format to the specified {@code format}. A
   * "best effort" approach is taken; if {@code str} does not conform to the assumed format, then
   * the behavior of this method is undefined but we make a reasonable effort at converting anyway.
   */
  public final String to(CaseFormat format, String str) {
    checkNotNull(format);
    checkNotNull(str);
    return (format == this) ? str : convert(format, str);
  }
  /** Enum values can override for performance reasons. */
  String convert(CaseFormat format, String s) {
    // deal with camel conversion
    StringBuilder out = null;
    int i = 0;
    int j = -1;
    while ((j = wordBoundary.indexIn(s, ++j)) != -1) {
      if (i == 0) {
        // include some extra space for separators
        out = new StringBuilder(s.length() + 4 * format.wordSeparator.length());
        out.append(format.normalizeFirstWord(s.substring(i, j)));
      } else {
        requireNonNull(out).append(format.normalizeWord(s.substring(i, j)));
      }
      out.append(format.wordSeparator);
      i = j + wordSeparator.length();
    }
    return (i == 0)
        ? format.normalizeFirstWord(s)
        : requireNonNull(out).append(format.normalizeWord(s.substring(i))).toString();
  }

Trino 源码剖析,spark,spark,大数据

Plugins

When you implement a new Trino plugin, you implement interfaces and override methods defined by the Service Provider Interface (SPI).

Every Trino plugin should be in a separate directory. Do not put JAR files directly into the plugin directory. Plugins should only contain JAR files, so any subdirectories will not be traversed and will be ignored.

  • By default, the plugin directory is the plugin directory relative to the directory in which Trino is installed, but it is configurable using the configuration variable plugin.dir. In order for Trino to pick up the new plugin, you must restart Trino.
  • Plugins must be installed on all nodes in the Trino cluster (coordinator and workers).
trino-cli
cd $TRINO_HOME/client/ 
./trino-cli --server {IP}:9000 --catalog hive --user=hadoop --schema default

schema 代表的是数据库文章来源地址https://www.toymoban.com/news/detail-734290.html

到了这里,关于Trino 源码剖析的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Spark2x原理剖析(二)

    基于社区已有的JDBCServer基础上,采用多主实例模式实现了其高可用性方案。集群中支持同时共存多个JDBCServer服务,通过客户端可以随机连接其中的任意一个服务进行业务操作。即使集群中一个或多个JDBCServer服务停止工作,也不影响用户通过同一个客户端接口连接其他正常的

    2024年02月09日
    浏览(33)
  • 【大数据】Presto(Trino)SQL 语法进阶

    Presto(Trino)是一个快速、分布式的SQL查询引擎,可以用于查询各种数据源,包括Hadoop、NoSQL、关系型数据库等。下面是Presto(Trino)SQL语法的概述: 它支持标准SQL语法,包括以下SQL命令: SELECT :用于从一个或多个表中检索数据,指定所需的列和过滤条件。 FROM :用于指定要

    2024年02月11日
    浏览(24)
  • 【大数据】Presto(Trino)配置参数以及 SQL语法

    Trino (前身为 PrestoSQL )是一款 高性能,分布式的SQL查询引擎 ,可以用于查询各种类型的数据存储,包括 Hive 、 Mysql 、 Elasticsearch 、 Kafka 、 PostgreSQL 等。在使用Trino时,可以通过一些参数来控制查询的行为,例如: coordinator 节点和 worker 节点的数量 : 这两个参数控制了Trino集群

    2024年02月09日
    浏览(36)
  • .Net大数据平台Microsoft.Spark环境构建 附可运行源码。

    前言:大什么数据?什么大数据?什么数据大?挖野菜才是正道。  NBNBNB 老资终于可以不用花太多精力搞python了  。 window环境的.Net大数据平台环境构建 附带可运行源码。 windows 安装jdk 相关坑 java jdk1.8.0_221 安装步骤_云草桑的博客-CSDN博客_jdk1.8.0_221  .NET for Apache Spark 使用

    2024年02月09日
    浏览(32)
  • 大数据:Trino简介及ETL场景的解决方案

    Presto 在 Facebook 的诞生最开始是为了填补当时 Facebook 内部实时查询和 ETL 处理之间的空白。Presto 的核心目标就是提供交互式查询,也就是我们常说的 Ad-Hoc Query,很多公司都使用它作为 OLAP 计算引擎。但是随着近年来业务场景越来越复杂,除了交互式查询场景,很多公司也需要

    2024年02月08日
    浏览(32)
  • spark法律服务大数据智能推荐(自己动手做的,完整过程+源码)

    水院的同学不要抄袭呀! 1 作品(项目)目标 与搜索引擎不同,推荐系统并不需要用户提供明确的需求,而是通过分析用户的历史行为,主动为用户推荐能够满足他们兴趣和需求的信息。为了能够更好地满足用户需求,需要依据其网站的海量数据,研究用户的兴趣偏好,分析

    2024年02月10日
    浏览(32)
  • 【大数据技术】Spark+Flume+Kafka实现商品实时交易数据统计分析实战(附源码)

    需要源码请点赞关注收藏后评论区留言私信~~~ 1)Kafka 是一个非常通用的系统,你可以有许多生产者和消费者共享多个主题Topics。相比之下,Flume是一个专用工具被设计为旨在往HDFS,HBase等发送数据。它对HDFS有特殊的优化,并且集成了Hadoop的安全特性。如果数据被多个系统消

    2024年02月03日
    浏览(37)
  • 【大数据】Presto(Trino)REST API 与执行计划介绍

    Presto(现在叫Trino)是一个分布式SQL查询引擎,它允许用户在多个数据源上执行查询。Presto本身是一个独立的Java程序,可以通过REST API与其他应用程序进行通信。 Presto的REST API是一组HTTP接口,可以用于与Presto服务器进行通信,并提交查询请求、获取查询结果等。以下是Presto

    2024年02月07日
    浏览(32)
  • Iceberg-Trino 如何解决链上数据面临的挑战

    区块链数据公司,在索引以及处理链上数据时,可能会面临一些挑战,包括: 海量数据。随着区块链上数据量的增加,数据索引将需要扩大规模以处理增加的负载并提供对数据的有效访问。因此,它导致了更高的存储成本;缓慢的指标计算和增加数据库服务器的负载。 复杂

    2024年02月02日
    浏览(31)
  • 数据湖架构Hudi(二)Hudi版本0.12源码编译、Hudi集成spark、使用IDEA与spark对hudi表增删改查

    Hadoop 3.1.3 Hive 3.1.2 Flink 1.13.6,scala-2.12 Spark 3.2.2,scala-2.12 2.1.1 环境准备 2.1.2 下载源码包 2.1.3 在pom文件中新增repository加速依赖下载 在pom文件中修改依赖的组件版本: 2.1.4 修改源码兼容hadoop3并添加kafka依赖 Hudi默认依赖的hadoop2,要兼容hadoop3,除了修改版本,还需要修改如下代

    2024年02月06日
    浏览(43)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包