Trino 源码剖析

2023-11-01 11:12
文章标签 源码 剖析 trino

本文主要是介绍Trino 源码剖析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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
在这里插入图片描述

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 conversionStringBuilder out = null;int i = 0;int j = -1;while ((j = wordBoundary.indexIn(s, ++j)) != -1) {if (i == 0) {// include some extra space for separatorsout = 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 源码剖析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/322560

相关文章

Java 正则表达式URL 匹配与源码全解析

《Java正则表达式URL匹配与源码全解析》在Web应用开发中,我们经常需要对URL进行格式验证,今天我们结合Java的Pattern和Matcher类,深入理解正则表达式在实际应用中... 目录1.正则表达式分解:2. 添加域名匹配 (2)3. 添加路径和查询参数匹配 (3) 4. 最终优化版本5.设计思

Java调用C++动态库超详细步骤讲解(附源码)

《Java调用C++动态库超详细步骤讲解(附源码)》C语言因其高效和接近硬件的特性,时常会被用在性能要求较高或者需要直接操作硬件的场合,:本文主要介绍Java调用C++动态库的相关资料,文中通过代... 目录一、直接调用C++库第一步:动态库生成(vs2017+qt5.12.10)第二步:Java调用C++

Python实现无痛修改第三方库源码的方法详解

《Python实现无痛修改第三方库源码的方法详解》很多时候,我们下载的第三方库是不会有需求不满足的情况,但也有极少的情况,第三方库没有兼顾到需求,本文将介绍几个修改源码的操作,大家可以根据需求进行选择... 目录需求不符合模拟示例 1. 修改源文件2. 继承修改3. 猴子补丁4. 追踪局部变量需求不符合很

Spring 中 BeanFactoryPostProcessor 的作用和示例源码分析

《Spring中BeanFactoryPostProcessor的作用和示例源码分析》Spring的BeanFactoryPostProcessor是容器初始化的扩展接口,允许在Bean实例化前... 目录一、概览1. 核心定位2. 核心功能详解3. 关键特性二、Spring 内置的 BeanFactory

Go中sync.Once源码的深度讲解

《Go中sync.Once源码的深度讲解》sync.Once是Go语言标准库中的一个同步原语,用于确保某个操作只执行一次,本文将从源码出发为大家详细介绍一下sync.Once的具体使用,x希望对大家有... 目录概念简单示例源码解读总结概念sync.Once是Go语言标准库中的一个同步原语,用于确保某个操

Java汇编源码如何查看环境搭建

《Java汇编源码如何查看环境搭建》:本文主要介绍如何在IntelliJIDEA开发环境中搭建字节码和汇编环境,以便更好地进行代码调优和JVM学习,首先,介绍了如何配置IntelliJIDEA以方... 目录一、简介二、在IDEA开发环境中搭建汇编环境2.1 在IDEA中搭建字节码查看环境2.1.1 搭建步

Node.js 中 http 模块的深度剖析与实战应用小结

《Node.js中http模块的深度剖析与实战应用小结》本文详细介绍了Node.js中的http模块,从创建HTTP服务器、处理请求与响应,到获取请求参数,每个环节都通过代码示例进行解析,旨在帮... 目录Node.js 中 http 模块的深度剖析与实战应用一、引言二、创建 HTTP 服务器:基石搭建(一

JAVA智听未来一站式有声阅读平台听书系统小程序源码

智听未来,一站式有声阅读平台听书系统 🌟&nbsp;开篇:遇见未来,从“智听”开始 在这个快节奏的时代,你是否渴望在忙碌的间隙,找到一片属于自己的宁静角落?是否梦想着能随时随地,沉浸在知识的海洋,或是故事的奇幻世界里?今天,就让我带你一起探索“智听未来”——这一站式有声阅读平台听书系统,它正悄悄改变着我们的阅读方式,让未来触手可及! 📚&nbsp;第一站:海量资源,应有尽有 走进“智听

Java ArrayList扩容机制 (源码解读)

结论:初始长度为10,若所需长度小于1.5倍原长度,则按照1.5倍扩容。若不够用则按照所需长度扩容。 一. 明确类内部重要变量含义         1:数组默认长度         2:这是一个共享的空数组实例,用于明确创建长度为0时的ArrayList ,比如通过 new ArrayList<>(0),ArrayList 内部的数组 elementData 会指向这个 EMPTY_EL

如何在Visual Studio中调试.NET源码

今天偶然在看别人代码时,发现在他的代码里使用了Any判断List<T>是否为空。 我一般的做法是先判断是否为null,再判断Count。 看了一下Count的源码如下: 1 [__DynamicallyInvokable]2 public int Count3 {4 [__DynamicallyInvokable]5 get