Skip to content

Commit 5bdbaf1

Browse files
author
gituser
committed
Merge branch 'hotfix_1.10_4.0.x_33011' into 1.10_release_4.0.x
2 parents 030d8e1 + 3ea21ae commit 5bdbaf1

File tree

7 files changed

+329
-7
lines changed

7 files changed

+329
-7
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package com.dtstack.flink.sql.exception;
20+
21+
/**
22+
* @author: chuixue
23+
* @create: 2020-11-30 16:23
24+
* @description: 公共错误码
25+
**/
26+
public enum BaseCodeEnum implements ErrorCode {
27+
/**
28+
* 未指明的异常
29+
*/
30+
UNSPECIFIED("000", "unknow exception"),
31+
;
32+
33+
/**
34+
* 错误码
35+
*/
36+
private final String code;
37+
38+
/**
39+
* 描述
40+
*/
41+
private final String description;
42+
43+
/**
44+
* @param code 错误码
45+
* @param description 描述
46+
*/
47+
private BaseCodeEnum(final String code, final String description) {
48+
this.code = code;
49+
this.description = description;
50+
}
51+
52+
@Override
53+
public String getCode() {
54+
return code;
55+
}
56+
57+
@Override
58+
public String getDescription() {
59+
return description;
60+
}
61+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package com.dtstack.flink.sql.exception;
20+
21+
22+
/**
23+
* @author: chuixue
24+
* @create: 2020-11-30 14:48
25+
* @description:根异常
26+
**/
27+
public class BaseException extends RuntimeException {
28+
29+
/**
30+
* 错误码
31+
*/
32+
protected final ErrorCode errorCode;
33+
34+
/**
35+
* 无参默认构造UNSPECIFIED
36+
*/
37+
public BaseException() {
38+
super(BaseCodeEnum.UNSPECIFIED.getDescription());
39+
errorCode = BaseCodeEnum.UNSPECIFIED;
40+
}
41+
42+
/**
43+
* 指定错误码构造通用异常
44+
*
45+
* @param errorCode 错误码
46+
*/
47+
public BaseException(ErrorCode errorCode) {
48+
super(errorCode.getDescription());
49+
this.errorCode = errorCode;
50+
}
51+
52+
/**
53+
* 指定详细描述构造通用异常
54+
*
55+
* @param detailedMessage 详细描述
56+
*/
57+
public BaseException(final String detailedMessage) {
58+
super(detailedMessage);
59+
this.errorCode = BaseCodeEnum.UNSPECIFIED;
60+
}
61+
62+
/**
63+
* 指定导火索构造通用异常
64+
*
65+
* @param t 导火索
66+
*/
67+
public BaseException(final Throwable t) {
68+
super(t);
69+
this.errorCode = BaseCodeEnum.UNSPECIFIED;
70+
}
71+
72+
/**
73+
* 构造通用异常
74+
*
75+
* @param errorCode 错误码
76+
* @param detailedMessage 详细描述
77+
*/
78+
public BaseException(final ErrorCode errorCode, final String detailedMessage) {
79+
super(detailedMessage);
80+
this.errorCode = errorCode;
81+
}
82+
83+
/**
84+
* 构造通用异常
85+
*
86+
* @param errorCode 错误码
87+
* @param t 导火索
88+
*/
89+
public BaseException(final ErrorCode errorCode, final Throwable t) {
90+
super(errorCode.getDescription(), t);
91+
this.errorCode = errorCode;
92+
}
93+
94+
/**
95+
* 构造通用异常
96+
*
97+
* @param detailedMessage 详细描述
98+
* @param t 导火索
99+
*/
100+
public BaseException(final String detailedMessage, final Throwable t) {
101+
super(detailedMessage, t);
102+
this.errorCode = BaseCodeEnum.UNSPECIFIED;
103+
}
104+
105+
/**
106+
* 构造通用异常
107+
*
108+
* @param errorCode 错误码
109+
* @param detailedMessage 详细描述
110+
* @param t 导火索
111+
*/
112+
public BaseException(final ErrorCode errorCode, final String detailedMessage,
113+
final Throwable t) {
114+
super(detailedMessage, t);
115+
this.errorCode = errorCode;
116+
}
117+
118+
/**
119+
* 获取错误码
120+
*
121+
* @return
122+
*/
123+
public ErrorCode getErrorCode() {
124+
return errorCode;
125+
}
126+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.dtstack.flink.sql.exception;
2+
3+
/**
4+
* 错误码
5+
*/
6+
public interface ErrorCode {
7+
8+
/**
9+
* 获取错误码
10+
*
11+
* @return
12+
*/
13+
String getCode();
14+
15+
/**
16+
* 获取错误信息
17+
*
18+
* @return
19+
*/
20+
String getDescription();
21+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package com.dtstack.flink.sql.exception.sqlparse;
20+
21+
import com.dtstack.flink.sql.exception.ErrorCode;
22+
23+
/**
24+
* @author: chuixue
25+
* @create: 2020-11-30 16:56
26+
* @description:sql解析错误码
27+
**/
28+
public enum SqlParseCodeEnum implements ErrorCode {
29+
/**
30+
* 流join维表时,select、join、group by等字段未使用t.field
31+
*/
32+
WITHOUT_TABLENAME("001", "field invalid , please use like t.field"),
33+
;
34+
35+
/**
36+
* 错误码
37+
*/
38+
private final String code;
39+
40+
/**
41+
* 描述
42+
*/
43+
private final String description;
44+
45+
/**
46+
* @param code 错误码
47+
* @param description 描述
48+
*/
49+
private SqlParseCodeEnum(final String code, final String description) {
50+
this.code = code;
51+
this.description = description;
52+
}
53+
54+
@Override
55+
public String getCode() {
56+
return code;
57+
}
58+
59+
@Override
60+
public String getDescription() {
61+
return description;
62+
}
63+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package com.dtstack.flink.sql.exception.sqlparse;
20+
21+
import com.dtstack.flink.sql.exception.BaseException;
22+
import com.dtstack.flink.sql.exception.ErrorCode;
23+
24+
/**
25+
* @author: chuixue
26+
* @create: 2020-11-30 14:49
27+
* @description:流join维表时,select、join、group by等字段未使用t.field
28+
**/
29+
public class WithoutTableNameException extends BaseException {
30+
public WithoutTableNameException(String msg){
31+
super(msg);
32+
}
33+
34+
public WithoutTableNameException(ErrorCode errorCode){
35+
super(errorCode);
36+
}
37+
}

core/src/main/java/com/dtstack/flink/sql/side/JoinNodeDealer.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@
1919

2020
package com.dtstack.flink.sql.side;
2121

22+
import com.dtstack.flink.sql.exception.sqlparse.WithoutTableNameException;
2223
import com.dtstack.flink.sql.parser.FlinkPlanner;
2324
import com.dtstack.flink.sql.util.ParseUtils;
2425
import com.dtstack.flink.sql.util.TableUtils;
2526
import com.esotericsoftware.minlog.Log;
2627
import com.google.common.base.Preconditions;
27-
import com.google.common.collect.*;
28+
import com.google.common.collect.Lists;
29+
import com.google.common.collect.Maps;
30+
import com.google.common.collect.Sets;
31+
import com.google.common.collect.HashBiMap;
2832
import org.apache.calcite.sql.JoinType;
2933
import org.apache.calcite.sql.SqlAsOperator;
3034
import org.apache.calcite.sql.SqlBasicCall;
@@ -39,7 +43,6 @@
3943
import org.apache.calcite.sql.SqlOperator;
4044
import org.apache.calcite.sql.fun.SqlCase;
4145
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
42-
import org.apache.calcite.sql.parser.SqlParser;
4346
import org.apache.calcite.sql.parser.SqlParserPos;
4447
import org.apache.commons.collections.CollectionUtils;
4548
import org.apache.commons.lang3.StringUtils;
@@ -49,6 +52,7 @@
4952
import java.util.Map;
5053
import java.util.Queue;
5154
import java.util.Set;
55+
import java.util.Arrays;
5256

5357
import static org.apache.calcite.sql.SqlKind.*;
5458

@@ -69,6 +73,9 @@ public class JoinNodeDealer {
6973

7074
private FlinkPlanner flinkPlanner = new FlinkPlanner();
7175

76+
// 内置无参函数的临时解决方法,防止被误判为表的字段
77+
private List<String> builtInFunctionNames = Arrays.asList("LOCALTIMESTAMP", "LOCALTIME", "CURRENT_TIMESTAMP", "CURRENT_TIME", "CURRENT_DATE", "PI");
78+
7279
public JoinNodeDealer(SideSQLParser sideSQLParser){
7380
this.sideSQLParser = sideSQLParser;
7481
}
@@ -605,8 +612,12 @@ private void extractSelectField(SqlNode selectNode,
605612
}else if(selectNode.getKind() == IDENTIFIER) {
606613
SqlIdentifier sqlIdentifier = (SqlIdentifier) selectNode;
607614

608-
if(sqlIdentifier.names.size() == 1){
609-
return;
615+
if (sqlIdentifier.names.size() == 1) {
616+
if (builtInFunctionNames.contains(sqlIdentifier.toString().toUpperCase())) {
617+
return;
618+
} else {
619+
throw new WithoutTableNameException(sqlIdentifier + " field invalid , please use like t." + sqlIdentifier);
620+
}
610621
}
611622

612623
String tableName = sqlIdentifier.names.get(0);

0 commit comments

Comments
 (0)