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

深圳福田做网站公司哪家好百度一下官网网址

深圳福田做网站公司哪家好,百度一下官网网址,一般做网站的宽度怎么处理的,wordpress图片网盘插件腾讯前言 上一篇文章中我们介绍了calcite中内置函数的使用。实际需求中会遇到一些场景标准内置函数无法满足需求,这时候就需要用到自定义函数。在 Apache Calcite 中添加自定义函数,以便在 SQL 查询中使用自定义的逻辑。这对于执行特定的数据处理或分析任务…

前言

上一篇文章中我们介绍了calcite中内置函数的使用。实际需求中会遇到一些场景标准内置函数无法满足需求,这时候就需要用到自定义函数。在 Apache Calcite 中添加自定义函数,以便在 SQL 查询中使用自定义的逻辑。这对于执行特定的数据处理或分析任务非常有用。

相关依赖

通过前面的学习,我们知道表、函数等信息维护在schema中,因此我们要做的事情就是在schema中新增自定义的函数。

以下演示基于1.36版包实现。

    <dependency><groupId>org.apache.calcite</groupId><artifactId>calcite-core</artifactId><version>1.36.0</version></dependency>

为了新增函数我们需要重写AbstractSchema中的 getFunctionMultimap方法,方法定义如下:

  protected Multimap<String, Function> getFunctionMultimap() {return ImmutableMultimap.of();}

Function有多种实现,由于我们要扩展的是标量函数,所以关注ScalarFunction即可。
在这里插入图片描述
这里我们用到ScalarFunctionImpl.create方法来创建标量函数,方法中的参数1是所建函数所在的类,第二个是对应的方法名。

  /*** Creates {@link org.apache.calcite.schema.ScalarFunction} from given class.** <p>If a method of the given name is not found, or it does not suit,* returns {@code null}.** @param clazz class that is used to implement the function* @param methodName Method name (typically "eval")* @return created {@link ScalarFunction} or null*/public static @Nullable ScalarFunction create(Class<?> clazz, String methodName) {final Method method = findMethod(clazz, methodName);if (method == null) {return null;}return create(method);}

实现自定义标量函数

为了方便演示,我们实现一个无用的简单方法,对整数减1

public class CustomFunctions {public static Integer minus1(int num1) {return num1 - 1;}
}

接着扩展前文中用到的schema,实现getFunctionMultimap方法,并增加添加函数的方法

public class ListSchema extends AbstractSchema {Map<String, Table> tableMap = new HashMap<>();Multimap<String, Function> functionMap = LinkedListMultimap.create();public void addTable(String name, Table table) {tableMap.put(name, table);}public void addFunction(String name,Function function) { functionMap.put(name, function);}public ListSchema() {}@Overrideprotected Map<String, Table> getTableMap() {return tableMap;}@Overrideprotected Multimap<String, Function> getFunctionMultimap() {return functionMap;}
}

最后我们在schema中注册函数

ListSchema listSchema = new ListSchema();
listSchema.addFunction("minus1", ScalarFunctionImpl.create(CustomFunctions.class,"minus1"));

完成上述工作后,在sql中使用自定义的函数

ResultSet countResult = statement.executeQuery("select age,listSchema.minus1(age) from listSchema.MyTable");

打印结果,可以看到自定义方法的计算结果

95 94 
21 20 
47 46 

异常处理

在完成上述工作时也遇到了几个异常,分别如下:

No match found for function signature minus1(< NUMERIC>)

  • 详细的异常提示为:java.sql.SQLException: Error while executing SQL “select age,minus1(age) from listSchema.MyTable”: From line 1, column 12 to line 1, column 22: No match found for function signature minus1()
  • 异常原因
    1.注册的方法名与使用方法名不一致。最开始注册时,将方法名首字母写成了大写。但实际使用时却使用的小写名 Minus1 - > minus1 listSchema.addFunction(“Minus1”, ScalarFunctionImpl.create(CustomFunctions.class,“minus1”));
    2.另外使用方法名时没指定schema名,导致了错误
    上述两个问题修改完毕程序正常运行

总结

实现自定义标量函数,注册到schema最后使用,schema是核心,维护了各类元信息,并提供了扩展接口来实现自定义的能力

http://www.wooajung.com/news/30826.html

相关文章:

  • 用dw做网站维护教程谷歌seo外链
  • 钓鱼网站开发html模板网站
  • php能建立网站吗网站怎么优化关键词快速提升排名
  • 网站建设及推广套餐苏州新闻今天最新消息新闻事件
  • 广东建设厅网站首页搜索引擎优化技术
  • 企业网站建设步骤免费网站推广网站短视频
  • 北京那家建网站好重庆森林电影完整版
  • 网站域名分几种安康seo
  • 静态网站怎么优化做网络推广需要多少钱
  • 微网站难做么软文推广营销平台
  • 宁德建设银行网站百度明星人气排行榜
  • 模板网站建设搜索引擎在线
  • 沭阳找做网站合伙南京市网站seo整站优化
  • 电商网站的在线客服怎么做百度注册网站
  • 织梦网站修改幻灯片经典品牌推广文案
  • 旅游网站 源码 织梦西安竞价托管代运营
  • 帝国网站管理系统安装连接不上数据库sem代运营托管公司
  • 淘宝联盟网站建设不完整国内b站不收费网站有哪些
  • 国内做香港视频网站网店代运营公司哪家好
  • 做服装网站宣传短视频seo排名系统
  • 用vue element-ui做的网站青岛seo网络推广
  • 怎样做网站api接口seo推广优化培训
  • wordpress网站统计代码放哪个文件网站流量统计分析工具
  • html是静态网站整合营销是什么
  • 做装饬在哪家网站挂seo服务哪家好
  • 商业案例网站网络口碑营销名词解释
  • python做网站方便吗百度广告联盟怎么赚钱
  • 做竞彩网站代理犯法么国际新闻头条今日国际大事
  • dw做网站实例百度视频下载
  • 深圳福永网站建设公司域名查询138ip