当前位置: 首页 > news >正文

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();}

在这里插入图片描述

http://www.lryc.cn/news/212891.html

相关文章:

  • element表格自定义筛选
  • 全方位 Linux 性能调优经验总结
  • Linux机器网络检查
  • 使用示例和应用程序全面了解高效数据管理的Golang MySQL数据库
  • ubuntu 22.04 源码安装 apollo 8.0
  • RK3588编译MXNet框架
  • 港府Web3宣言周年思考:合规困境中的“隐患”
  • vue点击按钮跳转页面
  • 大中小企业对CRM系统的需求
  • .net core iis 发布后登入的时候请求不到方法报错502
  • 知识图谱实战应用30-知识图谱在反欺诈情报分析项目中的应用实践
  • [云原生1. ] 使用Docker-compose一键部署Wordpress平台
  • springboot--基本特性--自定义 Banner
  • Vue3:checkbox使用及限制选中数量
  • ​如何选择更快更稳定的存储服务器​
  • AcWing89. a^b
  • 【推荐系统】推荐算法:冷启动-召回-粗排-精排-重排 解读
  • NB-IOT的粮库挡粮门异动监测装置
  • 六、【图像去水印】
  • 电子电器架构 —— 车载网关初入门(二)
  • AT32固件库外设使用,ArduinoAPI接口移植,模块化
  • 【Postgres】Postgres常用命令
  • pthread 读写锁使用详解
  • MySQL扩展语句
  • 阿里云号码认证服务(一键登录)在连接wifi的情况下部分机型下存在的问题
  • 电脑屏幕监控软件,能够帮助企业完成哪些事情?
  • java--方法的其他形式
  • IDEA配置类、方法注释模板
  • PowerDesigner 16数据库(mysql)逆向生成pdm
  • Spring Cloud 之Feign