Search in sources :

Example 1 with FlinkSqlTimestampFunction

use of org.apache.flink.table.planner.functions.sql.FlinkSqlTimestampFunction in project flink by apache.

the class SqlFunctionConverter method visitCall.

@Override
public RexNode visitCall(RexCall call) {
    SqlOperator operator = call.getOperator();
    List<RexNode> operands = call.getOperands();
    SqlOperator convertedOp = convertOperator(operator);
    final boolean[] update = null;
    if (convertedOp instanceof SqlCastFunction) {
        RelDataType type = call.getType();
        return builder.makeCall(type, convertedOp, visitList(operands, update));
    } else {
        if (convertedOp instanceof FlinkSqlTimestampFunction) {
            // flink's current_timestamp has different type from hive's, convert it to a literal
            Timestamp currentTS = ((HiveParser.HiveParserSessionState) SessionState.get()).getHiveParserCurrentTS();
            HiveShim hiveShim = HiveParserUtils.getSessionHiveShim();
            try {
                return HiveParserRexNodeConverter.convertConstant(new ExprNodeConstantDesc(hiveShim.toHiveTimestamp(currentTS)), cluster);
            } catch (SemanticException e) {
                throw new FlinkHiveException(e);
            }
        }
        return builder.makeCall(convertedOp, visitList(operands, update));
    }
}
Also used : ExprNodeConstantDesc(org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc) SqlCastFunction(org.apache.calcite.sql.fun.SqlCastFunction) SqlOperator(org.apache.calcite.sql.SqlOperator) FlinkHiveException(org.apache.flink.connectors.hive.FlinkHiveException) RelDataType(org.apache.calcite.rel.type.RelDataType) Timestamp(java.sql.Timestamp) FlinkSqlTimestampFunction(org.apache.flink.table.planner.functions.sql.FlinkSqlTimestampFunction) HiveShim(org.apache.flink.table.catalog.hive.client.HiveShim) RexNode(org.apache.calcite.rex.RexNode) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Aggregations

Timestamp (java.sql.Timestamp)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 RexNode (org.apache.calcite.rex.RexNode)1 SqlOperator (org.apache.calcite.sql.SqlOperator)1 SqlCastFunction (org.apache.calcite.sql.fun.SqlCastFunction)1 FlinkHiveException (org.apache.flink.connectors.hive.FlinkHiveException)1 HiveShim (org.apache.flink.table.catalog.hive.client.HiveShim)1 FlinkSqlTimestampFunction (org.apache.flink.table.planner.functions.sql.FlinkSqlTimestampFunction)1 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)1 ExprNodeConstantDesc (org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc)1