Skip to content

Commit eceec07

Browse files
committed
[fix][dingo-executor] The concat function supports composite types
1 parent 072fa30 commit eceec07

File tree

7 files changed

+88
-213
lines changed

7 files changed

+88
-213
lines changed

dingo-calcite/src/main/codegen/config.fmpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ data: {
150150
"io.dingodb.calcite.grammar.dml.SqlExecute"
151151
"io.dingodb.calcite.grammar.dml.SqlPrepare"
152152
"io.dingodb.calcite.grammar.SqlUserDefinedOperators"
153-
"io.dingodb.calcite.fun.SqlConcatFunction"
154153
"io.dingodb.calcite.type.DingoSqlLiteral"
155154
"io.dingodb.calcite.type.DingoSqlCharStringLiteral"
156155
"io.dingodb.calcite.utils.DingoSqlParserUtil"
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2021 DataCanvas
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.dingodb.calcite.fun;
18+
19+
import lombok.EqualsAndHashCode;
20+
import org.apache.calcite.rel.type.RelDataType;
21+
import org.apache.calcite.sql.SqlCall;
22+
import org.apache.calcite.sql.SqlFunction;
23+
import org.apache.calcite.sql.SqlFunctionCategory;
24+
import org.apache.calcite.sql.SqlKind;
25+
import org.apache.calcite.sql.SqlOperator;
26+
import org.apache.calcite.sql.SqlOperatorBinding;
27+
import org.apache.calcite.sql.type.SqlOperandTypeChecker;
28+
import org.apache.calcite.sql.type.SqlOperandTypeInference;
29+
import org.apache.calcite.sql.type.SqlReturnTypeInference;
30+
import org.apache.calcite.sql.type.SqlTypeName;
31+
import org.apache.calcite.sql.validate.SqlValidator;
32+
import org.apache.calcite.sql.validate.SqlValidatorScope;
33+
import org.checkerframework.checker.nullness.qual.NonNull;
34+
import org.checkerframework.checker.nullness.qual.Nullable;
35+
36+
@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true)
37+
public class DingoConcatFunction extends DingoSqlFunction {
38+
public DingoConcatFunction(
39+
String name,
40+
@Nullable SqlReturnTypeInference returnTypeInference,
41+
@Nullable SqlOperandTypeInference operandTypeInference,
42+
@Nullable SqlOperandTypeChecker operandTypeChecker,
43+
SqlFunctionCategory category
44+
) {
45+
super(
46+
name,
47+
returnTypeInference,
48+
operandTypeInference,
49+
operandTypeChecker,
50+
category
51+
);
52+
}
53+
54+
@Override
55+
public void validateCall(
56+
@NonNull SqlCall call,
57+
SqlValidator validator,
58+
SqlValidatorScope scope,
59+
SqlValidatorScope operandScope
60+
) {
61+
SqlOperator operator = call.getOperator();
62+
assert getClass().isAssignableFrom(operator.getClass());
63+
super.validateCall(call, validator, scope, operandScope);
64+
}
65+
66+
67+
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
68+
return opBinding.getTypeFactory().createSqlType(SqlTypeName.VARCHAR);
69+
}
70+
71+
}

dingo-calcite/src/main/java/io/dingodb/calcite/fun/DingoOperatorTable.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ private void init() {
125125
funMap.put("CURDATE", SqlStdOperatorTable.CURRENT_DATE);
126126
funMap.put("CURTIME", SqlStdOperatorTable.CURRENT_TIME);
127127
funMap.put("SUBSTR", SqlStdOperatorTable.SUBSTRING);
128-
funMap.put("CONCAT", SqlConcatFunction.CONCAT);
129128
funMap.put("IF", SqlIfFunction.IF);
130129

131130
// number
@@ -160,7 +159,7 @@ private void init() {
160159
);
161160

162161
// string
163-
registerFunction(
162+
registerConcatFunction(
164163
ConcatFun.NAME,
165164
ReturnTypes.VARCHAR_2000_NULLABLE,
166165
DingoInferTypes.VARCHAR,
@@ -544,6 +543,22 @@ public void registerFunction(
544543
));
545544
}
546545

546+
public void registerConcatFunction(
547+
@NonNull String name,
548+
@Nullable SqlReturnTypeInference returnTypeInference,
549+
@Nullable SqlOperandTypeInference operandTypeInference,
550+
@Nullable SqlOperandTypeChecker operandTypeChecker,
551+
SqlFunctionCategory category
552+
) {
553+
funMap.put(name.toUpperCase(), new DingoConcatFunction(
554+
name.toUpperCase(),
555+
returnTypeInference,
556+
operandTypeInference,
557+
operandTypeChecker,
558+
category
559+
));
560+
}
561+
547562
@Override
548563
public void lookupOperatorOverloads(
549564
SqlIdentifier opName,

dingo-calcite/src/main/java/io/dingodb/calcite/fun/DingoSqlFunction.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
import org.apache.calcite.sql.SqlCall;
2121
import org.apache.calcite.sql.SqlFunction;
2222
import org.apache.calcite.sql.SqlFunctionCategory;
23-
import org.apache.calcite.sql.SqlIdentifier;
2423
import org.apache.calcite.sql.SqlKind;
2524
import org.apache.calcite.sql.SqlOperator;
26-
import org.apache.calcite.sql.parser.SqlParserPos;
2725
import org.apache.calcite.sql.type.SqlOperandTypeChecker;
2826
import org.apache.calcite.sql.type.SqlOperandTypeInference;
2927
import org.apache.calcite.sql.type.SqlReturnTypeInference;

dingo-calcite/src/main/java/io/dingodb/calcite/fun/SqlConcatFunction.java

Lines changed: 0 additions & 141 deletions
This file was deleted.

dingo-exec/src/main/java/io/dingodb/exec/fun/ConcatFun.java

Lines changed: 0 additions & 66 deletions
This file was deleted.

dingo-exec/src/main/java/io/dingodb/exec/fun/DingoFunFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ private DingoFunFactory() {
7979
registerUnaryFun(LastValFun.NAME, LastValFun.INSTANCE);
8080
registerBinaryFun(SetValFun.NAME, SetValFun.INSTANCE);
8181
registerUnaryFun(LengthFun.NAME, LengthFun.INSTANCE);
82-
registerVariadicFun(ConcatFun.NAME, ConcatFun.INSTANCE);
8382
registerTertiaryFun(IfFun.NAME, IfFun.INSTANCE);
8483
registerBinaryFun(DateAddFun.NAME, DateAddFun.INSTANCE);
8584
registerBinaryFun(DateSubFun.NAME, DateSubFun.INSTANCE);

0 commit comments

Comments
 (0)