Hi automths, RexNode中的Literal type,在calcite convert to relNode的过程中,以col1 > 10为例, 10从calcite parse出来首先是SqlNumericLiteral, 其中类型会是Decimal(prec: 2, scale: 0). 在创建其对应的RelDataType时,如果其值域在Interger.MIN ~ Interger.Max之间,那就是Interger type。 如果不在就是decimal, 这里没有类似Hive的auto cast功能,而是calcite进行了隐式类型转换。 这里具体隐式转换的规则可以参考: https://calcite.apache.org/docs/reference.html#implicit-type-conversion
对于Function中,参数的类型,Flink也有一套规则进行推导。 select * from shortRow1 where col1 > CAST(10 AS SMALLINT) and col1 <= CAST(15 AS SMALLINT) 可以保证 在applyPredicates时看到的expression中,literal是预期的type,但不是特别通用,建议在相关connector中实现 一个TypeVisitor, 把literal转成预期的type。 Just my thoughts automths <[email protected]> 于2021年1月4日周一 上午9:36写道: > > > 谢谢你的回答。 > > 但是我的col1,col2就已经是SMALLINT类型的了,我的问题是where条件中值下推过程中是Integer类型的,我希望值也是SMALLINT的。 > > > > 祝好! > | | > automths > | > | > [email protected] > | > 在2020年12月31日 18:17,whirly<[email protected]> 写道: > Hi. > > 查询语句中可以使用 cast 内置函数将值强制转换为指定的类型,如 select CAST(A.`col1` AS SMALLINT) as > col1 from table > > > 参考: > > https://ci.apache.org/projects/flink/flink-docs-release-1.12/dev/table/functions/systemFunctions.html#type-conversion-functions > > https://ci.apache.org/projects/flink/flink-docs-release-1.12/dev/table/types.html#data-types > > > > > best 2021. > > > 在 2020-12-31 17:13:20,"automths" <[email protected]> 写道: > Hi: > 我自定义connect并实现了FilterableTableSource接口,可是发现flink planner 下推的Filter中, > Literal类型与字段类型不匹配。 > 比如:下面的SQL: > select * from shortRow1 where key in (1, 2, 3) and col1 > 10 and col1 <= 15 > 其中DDL定义时, key、col1、col1都是SMALLINT类型 > 在下推的Filter中, GreaterThan中的Literal是Integer类型,这样是合理的吗?或者我的查询语句中要做什么处理? > > > 祝好! > | | > automths > | > | > [email protected] > | > > -- *With kind regards ------------------------------------------------------------ Sebastian Liu 刘洋 Institute of Computing Technology, Chinese Academy of Science Mobile\WeChat: +86—15201613655 E-mail: [email protected] <[email protected]> QQ: 3239559*
