Skip to content

Commit

Permalink
response to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkPotato777 committed Apr 28, 2024
1 parent 26c1646 commit 20ec1ea
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.oceanbase.odc.common.util.StringUtils;
import com.oceanbase.odc.common.util.YamlUtils;
import com.oceanbase.odc.service.connection.logicaldatabase.model.DataNode;
import com.oceanbase.odc.service.connection.logicaldatabase.parser.LogicalTableService;

import lombok.AllArgsConstructor;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.oceanbase.odc.service.connection.logicaldatabase;
package com.oceanbase.odc.service.connection.logicaldatabase.parser;

import org.apache.commons.lang.StringUtils;
import org.springframework.http.HttpStatus;
Expand All @@ -28,7 +28,7 @@
* @Date: 2024/4/23 14:03
* @Description: []
*/
public class BadExpressionException extends HttpException {
class BadExpressionException extends HttpException {

public BadExpressionException(ErrorCode errorCode, Object[] args, String message) {
super(errorCode, args, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import org.antlr.v4.runtime.ParserRuleContext;

import com.oceanbase.odc.service.connection.logicaldatabase.BadExpressionException;
import com.oceanbase.tools.sqlparser.statement.BaseStatement;

public abstract class BaseLogicalTableExpression extends BaseStatement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import org.antlr.v4.runtime.ParserRuleContext;

import com.oceanbase.odc.service.connection.logicaldatabase.BadExpressionException;
import com.oceanbase.tools.sqlparser.statement.BaseStatement;

public abstract class BaseRangeExpression extends BaseStatement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import org.antlr.v4.runtime.ParserRuleContext;

import com.oceanbase.odc.service.connection.logicaldatabase.BadExpressionException;

import lombok.Getter;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.antlr.v4.runtime.ParserRuleContext;

import com.oceanbase.odc.core.shared.constant.ErrorCodes;
import com.oceanbase.odc.service.connection.logicaldatabase.BadExpressionException;

import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.commons.collections4.CollectionUtils;

import com.oceanbase.odc.core.shared.Verify;
import com.oceanbase.odc.service.connection.logicaldatabase.BadExpressionException;

import lombok.AllArgsConstructor;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import com.oceanbase.odc.core.shared.PreConditions;
import com.oceanbase.odc.core.shared.constant.ErrorCodes;
import com.oceanbase.odc.service.connection.logicaldatabase.BadExpressionException;

/**
* @Author: Lebie
Expand Down Expand Up @@ -70,24 +69,4 @@ public static List<String> listSteppedRanges(String start, String end, String st

return result;
}

public static List<List<String>> cartesianProduct(List<List<String>> lists) {
List<List<String>> result = new ArrayList<>();
cartesianProductRecursive(lists, result, 0, new ArrayList<>());
return result;
}

private static void cartesianProductRecursive(List<List<String>> lists, List<List<String>> result, int depth,
List<String> current) {
if (depth == lists.size()) {
result.add(new ArrayList<>(current));
return;
}

for (String s : lists.get(depth)) {
List<String> newCurrent = new ArrayList<>(current);
newCurrent.add(s);
cartesianProductRecursive(lists, result, depth + 1, newCurrent);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

import org.antlr.v4.runtime.ParserRuleContext;

import com.oceanbase.odc.service.connection.logicaldatabase.BadExpressionException;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.oceanbase.odc.service.connection.logicaldatabase;
package com.oceanbase.odc.service.connection.logicaldatabase.parser;

import java.io.StringReader;
import java.util.List;
Expand All @@ -24,8 +24,6 @@
import com.oceanbase.odc.core.shared.PreConditions;
import com.oceanbase.odc.core.shared.exception.UnexpectedException;
import com.oceanbase.odc.service.connection.logicaldatabase.model.DataNode;
import com.oceanbase.odc.service.connection.logicaldatabase.parser.DefaultLogicalTableExpressionParser;
import com.oceanbase.odc.service.connection.logicaldatabase.parser.LogicalTableExpressions;
import com.oceanbase.tools.sqlparser.SyntaxErrorException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import org.apache.commons.collections.CollectionUtils;

import com.oceanbase.odc.common.lang.Pair;
import com.oceanbase.odc.common.util.ListUtils;
import com.oceanbase.odc.core.shared.PreConditions;
import com.oceanbase.odc.service.connection.logicaldatabase.BadExpressionException;

import lombok.AllArgsConstructor;
import lombok.Data;
Expand Down Expand Up @@ -60,9 +60,8 @@ public List<String> evaluate() throws BadExpressionException {
.map(stmt -> new Pair<>(stmt.getStart() - this.getStart(), stmt.getStop() - this.getStart()))
.collect(
Collectors.toList());
List<List<String>> ranges = LogicalTableExpressionParseUtils
.cartesianProduct(sliceRanges.stream().map(BaseRangeExpression::listRanges)
.collect(Collectors.toList()));
List<List<String>> ranges = ListUtils.cartesianProduct(sliceRanges.stream().map(BaseRangeExpression::listRanges)
.collect(Collectors.toList()));
List<String> names = new ArrayList<>();
/**
* we need to iterate in reverse order to replace the ranges from right to left; otherwise, we may
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import org.antlr.v4.runtime.ParserRuleContext;

import com.oceanbase.odc.service.connection.logicaldatabase.BadExpressionException;

import lombok.Getter;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2023 OceanBase.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

grammar LogicalTableExpression;
@header {
package com.oceanbase.odc.service.connection.logicaldatabase;
Expand Down

0 comments on commit 20ec1ea

Please sign in to comment.