java温度转换自动识别(Apache Calcite 实现方言转换的代码)
类别:服务器 浏览量:965
时间:2021-10-12 00:54:47 java温度转换自动识别
Apache Calcite 实现方言转换的代码定义Calcite能够通过解析Sql为SqlNode,再将SqlNode转化为特定数据库的方言的形式实现Sql的统一。
实现在Calcite中实现方言转换的主要类是SqlDialect基类,其具体的变量含义如下:
public class SqlDialect { BUILT_IN_OPERATORS_LIST: 支持的内置定义函数或者运算符(例如:abs and..) // 列 表的标识符 String identifierQuoteString: 标识符的开始符号 String identifierEndQuoteString: 标识符的结束符号 String identifierEscapedQuote: (暂时没有弄明白这个在做什么,像是字符串中的转义符?) // 常量的标识符 String literalQuoteString: 常量的开始符号 String literalEndQuoteString: 常量的结束符号 String literalEscapedQuote:(暂时没有弄明白这个在做什么,像是字符串中的转义符?) DatabaseProduct databaseProduct: 所属的数据库产品 NullCollation nullCollation: 在进行排序查询式,空值的返回顺序 RelDataTypeSystem dataTypeSystem: 数据类型 // 和解析相关 Casing unquotedCasing: 大小写转换 Casing quotedCasing: 大小写转换 boolean caseSensitive: 是否大小写敏感(列名 表明 函数名等) }
// 方法区(不同的数据源根据细节的不同实现自定义的复写方法) allowsAs configureParser configureParser containsNonAscii create defaultNullDirection emptyContext emulateJoinTypeForCrossJoin emulateNullDirection emulateNullDirectionWithIsNull getCalendarPolicy getCastSpec getConformance getDatabaseProduct getNullCollation getProduct getQuotedCasing getQuoting getSingleRowTableName getTypeSystem getUnquotedCasing hasImplicitTableAlias identifierNeedsQuote isCaseSensitive quoteIdentifier quoteIdentifier quoteIdentifier quoteStringLiteral quoteStringLiteral quoteStringLiteralUnicode quoteTimestampLiteral requiresAliasForFromItems rewriteSingleValueExpr supportsAggregateFunction supportsAliasedValues supportsCharSet supportsDataType supportsFunction supportsGroupByWithCube supportsGroupByWithRollup supportsImplicitTypeCoercion supportsNestedAggregations supportsOffsetFetch supportsWindowFunctions unparseCall unparseDateTimeLiteral unparseFetchUsingAnsi unparseFetchUsingLimit unparseLimit unparseOffset unparseOffsetFetch unparseSqlDatetimeArithmetic unparseSqlIntervalLiteral unparseSqlIntervalQualifier unparseTopN unquoteStringLiteral
使用方式Demo
/** Returns SqlNode for type in "cast(column as type)", which might be * different between databases by type name, precision etc. * * <p>If this method returns null, the cast will be omitted. In the default * implementation, this is the case for the NULL type, and therefore * {@code CAST(NULL AS <nulltype>)} is rendered as {@code NULL}. */ public SqlNode getCastSpec(RelDataType type) 这个方法就可以根据具体的数据源的数据类型进行转换,例如: @Override public SqlNode getCastSpec(RelDataType type) { switch (type.getSqlTypeName()) { case VARCHAR: // MySQL doesn't have a VARCHAR type, only CHAR. int vcMaxPrecision = this.getTypeSystem().getMaxPrecision(SqlTypeName.CHAR); int precision = type.getPrecision(); if (vcMaxPrecision > 0 && precision > vcMaxPrecision) { precision = vcMaxPrecision; } return new SqlDataTypeSpec( new SqlBasicTypeNameSpec(SqlTypeName.CHAR, precision, SqlParserPos.ZERO), SqlParserPos.ZERO); } return super.getCastSpec(type); } 就可以经Sql中的Cast语句Cast为特定的类型: final String query = "select cast(\"product_id\" as varchar(50)), \"product_id\" " + "from \"product\" "; final String expected = "SELECT CAST(`product_id` AS CHAR(50)), `product_id`\n" + "FROM `foodmart`.`product`";
// 解析过的SqlNode sqlNode.toSqlString(CalciteSqlDialect.DEFAULT).getSql();
到此这篇关于Apache Calcite 实现方言转换的代码的文章就介绍到这了,更多相关Apache Calcite方言转换内容请搜索开心学习网以前的文章或继续浏览下面的相关文章希望大家以后多多支持开心学习网!
您可能感兴趣
- 修改mysql安装服务名称(Apache为mysql以及自己的项目设置虚拟路径)
- apachephp安装配置教程交流(Apache中利用mod_rewrite实现防盗链)
- 做网站是使用nginx还是apache(web服务器软件Apache与Nginx的对比分析)
- apache服务器配置伪静态(apache中通过mod_rewrite实现伪静态页面的方法)
- apache各种配置(让Apache支持Rewrite静态页面重写的方法)
- apache域名绑定(Apache配置独立域名的方法)
- apache跳转配置(Apache 的 order deny allow 设置说明)
- apache的日志配置(apache 配置成滚动日志的方法)
- apache服务器的安全配置(Apache常用虚拟主机配置方法解析)
- 安装apache服务器配置(Apache 配置详解最好的APACHE配置教程)
- apache设置站点(Apache 多端口多站点配置方法)
- xampp二次安装方法(xampp中apache在windows7下无法启动的解决方法)
- apache 代理服务器返回403(Apache中301重定向的配置代码)
- apache安装与配置windows(Apache 安装和使用文档)
- win10怎么安装apache(apache启动失败怎么办 快速解决Win10系统apache启动失败的方法教程)
- apache 配置域名(apache 二级域名解析 window与linux)
- 五代十国南唐历代国君(五代十国南唐历代国君)
- 飞机引进工程师杨隆 匠人匠心,只争朝夕(飞机引进工程师杨隆)
- 三人行,她们是育人路上的 铁三角 团队(她们是育人路上的)
- 阴阳师 孟婆山兔CP不倒 新皮肤草稿 孟婆兔 让痒痒鼠点赞(阴阳师孟婆山兔CP不倒)
- 阴阳师孟婆御魂推荐 孟婆御魂搭配毕业套(阴阳师孟婆御魂推荐)
- 袁冰妍终于接到新剧,饰演反追男主,看到合作演员 眼光果然毒辣(袁冰妍终于接到新剧)
热门推荐
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9