106 addAlias(SqlStdOperatorTable.CHARACTER_LENGTH, SqlStdOperatorTable.CHAR_LENGTH);
107 addAlias(SqlStdOperatorTable.IS_UNKNOWN, SqlStdOperatorTable.IS_NULL);
108 addAlias(SqlStdOperatorTable.IS_NOT_UNKNOWN, SqlStdOperatorTable.IS_NOT_NULL);
109 addAlias(SqlStdOperatorTable.PERCENT_REMAINDER, SqlStdOperatorTable.MOD);
112 registerOp(SqlStdOperatorTable.CAST, this::convertCast);
113 registerOp(SqlLibraryOperators.INFIX_CAST, this::convertCast);
116 registerOp(HeavyDBSqlOperatorTable.TRY_CAST, this::convertTryCast);
119 registerOp(SqlStdOperatorTable.IS_DISTINCT_FROM,
121 registerOp(SqlStdOperatorTable.IS_NOT_DISTINCT_FROM,
124 registerOp(SqlStdOperatorTable.PLUS, this::convertPlus);
126 registerOp(SqlStdOperatorTable.MINUS, (cx, call) -> {
128 cx, call.getOperator(), call.getOperandList());
129 switch (e.getOperands().get(0).getType().getSqlTypeName()) {
140 SqlLibraryOperators.LTRIM,
new TrimConvertlet(SqlTrimFunction.Flag.LEADING));
142 SqlLibraryOperators.RTRIM,
new TrimConvertlet(SqlTrimFunction.Flag.TRAILING));
144 registerOp(SqlLibraryOperators.GREATEST,
new GreatestConvertlet());
145 registerOp(SqlLibraryOperators.LEAST,
new GreatestConvertlet());
147 registerOp(SqlLibraryOperators.NVL, (cx, call) -> {
148 final RexBuilder rexBuilder = cx.getRexBuilder();
149 final RexNode operand0 = cx.convertExpression(call.getOperandList().
get(0));
150 final RexNode operand1 = cx.convertExpression(call.getOperandList().
get(1));
151 final RelDataType
type = cx.getValidator().getValidatedNodeType(call);
152 return rexBuilder.makeCall(
type,
153 SqlStdOperatorTable.CASE,
155 rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL, operand0),
156 rexBuilder.makeCast(type, operand0),
157 rexBuilder.makeCast(
type, operand1)));
160 registerOp(SqlLibraryOperators.DECODE, (cx, call) -> {
161 final RexBuilder rexBuilder = cx.getRexBuilder();
163 cx, call.getOperandList(), SqlOperandTypeChecker.Consistency.NONE);
164 final RelDataType
type = cx.getValidator().getValidatedNodeType(call);
165 final List<RexNode> exprs =
new ArrayList<>();
166 for (
int i = 1; i < operands.size() - 1; i += 2) {
167 exprs.add(RelOptUtil.isDistinctFrom(
168 rexBuilder, operands.get(0), operands.get(i),
true));
169 exprs.add(operands.get(i + 1));
171 if (operands.size() % 2 == 0) {
172 exprs.add(Util.last(operands));
174 exprs.add(rexBuilder.makeNullLiteral(
type));
176 return rexBuilder.makeCall(
type, SqlStdOperatorTable.CASE, exprs);
180 registerOp(SqlStdOperatorTable.NOT_LIKE,
182 -> cx.convertExpression(
183 SqlStdOperatorTable.NOT.createCall(SqlParserPos.ZERO,
184 SqlStdOperatorTable.LIKE.createCall(
185 SqlParserPos.ZERO, call.getOperandList()))));
188 registerOp(SqlStdOperatorTable.NOT_SIMILAR_TO,
190 -> cx.convertExpression(
191 SqlStdOperatorTable.NOT.createCall(SqlParserPos.ZERO,
192 SqlStdOperatorTable.SIMILAR_TO.createCall(
193 SqlParserPos.ZERO, call.getOperandList()))));
196 registerOp(SqlStdOperatorTable.UNARY_PLUS,
197 (cx, call) -> cx.convertExpression(call.operand(0)));
200 registerOp(SqlStdOperatorTable.DOT,
202 -> cx.getRexBuilder().makeFieldAccess(
203 cx.convertExpression(call.operand(0)),
208 SqlStdOperatorTable.AS, (cx, call) -> cx.convertExpression(call.operand(0)));
210 registerOp(SqlStdOperatorTable.SQRT,
212 -> cx.convertExpression(SqlStdOperatorTable.POWER.createCall(
215 SqlLiteral.createExactNumeric(
"0.5", SqlParserPos.ZERO))));
233 registerOp(SqlStdOperatorTable.AVG,
new AvgVarianceConvertlet(SqlKind.AVG));
234 registerOp(SqlStdOperatorTable.STDDEV_POP,
235 new AvgVarianceConvertlet(SqlKind.STDDEV_POP));
236 registerOp(SqlStdOperatorTable.STDDEV_SAMP,
237 new AvgVarianceConvertlet(SqlKind.STDDEV_SAMP));
239 SqlStdOperatorTable.STDDEV,
new AvgVarianceConvertlet(SqlKind.STDDEV_SAMP));
240 registerOp(SqlStdOperatorTable.VAR_POP,
new AvgVarianceConvertlet(SqlKind.VAR_POP));
241 registerOp(SqlStdOperatorTable.VAR_SAMP,
new AvgVarianceConvertlet(SqlKind.VAR_SAMP));
242 registerOp(SqlStdOperatorTable.VARIANCE,
new AvgVarianceConvertlet(SqlKind.VAR_SAMP));
243 registerOp(SqlStdOperatorTable.COVAR_POP,
244 new RegrCovarianceConvertlet(SqlKind.COVAR_POP));
245 registerOp(SqlStdOperatorTable.COVAR_SAMP,
246 new RegrCovarianceConvertlet(SqlKind.COVAR_SAMP));
248 SqlStdOperatorTable.REGR_SXX,
new RegrCovarianceConvertlet(SqlKind.REGR_SXX));
250 SqlStdOperatorTable.REGR_SYY,
new RegrCovarianceConvertlet(SqlKind.REGR_SYY));
252 final SqlRexConvertlet floorCeilConvertlet =
new FloorCeilConvertlet();
253 registerOp(SqlStdOperatorTable.FLOOR, floorCeilConvertlet);
254 registerOp(SqlStdOperatorTable.CEIL, floorCeilConvertlet);
256 registerOp(SqlStdOperatorTable.TIMESTAMP_ADD,
new TimestampAddConvertlet());
257 registerOp(SqlStdOperatorTable.TIMESTAMP_DIFF,
new TimestampDiffConvertlet());
264 registerOp(SqlStdOperatorTable.ELEMENT, (cx, call) -> {
265 assert call.operandCount() == 1;
266 final SqlNode operand = call.operand(0);
267 final RelDataType
type = cx.getValidator().getValidatedNodeType(operand);
268 if (!type.getComponentType().isStruct()) {
269 return cx.convertExpression(SqlStdOperatorTable.ELEMENT_SLICE.createCall(
270 SqlParserPos.ZERO, operand));
274 return StandardConvertletTable.this.convertCall(cx, call);
280 registerOp(SqlStdOperatorTable.ELEMENT_SLICE, (cx, call) -> {
281 assert call.operandCount() == 1;
282 final SqlNode operand = call.operand(0);
283 final RexNode expr = cx.convertExpression(
284 SqlStdOperatorTable.ELEMENT.createCall(SqlParserPos.ZERO, operand));
285 return cx.getRexBuilder().makeFieldAccess(expr, 0);
static RexNode convertInterval(SqlRexContext cx, SqlCall call)
static List< RexNode > convertExpressionList(SqlRexContext cx, List< SqlNode > nodes, SqlOperandTypeChecker.Consistency consistency)
std::string toString(const Executor::ExtModuleKinds &kind)
StandardConvertletTable()
RexNode convertIsDistinctFrom(SqlRexContext cx, SqlCall call, boolean neg)
RexNode convertDatetimeMinus(SqlRexContext cx, SqlDatetimeSubtractionOperator op, SqlCall call)