Skip to content

Commit a932515

Browse files
authored
merge from dev/obcloud_202409 into main (#3744)
merge from dev/obcloud_202409 into main
2 parents 46db6fb + 03784c1 commit a932515

File tree

196 files changed

+8909
-983
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+8909
-983
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ maven/
5555
venv/
5656
**/local-unit-test.properties
5757
**/integration-test.properties
58+
**/oss_temp_dir/

libs/db-browser/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
<commons-collections4.version>4.4</commons-collections4.version>
8484
<log4j.version>2.18.0</log4j.version>
8585
<fastjson.version>1.2.83</fastjson.version>
86-
<ob-sql-parser.version>1.3.1</ob-sql-parser.version>
86+
<ob-sql-parser.version>1.4.0</ob-sql-parser.version>
8787
<commons-cli.version>1.4</commons-cli.version>
8888
<oceanbase-client.version>2.4.12</oceanbase-client.version>
8989
<root-project.basedir>${project.basedir}</root-project.basedir>

libs/ob-sql-parser/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.oceanbase</groupId>
66
<artifactId>ob-sql-parser</artifactId>
7-
<version>1.3.1</version>
7+
<version>1.4.0</version>
88
<name>ob-sql-parser</name>
99
<url>https://github.com/oceanbase/odc/tree/main/libs/ob-sql-parser</url>
1010

libs/ob-sql-parser/src/main/java/com/oceanbase/tools/sqlparser/adapter/mysql/MySQLCreateIndexFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public CreateIndex visitCreate_index_stmt(Create_index_stmtContext ctx) {
7373
index.setUnique(true);
7474
} else if (ctx.FULLTEXT() != null) {
7575
index.setFullText(true);
76+
} else if (ctx.VECTOR() != null) {
77+
index.setVector(true);
7678
} else if (ctx.SPATIAL() != null) {
7779
index.setSpatial(true);
7880
}

libs/ob-sql-parser/src/main/java/com/oceanbase/tools/sqlparser/adapter/mysql/MySQLDataTypeFactory.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,19 @@
4444
import com.oceanbase.tools.sqlparser.obmysql.OBParser.Json_type_iContext;
4545
import com.oceanbase.tools.sqlparser.obmysql.OBParser.Number_type_iContext;
4646
import com.oceanbase.tools.sqlparser.obmysql.OBParser.Precision_int_numContext;
47+
import com.oceanbase.tools.sqlparser.obmysql.OBParser.Roaringbitmap_type_iContext;
4748
import com.oceanbase.tools.sqlparser.obmysql.OBParser.String_length_iContext;
4849
import com.oceanbase.tools.sqlparser.obmysql.OBParser.Text_type_iContext;
50+
import com.oceanbase.tools.sqlparser.obmysql.OBParser.Vector_type_iContext;
4951
import com.oceanbase.tools.sqlparser.obmysql.OBParserBaseVisitor;
5052
import com.oceanbase.tools.sqlparser.statement.common.CharacterType;
5153
import com.oceanbase.tools.sqlparser.statement.common.DataType;
5254
import com.oceanbase.tools.sqlparser.statement.common.GeneralDataType;
5355
import com.oceanbase.tools.sqlparser.statement.common.NumberType;
5456
import com.oceanbase.tools.sqlparser.statement.common.TimestampType;
57+
import com.oceanbase.tools.sqlparser.statement.common.mysql.ArrayType;
5558
import com.oceanbase.tools.sqlparser.statement.common.mysql.CollectionType;
59+
import com.oceanbase.tools.sqlparser.statement.common.mysql.VectorType;
5660

5761
import lombok.NonNull;
5862

@@ -85,6 +89,8 @@ public DataType generate() {
8589
public DataType visitData_type(Data_typeContext ctx) {
8690
if (ctx.STRING_VALUE() != null) {
8791
return new GeneralDataType(ctx, ctx.STRING_VALUE().getText(), null);
92+
} else if (ctx.data_type() != null) {
93+
return new ArrayType(visitData_type(ctx.data_type()));
8894
}
8995
return visitChildren(ctx);
9096
}
@@ -283,6 +289,16 @@ public DataType visitCollection_type_i(Collection_type_iContext ctx) {
283289
return type;
284290
}
285291

292+
@Override
293+
public DataType visitVector_type_i(Vector_type_iContext ctx) {
294+
return new VectorType(ctx, ctx.VECTOR().getText(), Integer.valueOf(ctx.INTNUM().getText()));
295+
}
296+
297+
@Override
298+
public DataType visitRoaringbitmap_type_i(Roaringbitmap_type_iContext ctx) {
299+
return new GeneralDataType(ctx, ctx.ROARINGBITMAP().getText(), null);
300+
}
301+
286302
private void setNumberTypeOptions(NumberType numberType, TerminalNode unsigned,
287303
TerminalNode signed, TerminalNode zeroFill) {
288304
if (unsigned != null) {

libs/ob-sql-parser/src/main/java/com/oceanbase/tools/sqlparser/adapter/mysql/MySQLExpressionFactory.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import com.oceanbase.tools.sqlparser.adapter.StatementFactory;
3232
import com.oceanbase.tools.sqlparser.obmysql.OBLexer;
33+
import com.oceanbase.tools.sqlparser.obmysql.OBParser.Any_exprContext;
3334
import com.oceanbase.tools.sqlparser.obmysql.OBParser.Bit_exprContext;
3435
import com.oceanbase.tools.sqlparser.obmysql.OBParser.Bool_priContext;
3536
import com.oceanbase.tools.sqlparser.obmysql.OBParser.Case_exprContext;
@@ -78,6 +79,7 @@
7879
import com.oceanbase.tools.sqlparser.statement.common.CharacterType;
7980
import com.oceanbase.tools.sqlparser.statement.common.GeneralDataType;
8081
import com.oceanbase.tools.sqlparser.statement.common.WindowSpec;
82+
import com.oceanbase.tools.sqlparser.statement.expression.ArrayExpression;
8183
import com.oceanbase.tools.sqlparser.statement.expression.BoolValue;
8284
import com.oceanbase.tools.sqlparser.statement.expression.CaseWhen;
8385
import com.oceanbase.tools.sqlparser.statement.expression.CollectionExpression;
@@ -218,6 +220,9 @@ public Expression visitBool_pri(Bool_priContext ctx) {
218220
} else if (ctx.bool_pri() != null && ctx.select_no_parens() != null) {
219221
left = visit(ctx.bool_pri());
220222
right = visit(ctx.select_no_parens());
223+
} else if (ctx.bool_pri() != null && ctx.any_expr() != null) {
224+
left = visit(ctx.bool_pri());
225+
right = visit(ctx.any_expr());
221226
}
222227
if (left == null || right == null || operator == null) {
223228
throw new IllegalStateException("Unable to build expression, some syntax modules are missing");
@@ -356,7 +361,10 @@ public Expression visitSimple_expr(Simple_exprContext ctx) {
356361
} else if (ctx.expr_const() != null) {
357362
return visit(ctx.expr_const());
358363
} else if (ctx.expr_list() != null) {
359-
if (ctx.ROW() == null) {
364+
if (ctx.ARRAY() != null || (ctx.LeftBracket() != null && ctx.RightBracket() != null)) {
365+
return new ArrayExpression(ctx,
366+
ctx.expr_list().expr().stream().map(this::visit).collect(Collectors.toList()));
367+
} else if (ctx.ROW() == null) {
360368
return visit(ctx.expr_list());
361369
}
362370
List<FunctionParam> params = ctx.expr_list().expr().stream()
@@ -703,6 +711,10 @@ public Expression visitComplex_func_expr(Complex_func_exprContext ctx) {
703711
} else if (ctx.sys_interval_func().CHECK() != null) {
704712
funcName = ctx.sys_interval_func().CHECK().getText();
705713
}
714+
} else if (ctx.vector_distance_expr() != null) {
715+
params = ctx.vector_distance_expr().expr()
716+
.stream().map(this::wrap).collect(Collectors.toList());
717+
funcName = ctx.vector_distance_expr().VECTOR_DISTANCE().getText();
706718
}
707719
if (funcName == null) {
708720
throw new IllegalStateException("Missing function name");
@@ -874,6 +886,14 @@ public Expression visitJson_table_expr(Json_table_exprContext ctx) {
874886
return fCall;
875887
}
876888

889+
@Override
890+
public Expression visitAny_expr(Any_exprContext ctx) {
891+
if (ctx.select_with_parens() != null) {
892+
return new MySQLSelectBodyFactory(ctx.select_with_parens()).generate();
893+
}
894+
return visit(ctx.expr_list());
895+
}
896+
877897
private JsonOnOption getJsonOnOption(Mock_jt_on_error_on_emptyContext ctx) {
878898
return null;
879899
}

libs/ob-sql-parser/src/main/java/com/oceanbase/tools/sqlparser/adapter/mysql/MySQLTableElementFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public TableElement visitOut_of_line_index(Out_of_line_indexContext ctx) {
147147
index.setIndexOptions(getIndexOptions(ctx.index_using_algorithm(), ctx.opt_index_options()));
148148
index.setSpatial(ctx.SPATIAL() != null);
149149
index.setFullText(ctx.FULLTEXT() != null);
150+
index.setVector(ctx.VECTOR() != null);
150151
if (ctx.partition_option() != null) {
151152
index.setPartition(new MySQLPartitionFactory(ctx.partition_option()).generate());
152153
} else if (ctx.auto_partition_option() != null) {

libs/ob-sql-parser/src/main/java/com/oceanbase/tools/sqlparser/adapter/oracle/OracleExpressionFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ private FunctionParam visitFunctionParam(Func_paramContext paramContext) {
12431243
return new ExpressionParam(visit(bitExpr));
12441244
} else if (paramWithAssign != null) {
12451245
// 函数参数带赋值操作
1246-
String varName = paramWithAssign.var_name().getText();
1246+
String varName = paramWithAssign.pl_var_name().getText();
12471247
Bit_exprContext assignExpr = paramWithAssign.bit_expr();
12481248
Expression varValue;
12491249
if (assignExpr != null) {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2023 OceanBase.
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+
package com.oceanbase.tools.sqlparser.statement.common.mysql;
17+
18+
import java.util.Collections;
19+
import java.util.List;
20+
21+
import org.antlr.v4.runtime.ParserRuleContext;
22+
23+
import com.oceanbase.tools.sqlparser.statement.BaseStatement;
24+
import com.oceanbase.tools.sqlparser.statement.common.DataType;
25+
26+
import lombok.EqualsAndHashCode;
27+
import lombok.Getter;
28+
import lombok.NonNull;
29+
import lombok.Setter;
30+
31+
/**
32+
* @Author: Lebie
33+
* @Date: 2024/10/14 17:27
34+
* @Description: []
35+
*/
36+
@Getter
37+
@Setter
38+
@EqualsAndHashCode(callSuper = false)
39+
public class ArrayType extends BaseStatement implements DataType {
40+
private final String typeName = "ARRAY";
41+
private final DataType elementType;
42+
43+
public ArrayType(@NonNull ParserRuleContext context, @NonNull DataType elementType) {
44+
super(context);
45+
this.elementType = elementType;
46+
}
47+
48+
public ArrayType(DataType elementType) {
49+
this.elementType = elementType;
50+
}
51+
52+
@Override
53+
public String getName() {
54+
return this.typeName;
55+
}
56+
57+
@Override
58+
public List<String> getArguments() {
59+
return Collections.emptyList();
60+
}
61+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2023 OceanBase.
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+
package com.oceanbase.tools.sqlparser.statement.common.mysql;
17+
18+
import java.util.Collections;
19+
import java.util.List;
20+
21+
import org.antlr.v4.runtime.ParserRuleContext;
22+
23+
import com.oceanbase.tools.sqlparser.statement.BaseStatement;
24+
import com.oceanbase.tools.sqlparser.statement.common.DataType;
25+
26+
import lombok.EqualsAndHashCode;
27+
import lombok.Getter;
28+
import lombok.NonNull;
29+
import lombok.Setter;
30+
31+
/**
32+
* @Author: Lebie
33+
* @Date: 2024/10/14 17:14
34+
* @Description: []
35+
*/
36+
@Getter
37+
@Setter
38+
@EqualsAndHashCode(callSuper = false)
39+
public class VectorType extends BaseStatement implements DataType {
40+
private final String typeName;
41+
private final Integer dimension;
42+
43+
public VectorType(@NonNull ParserRuleContext context,
44+
@NonNull String typeName, @NonNull Integer dimension) {
45+
super(context);
46+
this.typeName = typeName;
47+
this.dimension = dimension;
48+
}
49+
50+
public VectorType(@NonNull String typeName, @NonNull Integer dimension) {
51+
this.typeName = typeName;
52+
this.dimension = dimension;
53+
}
54+
55+
@Override
56+
public String getName() {
57+
return this.typeName;
58+
}
59+
60+
@Override
61+
public List<String> getArguments() {
62+
return Collections.singletonList(String.valueOf(this.dimension));
63+
}
64+
65+
@Override
66+
public String toString() {
67+
StringBuilder builder = new StringBuilder(getName());
68+
builder.append("(").append(dimension).append(")");
69+
return builder.toString();
70+
}
71+
}

libs/ob-sql-parser/src/main/java/com/oceanbase/tools/sqlparser/statement/createindex/CreateIndex.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class CreateIndex extends BaseStatement {
4646

4747
private boolean fullText;
4848
private boolean spatial;
49+
private boolean vector;
4950
private boolean unique;
5051
private boolean ifNotExists;
5152
private RelationFactor on;
@@ -80,6 +81,9 @@ public String toString() {
8081
if (this.fullText) {
8182
builder.append(" FULLTEXT");
8283
}
84+
if (this.vector) {
85+
builder.append(" VECTOR");
86+
}
8387
if (this.spatial) {
8488
builder.append(" SPATIAL");
8589
}

libs/ob-sql-parser/src/main/java/com/oceanbase/tools/sqlparser/statement/createtable/OutOfLineIndex.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class OutOfLineIndex extends BaseStatement implements TableElement {
4545
private Partition partition;
4646
private boolean fullText;
4747
private boolean spatial;
48+
private boolean vector;
4849
private final String indexName;
4950
private final List<SortColumn> columns;
5051
private List<ColumnGroupElement> columnGroupElements;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2023 OceanBase.
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+
package com.oceanbase.tools.sqlparser.statement.expression;
17+
18+
import java.util.ArrayList;
19+
import java.util.List;
20+
import java.util.stream.Collectors;
21+
22+
import org.antlr.v4.runtime.ParserRuleContext;
23+
24+
import com.oceanbase.tools.sqlparser.statement.Expression;
25+
26+
import lombok.EqualsAndHashCode;
27+
import lombok.Getter;
28+
import lombok.NonNull;
29+
30+
/**
31+
* @Author: Lebie
32+
* @Date: 2024/10/14 21:00
33+
* @Description: []
34+
*/
35+
@Getter
36+
@EqualsAndHashCode(callSuper = true)
37+
public class ArrayExpression extends BaseExpression {
38+
private List<Expression> expressions = new ArrayList<>();
39+
40+
public ArrayExpression(@NonNull ParserRuleContext context, @NonNull List<Expression> expressions) {
41+
super(context);
42+
this.expressions = expressions;
43+
}
44+
45+
public ArrayExpression(@NonNull List<Expression> expressions) {
46+
this.expressions = expressions;
47+
}
48+
49+
@Override
50+
protected String doToString() {
51+
return "[" + this.expressions.stream().map(Object::toString).collect(Collectors.joining(",")) + "]";
52+
}
53+
}

0 commit comments

Comments
 (0)