diff --git a/pom.xml b/pom.xml index d08c07677c344..5bef146c830d1 100644 --- a/pom.xml +++ b/pom.xml @@ -121,7 +121,6 @@ 42.7.2 8.3.0 6.1.7.jre8-preview - 1.7.1 2.2.224 3.1.0-og 2.4.2 @@ -453,11 +452,6 @@ ${mssql.version} test - - org.apache.hbase - hbase-shaded-client - ${hbase.client.version} - org.opengauss opengauss-jdbc diff --git a/proxy/backend/type/hbase/pom.xml b/proxy/backend/type/hbase/pom.xml deleted file mode 100644 index bd4227f3e44bf..0000000000000 --- a/proxy/backend/type/hbase/pom.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - 4.0.0 - - org.apache.shardingsphere - shardingsphere-proxy-backend-type - 5.5.1-SNAPSHOT - - shardingsphere-proxy-backend-hbase - ${project.artifactId} - - - - org.apache.shardingsphere - shardingsphere-infra-util - ${project.version} - - - org.apache.shardingsphere - shardingsphere-infra-executor - ${project.version} - - - - org.apache.shardingsphere - shardingsphere-proxy-backend-core - ${project.version} - compile - - - - org.apache.shardingsphere - shardingsphere-test-util - ${project.version} - test - - - - org.apache.hbase - hbase-shaded-client - - - diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/bean/HBaseCluster.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/bean/HBaseCluster.java deleted file mode 100644 index 993b87e3f5398..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/bean/HBaseCluster.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.bean; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.apache.hadoop.hbase.client.Connection; - -/** - * HBase cluster. - */ -@RequiredArgsConstructor -@Getter -public final class HBaseCluster { - - private final String clusterName; - - private final Connection connection; -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/bean/HBaseOperation.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/bean/HBaseOperation.java deleted file mode 100644 index 11809d7b25ca7..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/bean/HBaseOperation.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.bean; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.apache.hadoop.hbase.client.Operation; - -/** - * HBase operation. - */ -@RequiredArgsConstructor -@Getter -public final class HBaseOperation { - - private final String tableName; - - private final Operation operation; -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/CommonHeterogeneousSQLStatementChecker.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/CommonHeterogeneousSQLStatementChecker.java deleted file mode 100644 index 915f637ac41bd..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/CommonHeterogeneousSQLStatementChecker.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.checker; - -import com.google.common.base.Preconditions; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.InExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ListExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.ParameterMarkerExpressionSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; - -import java.util.Arrays; -import java.util.List; - -/** - * Common heterogeneous SQL statement checker. - */ -@RequiredArgsConstructor -@Getter -public class CommonHeterogeneousSQLStatementChecker implements HeterogeneousSQLStatementChecker { - - protected static final List ALLOW_KEYS = Arrays.asList("rowKey", "row_key", "key", "pk", "id"); - - private final SQLStatement sqlStatement; - - protected final void checkIsSinglePointQuery(final WhereSegment whereSegment) { - ExpressionSegment whereExpr = whereSegment.getExpr(); - Preconditions.checkArgument(whereExpr instanceof BinaryOperationExpression, "Only support binary operation expression."); - BinaryOperationExpression expression = (BinaryOperationExpression) whereExpr; - Preconditions.checkArgument(!(expression.getLeft() instanceof BinaryOperationExpression), "Do not supported multiple expressions."); - Preconditions.checkArgument(expression.getLeft() instanceof ColumnSegment, "Left segment must column segment."); - Preconditions.checkArgument("=".equals(expression.getOperator()), "Only Supported `=` operator."); - String rowKey = ((ColumnSegment) expression.getLeft()).getIdentifier().getValue(); - boolean isAllowKey = ALLOW_KEYS.stream().anyMatch(each -> each.equalsIgnoreCase(rowKey)); - Preconditions.checkArgument(isAllowKey, String.format("%s is not a allowed key.", rowKey)); - } - - /** - * Check value is literal or parameter marker. - * - * @param expressionSegment value segment - * @return is supported - */ - protected final boolean isAllowExpressionSegment(final ExpressionSegment expressionSegment) { - return expressionSegment instanceof LiteralExpressionSegment || expressionSegment instanceof ParameterMarkerExpressionSegment; - } - - /** - * Check in expression. - * - * @param whereExpr In expression - */ - protected final void checkInExpressionIsExpected(final ExpressionSegment whereExpr) { - InExpression expression = (InExpression) whereExpr; - Preconditions.checkArgument(expression.getLeft() instanceof ColumnSegment, "Left segment must column segment."); - String rowKey = ((ColumnSegment) expression.getLeft()).getIdentifier().getValue(); - boolean isAllowKey = ALLOW_KEYS.stream().anyMatch(each -> each.equalsIgnoreCase(rowKey)); - Preconditions.checkArgument(isAllowKey, String.format("%s is not a allowed key.", rowKey)); - Preconditions.checkArgument(!expression.isNot(), "Do not supported `not in`."); - Preconditions.checkArgument(expression.getRight() instanceof ListExpression, "Only supported list expression."); - } - - @Override - public void execute() { - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HBaseCheckerFactory.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HBaseCheckerFactory.java deleted file mode 100644 index 262e03ddd84d0..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HBaseCheckerFactory.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.checker; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.DeleteStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.InsertStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.SelectStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.UpdateStatement; - -/** - * HBase checker factory. - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class HBaseCheckerFactory { - - /** - * Create new instance of HBase checker. - * - * @param sqlStatement SQL statement - * @return created instance - */ - public static HeterogeneousSQLStatementChecker newInstance(final SQLStatement sqlStatement) { - if (sqlStatement instanceof SelectStatement) { - return new HeterogeneousSelectStatementChecker((SelectStatement) sqlStatement); - } - if (sqlStatement instanceof InsertStatement) { - return new HeterogeneousInsertStatementChecker((InsertStatement) sqlStatement); - } - if (sqlStatement instanceof DeleteStatement) { - return new HeterogeneousDeleteStatementChecker((DeleteStatement) sqlStatement); - } - if (sqlStatement instanceof UpdateStatement) { - return new HeterogeneousUpdateStatementChecker((UpdateStatement) sqlStatement); - } - return new CommonHeterogeneousSQLStatementChecker(sqlStatement); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousDeleteStatementChecker.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousDeleteStatementChecker.java deleted file mode 100644 index a4af3275080e2..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousDeleteStatementChecker.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.checker; - -import com.google.common.base.Preconditions; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.InExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.DeleteStatement; - -import java.util.Optional; - -/** - * Delete statement checker. - */ -public final class HeterogeneousDeleteStatementChecker extends CommonHeterogeneousSQLStatementChecker { - - private final DeleteStatement sqlStatement; - - public HeterogeneousDeleteStatementChecker(final DeleteStatement sqlStatement) { - super(sqlStatement); - this.sqlStatement = sqlStatement; - } - - @Override - public void execute() { - Optional whereSegment = sqlStatement.getWhere(); - Preconditions.checkArgument(whereSegment.isPresent(), "Must contain where segment."); - if (whereSegment.get().getExpr() instanceof InExpression) { - checkInExpressionIsExpected(whereSegment.get().getExpr()); - } else { - checkIsSinglePointQuery(whereSegment.get()); - } - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousInsertStatementChecker.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousInsertStatementChecker.java deleted file mode 100644 index dbd8f614adaa4..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousInsertStatementChecker.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.checker; - -import com.google.common.base.Preconditions; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.InsertValuesSegment; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.InsertStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLInsertStatement; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -/** - * Insert statement checker. - */ -public final class HeterogeneousInsertStatementChecker extends CommonHeterogeneousSQLStatementChecker { - - private final InsertStatement sqlStatement; - - public HeterogeneousInsertStatementChecker(final InsertStatement sqlStatement) { - super(sqlStatement); - this.sqlStatement = sqlStatement; - } - - @Override - public void execute() { - checkIsExistsRowKeyInInsertColumns(); - checkIsExistsSubQuery(); - checkValueIsExpected(); - checkOnDuplicateKey(); - } - - private void checkIsExistsRowKeyInInsertColumns() { - List columns = sqlStatement.getColumns().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList()); - Preconditions.checkArgument(!columns.isEmpty(), "The inserted column must be explicitly specified."); - Preconditions.checkArgument(ALLOW_KEYS.stream().anyMatch(each -> each.equalsIgnoreCase(columns.get(0))), "First column must be rowKey."); - boolean isExists = columns.subList(1, columns.size()).stream().anyMatch(ALLOW_KEYS::contains); - Preconditions.checkArgument(!isExists, "Cannot contain multiple rowKeys."); - } - - private void checkIsExistsSubQuery() { - Preconditions.checkArgument(!sqlStatement.getInsertSelect().isPresent(), "Do not supported `insert into...select...`"); - } - - private void checkValueIsExpected() { - Collection values = sqlStatement.getValues(); - for (InsertValuesSegment insertValuesSegment : values) { - boolean isAllMatch = insertValuesSegment.getValues().stream().allMatch(this::isAllowExpressionSegment); - Preconditions.checkArgument(isAllMatch, "Value must is literal or parameter marker."); - } - } - - private void checkOnDuplicateKey() { - Preconditions.checkArgument(!((MySQLInsertStatement) sqlStatement).getOnDuplicateKeyColumns().isPresent(), "Do not supported ON DUPLICATE KEY UPDATE"); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousSQLStatementChecker.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousSQLStatementChecker.java deleted file mode 100644 index 0d137fa4289be..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousSQLStatementChecker.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.checker; - -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; - -/** - * Check where clause. - */ -public interface HeterogeneousSQLStatementChecker { - - /** - * Get SQL statement. - * - * @return SQL statement - */ - SQLStatement getSqlStatement(); - - /** - * do check. - */ - void execute(); -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousSelectStatementChecker.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousSelectStatementChecker.java deleted file mode 100644 index 8d2bfd78f1a91..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousSelectStatementChecker.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.checker; - -import com.google.common.base.Preconditions; -import org.apache.shardingsphere.proxy.backend.hbase.context.HBaseContext; -import org.apache.shardingsphere.proxy.backend.hbase.props.HBasePropertyKey; -import org.apache.shardingsphere.proxy.backend.hbase.util.HBaseHeterogeneousUtils; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BetweenExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.InExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ColumnProjectionSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ShorthandProjectionSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.order.item.ColumnOrderByItemSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.order.item.OrderByItemSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.pagination.PaginationValueSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.pagination.limit.LimitSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.pagination.limit.NumberLiteralLimitValueSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.SelectStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLSelectStatement; - -import java.util.Optional; - -/** - * Select statement checker. - */ -public final class HeterogeneousSelectStatementChecker extends CommonHeterogeneousSQLStatementChecker { - - private final SelectStatement sqlStatement; - - public HeterogeneousSelectStatementChecker(final SelectStatement sqlStatement) { - super(sqlStatement); - this.sqlStatement = sqlStatement; - } - - @Override - public void execute() { - checkProjectionsIsExpected(); - checkDoNotSupportedSegment(); - checkSupportedWhereSegment(); - checkSupportedOrderBySegment(); - } - - private void checkDoNotSupportedSegment() { - Preconditions.checkArgument(sqlStatement.getFrom().isPresent() && sqlStatement.getFrom().get() instanceof SimpleTableSegment, "Only supported simple table segment."); - Preconditions.checkArgument(!sqlStatement.getHaving().isPresent(), "Do not supported having segment."); - Preconditions.checkArgument(!sqlStatement.getGroupBy().isPresent(), "Do not supported group by segment."); - MySQLSelectStatement selectStatement = (MySQLSelectStatement) sqlStatement; - Preconditions.checkArgument(!selectStatement.getWindow().isPresent(), "Do not supported window segment."); - Preconditions.checkArgument(!selectStatement.getLock().isPresent(), "Do not supported lock segment."); - Optional limitSegment = selectStatement.getLimit(); - if (limitSegment.isPresent()) { - Preconditions.checkArgument(!limitSegment.get().getOffset().isPresent(), "Do not supported offset segment."); - Optional paginationSegment = selectStatement.getLimit().flatMap(LimitSegment::getRowCount); - Long maxScanLimitSize = HBaseContext.getInstance().getProps().getValue(HBasePropertyKey.MAX_SCAN_LIMIT_SIZE); - paginationSegment.ifPresent(optional -> Preconditions.checkArgument(((NumberLiteralLimitValueSegment) optional).getValue() <= maxScanLimitSize, "Row count must less than 5000.")); - } - } - - private void checkProjectionsIsExpected() { - for (ProjectionSegment projectionSegment : sqlStatement.getProjections().getProjections()) { - if (!(projectionSegment instanceof ShorthandProjectionSegment || projectionSegment instanceof ColumnProjectionSegment || HBaseHeterogeneousUtils.isCrcProjectionSegment( - projectionSegment))) { - throw new IllegalArgumentException("Only supported shorthand, column and crc32 expression projections."); - } - } - } - - private void checkSupportedWhereSegment() { - Optional whereSegment = sqlStatement.getWhere(); - if (!whereSegment.isPresent()) { - return; - } - ExpressionSegment whereExpr = whereSegment.get().getExpr(); - if (whereExpr instanceof BinaryOperationExpression) { - checkIsSinglePointQuery(whereSegment.get()); - } else if (whereExpr instanceof InExpression) { - checkInExpressionIsExpected(whereExpr); - } else if (whereExpr instanceof BetweenExpression) { - checkBetweenExpressionIsExpected(whereExpr); - } else { - throw new IllegalArgumentException("Only supported =、in、between...and..."); - } - } - - private void checkBetweenExpressionIsExpected(final ExpressionSegment whereExpr) { - BetweenExpression expression = (BetweenExpression) whereExpr; - Preconditions.checkArgument(expression.getLeft() instanceof ColumnSegment, "Left segment must column segment."); - String rowKey = ((ColumnSegment) expression.getLeft()).getIdentifier().getValue(); - boolean isAllowKey = ALLOW_KEYS.stream().anyMatch(each -> each.equalsIgnoreCase(rowKey)); - Preconditions.checkArgument(isAllowKey, String.format("%s is not a allowed key.", rowKey)); - Preconditions.checkArgument(!expression.isNot(), "Do not supported `not between...and...`"); - Preconditions.checkArgument(isAllowExpressionSegment(expression.getBetweenExpr()), "Between expr must literal or parameter marker."); - Preconditions.checkArgument(isAllowExpressionSegment(expression.getAndExpr()), "Between expr must literal or parameter marker."); - } - - private void checkSupportedOrderBySegment() { - if (!sqlStatement.getOrderBy().isPresent()) { - return; - } - for (OrderByItemSegment orderByItemSegment : sqlStatement.getOrderBy().get().getOrderByItems()) { - if (!(orderByItemSegment instanceof ColumnOrderByItemSegment)) { - throw new IllegalArgumentException("Only simple row key order by."); - } - if (!"rowKey".equalsIgnoreCase(((ColumnOrderByItemSegment) orderByItemSegment).getColumn().getIdentifier().getValue())) { - throw new IllegalArgumentException("Only simple row key order by."); - } - } - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousUpdateStatementChecker.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousUpdateStatementChecker.java deleted file mode 100644 index 2b527322ce77b..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousUpdateStatementChecker.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.checker; - -import com.google.common.base.Preconditions; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.ColumnAssignmentSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.InExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.UpdateStatement; - -import java.util.Collection; -import java.util.Optional; - -/** - * Update statement checker. - */ -public final class HeterogeneousUpdateStatementChecker extends CommonHeterogeneousSQLStatementChecker { - - private final UpdateStatement sqlStatement; - - public HeterogeneousUpdateStatementChecker(final UpdateStatement sqlStatement) { - super(sqlStatement); - this.sqlStatement = sqlStatement; - } - - @Override - public void execute() { - Optional whereSegment = sqlStatement.getWhere(); - Preconditions.checkArgument(whereSegment.isPresent(), "Must contain where segment."); - if (whereSegment.get().getExpr() instanceof InExpression) { - checkInExpressionIsExpected(whereSegment.get().getExpr()); - } else { - checkIsSinglePointQuery(whereSegment.get()); - } - checkAssignmentIsOk(); - } - - private void checkAssignmentIsOk() { - Collection assignmentSegments = sqlStatement.getSetAssignment().getAssignments(); - for (ColumnAssignmentSegment assignmentSegment : assignmentSegments) { - Preconditions.checkArgument(isAllowExpressionSegment(assignmentSegment.getValue()), "Assignment must is literal or parameter marker."); - boolean isRowKey = ALLOW_KEYS.stream().anyMatch(each -> each.equalsIgnoreCase(assignmentSegment.getColumns().iterator().next().getIdentifier().getValue())); - Preconditions.checkArgument(!isRowKey, "Do not allow update rowKey"); - } - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/config/YamlHBaseConfiguration.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/config/YamlHBaseConfiguration.java deleted file mode 100644 index fce5a0912e65c..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/config/YamlHBaseConfiguration.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.config; - -import lombok.Getter; -import lombok.Setter; -import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -/** - * YAML rule configuration for HBase. - */ -@Getter -@Setter -public final class YamlHBaseConfiguration implements YamlConfiguration { - - private String databaseName; - - private Map commonDataSourcePoolProps; - - private Map dataSources = new HashMap<>(); - - private Properties props; -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/config/YamlHBaseParameter.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/config/YamlHBaseParameter.java deleted file mode 100644 index 0dc83b0513203..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/config/YamlHBaseParameter.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.config; - -import lombok.Getter; -import lombok.Setter; -import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration; - -/** - * YAML Data source parameters for HBase. - */ -@Getter -@Setter -public final class YamlHBaseParameter implements YamlConfiguration { - - private String hbaseZookeeperQuorum; - - private String fsDefaultFs; - - private String hbaseRootDir; - - private long hbaseRpcTimeout; - - private long hbaseClientOperationTimeout; - - private long hbaseClientScannerTimeoutPeriod; - - private String hbaseZookeeperPropertyDataDir; - - private String zookeeperZNodeParent; - - private String accessUser; - - private int ipcPoolSize = 1; -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/connector/HBaseConnectionFactory.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/connector/HBaseConnectionFactory.java deleted file mode 100644 index 2b0703cc4d8e1..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/connector/HBaseConnectionFactory.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.connector; - -import com.google.common.base.Strings; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.hbase.client.Connection; -import org.apache.hadoop.hbase.client.ConnectionFactory; -import org.apache.hadoop.hbase.security.User; -import org.apache.hadoop.security.UserGroupInformation; -import org.apache.shardingsphere.proxy.backend.hbase.config.YamlHBaseConfiguration; -import org.apache.shardingsphere.proxy.backend.hbase.config.YamlHBaseParameter; - -import java.io.IOException; -import java.sql.SQLException; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Map.Entry; - -/** - * Connection factory of HBase. - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class HBaseConnectionFactory { - - /** - * Create HBase connection. - * - * @param yamlProxyHBaseConfig YAML HBase configuration - * @return A connection for per HBase cluster - * @throws SQLException SQL exception - */ - public static Map createHBaseConnections(final YamlHBaseConfiguration yamlProxyHBaseConfig) throws SQLException { - Map result = new LinkedHashMap<>(yamlProxyHBaseConfig.getDataSources().size(), 1F); - for (Entry entry : yamlProxyHBaseConfig.getDataSources().entrySet()) { - result.put(entry.getKey(), createConnection(entry.getValue())); - } - return result; - } - - private static Connection createConnection(final YamlHBaseParameter parameter) throws SQLException { - Configuration config = createConfiguration(parameter); - try { - return Strings.isNullOrEmpty(parameter.getAccessUser()) - ? ConnectionFactory.createConnection(config) - : ConnectionFactory.createConnection(config, User.create(UserGroupInformation.createRemoteUser(parameter.getAccessUser()))); - } catch (final IOException ex) { - throw new SQLException(ex); - } - } - - private static Configuration createConfiguration(final YamlHBaseParameter parameter) { - Configuration result = HBaseConfiguration.create(); - result.set("fs.defaultFS", parameter.getFsDefaultFs()); - result.set("hbase.rootdir", parameter.getHbaseRootDir()); - result.setLong("hbase.rpc.timeout", parameter.getHbaseRpcTimeout()); - result.setLong("hbase.client.operation.timeout", parameter.getHbaseClientOperationTimeout()); - result.setLong("hbase.client.scanner.timeout.period", parameter.getHbaseClientScannerTimeoutPeriod()); - result.set("hbase.zookeeper.property.dataDir", parameter.getHbaseZookeeperPropertyDataDir()); - result.set("hbase.zookeeper.quorum", parameter.getHbaseZookeeperQuorum()); - result.set("zookeeper.znode.parent", parameter.getZookeeperZNodeParent()); - result.setInt("hbase.client.ipc.pool.size", parameter.getIpcPoolSize()); - return result; - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/context/HBaseContext.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/context/HBaseContext.java deleted file mode 100644 index 7a8d06f02ed51..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/context/HBaseContext.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.context; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; -import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.client.Admin; -import org.apache.hadoop.hbase.client.Connection; -import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; -import org.apache.shardingsphere.infra.exception.kernel.metadata.TableNotFoundException; -import org.apache.shardingsphere.proxy.backend.hbase.bean.HBaseCluster; -import org.apache.shardingsphere.proxy.backend.hbase.executor.HBaseBackgroundExecutorManager; -import org.apache.shardingsphere.proxy.backend.hbase.executor.HBaseExecutor; -import org.apache.shardingsphere.proxy.backend.hbase.props.HBaseProperties; -import org.apache.shardingsphere.proxy.backend.hbase.props.HBasePropertyKey; - -import java.io.IOException; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; - -/** - * HBase context. - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -@Getter -@Slf4j -public final class HBaseContext implements AutoCloseable { - - private static final HBaseContext INSTANCE = new HBaseContext(); - - private final HBaseBackgroundExecutorManager executorManager = new HBaseBackgroundExecutorManager(); - - private HBaseRegionWarmUpContext warmUpContext; - - @Setter - private HBaseProperties props; - - private final String columnFamily = "i"; - - private Collection connections; - - private boolean isSyncWarmUp; - - private final Map tableConnectionMap = new ConcurrentHashMap<>(); - - /** - * Get instance of HBase context. - * - * @return got instance - */ - public static HBaseContext getInstance() { - return INSTANCE; - } - - /** - * Initialize HBase context. - * - * @param connections A connection for per HBase cluster - * @throws SQLException SQL exception - */ - public void init(final Map connections) throws SQLException { - this.connections = new ArrayList<>(connections.size()); - warmUpContext = HBaseRegionWarmUpContext.getInstance(); - warmUpContext.init(getWarmUpThreadSize()); - isSyncWarmUp = HBaseContext.getInstance().getProps().getValue(HBasePropertyKey.IS_SYNC_WARM_UP); - for (Entry entry : connections.entrySet()) { - HBaseCluster cluster = new HBaseCluster(entry.getKey(), entry.getValue()); - loadTables(cluster); - this.connections.add(cluster); - } - log.info("{} tables loaded from {} clusters.", tableConnectionMap.size(), connections.size()); - } - - /** - * Get warm up thread size. - * - * @return warm up thread size, value should be in (0, 30] - */ - private int getWarmUpThreadSize() { - int warmUpThreadSize = HBaseContext.getInstance().getProps().getValue(HBasePropertyKey.WARM_UP_THREAD_NUM); - return warmUpThreadSize < 0 ? 1 : Math.min(warmUpThreadSize, 30); - } - - /** - * Load tables. - * - * @param hbaseCluster HBase cluster - * @throws SQLException SQL exception - */ - public synchronized void loadTables(final HBaseCluster hbaseCluster) throws SQLException { - warmUpContext.initStatisticsInfo(System.currentTimeMillis()); - HTableDescriptor[] hTableDescriptor = HBaseExecutor.executeAdmin(hbaseCluster.getConnection(), Admin::listTables); - for (String each : Arrays.stream(hTableDescriptor).map(HTableDescriptor::getNameAsString).collect(Collectors.toList())) { - if (tableConnectionMap.containsKey(each)) { - continue; - } - warmUpContext.addNeedWarmCount(); - log.info("Load table `{}` from cluster `{}`.", each, hbaseCluster.getClusterName()); - tableConnectionMap.put(each, hbaseCluster); - warmUpContext.submitWarmUpTask(each, hbaseCluster); - } - if (isSyncWarmUp) { - warmUpContext.syncExecuteWarmUp(hbaseCluster.getClusterName()); - warmUpContext.clear(); - } - } - - /** - * Get connection via table name. - * - * @param tableName table name - * @return HBase connection - */ - public Connection getConnection(final String tableName) { - ShardingSpherePreconditions.checkContainsKey(tableConnectionMap, tableName, () -> new TableNotFoundException(tableName)); - return tableConnectionMap.get(tableName).getConnection(); - } - - /** - * Is table exists. - * - * @param tableName table name - * @return table exists or not - */ - public boolean isTableExists(final String tableName) { - return tableConnectionMap.containsKey(tableName); - } - - /** - * Get connection via cluster name. - * - * @param clusterName cluster name - * @return HBase connection - * @throws SQLException SQL exception - */ - public Connection getConnectionByClusterName(final String clusterName) throws SQLException { - HBaseCluster cluster = connections.stream().filter(each -> each.getClusterName().equalsIgnoreCase(clusterName)).findFirst() - .orElseThrow(() -> new SQLException(String.format("Cluster `%s` is not exists", clusterName))); - return cluster.getConnection(); - } - - @Override - public void close() throws SQLException { - connections.clear(); - tableConnectionMap.clear(); - executorManager.close(); - for (Connection connection : connections.stream().map(HBaseCluster::getConnection).collect(Collectors.toList())) { - try { - connection.close(); - } catch (final IOException ex) { - throw new SQLException(ex); - } - } - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/context/HBaseMetaDataRefresher.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/context/HBaseMetaDataRefresher.java deleted file mode 100644 index c32549396cbb1..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/context/HBaseMetaDataRefresher.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.context; - -import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.proxy.backend.hbase.bean.HBaseCluster; - -import java.sql.SQLException; - -/** - * HBase meta data refresher. - */ -@RequiredArgsConstructor -public final class HBaseMetaDataRefresher implements Runnable { - - private final HBaseContext context; - - @Override - public void run() { - for (HBaseCluster hBaseCluster : context.getConnections()) { - try { - context.loadTables(hBaseCluster); - } catch (final SQLException ignored) { - } - } - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/context/HBaseRegionWarmUpContext.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/context/HBaseRegionWarmUpContext.java deleted file mode 100644 index ccf7b2a84d8d0..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/context/HBaseRegionWarmUpContext.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.context; - -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; -import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.client.Connection; -import org.apache.hadoop.hbase.client.RegionLocator; -import org.apache.shardingsphere.proxy.backend.hbase.bean.HBaseCluster; -import org.apache.shardingsphere.proxy.backend.hbase.executor.HBaseTaskExecutorManager; - -import java.io.IOException; -import java.sql.SQLException; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * HBase region warn up context. - */ -@Getter -@Slf4j -public final class HBaseRegionWarmUpContext { - - private static final HBaseRegionWarmUpContext INSTANCE = new HBaseRegionWarmUpContext(); - - private final AtomicInteger executeCount = new AtomicInteger(0); - - private final AtomicInteger tableCount = new AtomicInteger(0); - - private HBaseTaskExecutorManager executorManager; - - private long startWarmUpTime; - - /** - * Get instance of HBase context. - * - * @return instance of HBase context - */ - public static HBaseRegionWarmUpContext getInstance() { - return INSTANCE; - } - - /** - * Init. - * - * @param poolSize execute pool size - */ - public void init(final int poolSize) { - executorManager = new HBaseTaskExecutorManager(poolSize); - } - - /** - * Submit region warm up task. - * - * @param tableName table name - * @param hbaseCluster HBase cluster - */ - public void submitWarmUpTask(final String tableName, final HBaseCluster hbaseCluster) { - executorManager.submit(() -> loadRegionInfo(tableName, hbaseCluster)); - } - - /** - * Load one table region info. - * - * @param tableName table name - * @param connection HBase connection - * @throws SQLException SQL exception - */ - public void loadRegionInfo(final String tableName, final Connection connection) throws SQLException { - HBaseRegionWarmUpContext.getInstance().addExecuteCount(); - try { - if (null == connection) { - return; - } - RegionLocator regionLocator = connection.getRegionLocator(TableName.valueOf(tableName)); - regionLocator.getAllRegionLocations(); - } catch (final IOException ex) { - throw new SQLException(String.format("Table '%s' warm up error.", tableName), ex); - } - } - - private void loadRegionInfo(final String tableName, final HBaseCluster hbaseCluster) { - try { - RegionLocator regionLocator = hbaseCluster.getConnection().getRegionLocator(TableName.valueOf(tableName)); - warmUpRegion(regionLocator); - HBaseRegionWarmUpContext.getInstance().addExecuteCount(); - } catch (final IOException ex) { - log.error(String.format("Table: `%s` load region info error, reason is %s", tableName, ex)); - } - } - - private void warmUpRegion(final RegionLocator regionLocator) throws IOException { - regionLocator.getAllRegionLocations(); - } - - /** - * Init statistics info. - * - * @param startWarmUpTime start warm up time - */ - public void initStatisticsInfo(final long startWarmUpTime) { - this.startWarmUpTime = startWarmUpTime; - } - - /** - * Execute count add one. - */ - public void addExecuteCount() { - executeCount.incrementAndGet(); - } - - /** - * All need warm up table add one. - */ - public void addNeedWarmCount() { - tableCount.incrementAndGet(); - } - - /** - * Sync execute. - * - * @param clusterName cluster name - */ - public void syncExecuteWarmUp(final String clusterName) { - while (executeCount.get() < tableCount.get()) { - try { - Thread.sleep(100L); - } catch (final InterruptedException ignore) { - Thread.currentThread().interrupt(); - } - } - log.info(String.format("%s cluster end warm up, execute time: %dms, warm table: %d", clusterName, System.currentTimeMillis() - startWarmUpTime, executeCount.get())); - } - - /** - * Clear statistics info. - */ - public void clear() { - tableCount.set(0); - executeCount.set(0); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/HBaseOperationConverter.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/HBaseOperationConverter.java deleted file mode 100644 index c2a42a4ba624e..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/HBaseOperationConverter.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.converter; - -import org.apache.shardingsphere.proxy.backend.hbase.bean.HBaseOperation; - -/** - * Convert SQL statement to HBase operation. - */ -public interface HBaseOperationConverter { - - /** - * Convert SQL statement to HBase operation. - * - * @return HBase operation - */ - HBaseOperation convert(); -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/HBaseOperationConverterFactory.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/HBaseOperationConverterFactory.java deleted file mode 100644 index 73e57e5feb693..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/HBaseOperationConverterFactory.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.converter; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.binder.context.statement.dal.FlushStatementContext; -import org.apache.shardingsphere.infra.binder.context.statement.dml.DeleteStatementContext; -import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; -import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; -import org.apache.shardingsphere.infra.binder.context.statement.dml.UpdateStatementContext; -import org.apache.shardingsphere.proxy.backend.hbase.converter.type.HBaseDeleteOperationConverter; -import org.apache.shardingsphere.proxy.backend.hbase.converter.type.HBaseInsertOperationConverter; -import org.apache.shardingsphere.proxy.backend.hbase.converter.type.HBaseRegionReloadOperationConverter; -import org.apache.shardingsphere.proxy.backend.hbase.converter.type.HBaseSelectOperationConverter; -import org.apache.shardingsphere.proxy.backend.hbase.converter.type.HBaseUpdateOperationConverter; - -import java.sql.SQLException; - -/** - * HBase operation converter factory. - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class HBaseOperationConverterFactory { - - /** - * Create new instance of HBase operation converter. - * - * @param sqlStatementContext SQL statement context - * @return instance of converter - * @throws SQLException SQL exception - */ - public static HBaseOperationConverter newInstance(final SQLStatementContext sqlStatementContext) throws SQLException { - if (sqlStatementContext instanceof SelectStatementContext) { - return new HBaseSelectOperationConverter(sqlStatementContext); - } - if (sqlStatementContext instanceof InsertStatementContext) { - return new HBaseInsertOperationConverter(sqlStatementContext); - } - if (sqlStatementContext instanceof DeleteStatementContext) { - return new HBaseDeleteOperationConverter(sqlStatementContext); - } - if (sqlStatementContext instanceof UpdateStatementContext) { - return new HBaseUpdateOperationConverter(sqlStatementContext); - } - if (sqlStatementContext instanceof FlushStatementContext) { - return new HBaseRegionReloadOperationConverter(sqlStatementContext); - } - throw new SQLException("Can not find HBase converter."); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/HBaseRowKeyExtractor.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/HBaseRowKeyExtractor.java deleted file mode 100644 index 4fa799dbfe84c..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/HBaseRowKeyExtractor.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.converter; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.InExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ListExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment; - -import java.util.List; -import java.util.stream.Collectors; - -/** - * HBase row key extractor. - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class HBaseRowKeyExtractor { - - /** - * Get row keys from binary operation expression. - * - * @param expr binary operation expression - * @return row keys - */ - public static String getRowKey(final BinaryOperationExpression expr) { - return String.valueOf(((LiteralExpressionSegment) expr.getRight()).getLiterals()); - } - - /** - * Get row keys from in expression. - * - * @param expr in expression - * @return row keys - */ - public static List getRowKeys(final InExpression expr) { - return ((ListExpression) expr.getRight()).getItems().stream().map(each -> String.valueOf(((LiteralExpressionSegment) each).getLiterals())).collect(Collectors.toList()); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/operation/HBaseDeleteOperation.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/operation/HBaseDeleteOperation.java deleted file mode 100644 index 477a4066429a7..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/operation/HBaseDeleteOperation.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.converter.operation; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.apache.hadoop.hbase.client.Delete; -import org.apache.hadoop.hbase.client.Operation; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * HBase delete operation. - */ -@RequiredArgsConstructor -@Getter -public final class HBaseDeleteOperation extends Operation { - - private final List deletes; - - @Override - public Map getFingerprint() { - return Collections.emptyMap(); - } - - @Override - public Map toMap(final int i) { - return Collections.emptyMap(); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/operation/HBaseInsertOperation.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/operation/HBaseInsertOperation.java deleted file mode 100644 index f5a8d67409ce8..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/operation/HBaseInsertOperation.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.converter.operation; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.apache.hadoop.hbase.client.Operation; -import org.apache.hadoop.hbase.client.Put; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * HBase insert operation. - */ -@RequiredArgsConstructor -@Getter -public final class HBaseInsertOperation extends Operation { - - private final List puts; - - @Override - public Map getFingerprint() { - return Collections.emptyMap(); - } - - @Override - public Map toMap(final int i) { - return Collections.emptyMap(); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/operation/HBaseRegionReloadOperation.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/operation/HBaseRegionReloadOperation.java deleted file mode 100644 index d9d5c6cbcd439..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/operation/HBaseRegionReloadOperation.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.converter.operation; - -import org.apache.hadoop.hbase.client.Operation; - -import java.util.Collections; -import java.util.Map; - -/** - * HBase region reload operation. - */ -public final class HBaseRegionReloadOperation extends Operation { - - @Override - public Map getFingerprint() { - return Collections.emptyMap(); - } - - @Override - public Map toMap(final int i) { - return Collections.emptyMap(); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/operation/HBaseSelectOperation.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/operation/HBaseSelectOperation.java deleted file mode 100644 index 5d0448047ed3f..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/operation/HBaseSelectOperation.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.converter.operation; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.apache.hadoop.hbase.client.Get; -import org.apache.hadoop.hbase.client.Operation; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * HBase select operation. - */ -@RequiredArgsConstructor -@Getter -public final class HBaseSelectOperation extends Operation { - - private final List gets; - - @Override - public Map getFingerprint() { - return Collections.emptyMap(); - } - - @Override - public Map toMap(final int i) { - return Collections.emptyMap(); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/operation/HBaseUpdateOperation.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/operation/HBaseUpdateOperation.java deleted file mode 100644 index 99b45fc273149..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/operation/HBaseUpdateOperation.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.converter.operation; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.apache.hadoop.hbase.client.Operation; -import org.apache.hadoop.hbase.client.Put; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * HBase update operation. - */ -@RequiredArgsConstructor -@Getter -public final class HBaseUpdateOperation extends Operation { - - private final List puts; - - @Override - public Map getFingerprint() { - return Collections.emptyMap(); - } - - @Override - public Map toMap(final int i) { - return Collections.emptyMap(); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseDeleteOperationConverter.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseDeleteOperationConverter.java deleted file mode 100644 index 7c1da82a8e50e..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseDeleteOperationConverter.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.converter.type; - -import com.google.common.base.Preconditions; -import lombok.RequiredArgsConstructor; -import org.apache.hadoop.hbase.client.Delete; -import org.apache.hadoop.hbase.util.Bytes; -import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.binder.context.statement.dml.DeleteStatementContext; -import org.apache.shardingsphere.proxy.backend.hbase.bean.HBaseOperation; -import org.apache.shardingsphere.proxy.backend.hbase.converter.HBaseOperationConverter; -import org.apache.shardingsphere.proxy.backend.hbase.converter.HBaseRowKeyExtractor; -import org.apache.shardingsphere.proxy.backend.hbase.converter.operation.HBaseDeleteOperation; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.InExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; - -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -/** - * HBase delete operation converter. - */ -@RequiredArgsConstructor -public final class HBaseDeleteOperationConverter implements HBaseOperationConverter { - - private final SQLStatementContext sqlStatementContext; - - @Override - public HBaseOperation convert() { - DeleteStatementContext deleteStatementContext = (DeleteStatementContext) sqlStatementContext; - Optional whereSegment = deleteStatementContext.getWhereSegments().stream().findFirst(); - Preconditions.checkArgument(whereSegment.isPresent(), "Where segment is absent."); - return whereSegment.get().getExpr() instanceof InExpression - ? createDeleteMultipleRowKeysOperation(deleteStatementContext, whereSegment.get()) - : createDeleteSingleRowKeyOperation(deleteStatementContext, whereSegment.get()); - } - - private HBaseOperation createDeleteMultipleRowKeysOperation(final DeleteStatementContext deleteStatementContext, final WhereSegment whereSegment) { - String tableName = deleteStatementContext.getTablesContext().getTableNames().iterator().next(); - List rowKeys = HBaseRowKeyExtractor.getRowKeys((InExpression) whereSegment.getExpr()); - List deletes = rowKeys.stream().map(each -> new Delete(Bytes.toBytes(each))).collect(Collectors.toList()); - return new HBaseOperation(tableName, new HBaseDeleteOperation(deletes)); - } - - private HBaseOperation createDeleteSingleRowKeyOperation(final DeleteStatementContext deleteStatementContext, final WhereSegment whereSegment) { - String tableName = deleteStatementContext.getTablesContext().getTableNames().iterator().next(); - String rowKey = HBaseRowKeyExtractor.getRowKey((BinaryOperationExpression) whereSegment.getExpr()); - Delete delete = new Delete(Bytes.toBytes(rowKey)); - return new HBaseOperation(tableName, delete); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseInsertOperationConverter.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseInsertOperationConverter.java deleted file mode 100644 index 9e48cb0f450ce..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseInsertOperationConverter.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.converter.type; - -import lombok.RequiredArgsConstructor; -import org.apache.hadoop.hbase.client.Put; -import org.apache.hadoop.hbase.util.Bytes; -import org.apache.shardingsphere.infra.binder.context.segment.insert.values.InsertValueContext; -import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; -import org.apache.shardingsphere.proxy.backend.hbase.bean.HBaseOperation; -import org.apache.shardingsphere.proxy.backend.hbase.context.HBaseContext; -import org.apache.shardingsphere.proxy.backend.hbase.converter.HBaseOperationConverter; -import org.apache.shardingsphere.proxy.backend.hbase.converter.operation.HBaseInsertOperation; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment; -import java.util.List; -import java.util.stream.Collectors; - -/** - * HBase insert operation converter. - */ -@RequiredArgsConstructor -public final class HBaseInsertOperationConverter implements HBaseOperationConverter { - - private final SQLStatementContext sqlStatementContext; - - @Override - public HBaseOperation convert() { - InsertStatementContext insertStatementContext = (InsertStatementContext) sqlStatementContext; - String tableName = insertStatementContext.getTablesContext().getTableNames().iterator().next(); - return new HBaseOperation(tableName, new HBaseInsertOperation(createHBaseRequest(insertStatementContext))); - } - - private List createHBaseRequest(final InsertStatementContext insertStatementContext) { - return insertStatementContext.getInsertValueContexts().stream().map(each -> generateHBaseRequest(insertStatementContext, each)).collect(Collectors.toList()); - } - - private Put generateHBaseRequest(final InsertStatementContext insertStatementContext, final InsertValueContext insertValueContext) { - List columns = insertStatementContext.getInsertColumnNames(); - List values = insertValueContext.getValueExpressions().stream().map(each -> ((LiteralExpressionSegment) each).getLiterals()).collect(Collectors.toList()); - Put result = new Put(Bytes.toBytes(String.valueOf(values.get(0)))); - for (int i = 1; i < columns.size(); i++) { - result.addColumn(Bytes.toBytes(HBaseContext.getInstance().getColumnFamily()), Bytes.toBytes(String.valueOf(columns.get(i))), Bytes.toBytes(String.valueOf(values.get(i)))); - } - return result; - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseRegionReloadOperationConverter.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseRegionReloadOperationConverter.java deleted file mode 100644 index deef41c330588..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseRegionReloadOperationConverter.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.converter.type; - -import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; -import org.apache.shardingsphere.proxy.backend.hbase.bean.HBaseOperation; -import org.apache.shardingsphere.proxy.backend.hbase.converter.HBaseOperationConverter; -import org.apache.shardingsphere.proxy.backend.hbase.converter.operation.HBaseRegionReloadOperation; - -import java.util.Collection; -import java.util.Collections; -import java.util.stream.Collectors; - -/** - * HBase region reload operation converter. - */ -@RequiredArgsConstructor -public final class HBaseRegionReloadOperationConverter implements HBaseOperationConverter { - - private final SQLStatementContext sqlStatementContext; - - @Override - public HBaseOperation convert() { - Collection tables = sqlStatementContext instanceof TableAvailable - ? ((TableAvailable) sqlStatementContext).getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()) - : Collections.emptyList(); - return new HBaseOperation(String.join(",", tables), new HBaseRegionReloadOperation()); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseSelectOperationConverter.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseSelectOperationConverter.java deleted file mode 100644 index cd168aaac6558..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseSelectOperationConverter.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.converter.type; - -import com.google.common.base.Preconditions; -import lombok.RequiredArgsConstructor; -import org.apache.hadoop.hbase.client.Get; -import org.apache.hadoop.hbase.client.Query; -import org.apache.hadoop.hbase.client.Scan; -import org.apache.hadoop.hbase.util.Bytes; -import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; -import org.apache.shardingsphere.proxy.backend.hbase.bean.HBaseOperation; -import org.apache.shardingsphere.proxy.backend.hbase.converter.HBaseOperationConverter; -import org.apache.shardingsphere.proxy.backend.hbase.converter.HBaseRowKeyExtractor; -import org.apache.shardingsphere.proxy.backend.hbase.converter.operation.HBaseSelectOperation; -import org.apache.shardingsphere.proxy.backend.hbase.util.HBaseHeterogeneousUtils; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BetweenExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.InExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.pagination.limit.NumberLiteralLimitValueSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; -import org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLSelectStatement; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -/** - * HBase select operation converter. - */ -@RequiredArgsConstructor -public final class HBaseSelectOperationConverter implements HBaseOperationConverter { - - private final SQLStatementContext sqlStatementContext; - - @Override - public HBaseOperation convert() { - SelectStatementContext selectStatementContext = (SelectStatementContext) sqlStatementContext; - Optional whereSegment = selectStatementContext.getWhereSegments().stream().findFirst(); - Preconditions.checkArgument(whereSegment.isPresent(), "Where segment is absent."); - return whereSegment.get().getExpr() instanceof BinaryOperationExpression || whereSegment.get().getExpr() instanceof InExpression - ? createGetOperation(selectStatementContext, whereSegment.get()) - : createScanOperation(selectStatementContext, whereSegment.get()); - } - - private HBaseOperation createGetOperation(final SelectStatementContext selectStatementContext, final WhereSegment whereSegment) { - ExpressionSegment expr = whereSegment.getExpr(); - List gets = getRowKeys(expr).stream().map(each -> new Get(Bytes.toBytes(each))).collect(Collectors.toList()); - if (!HBaseHeterogeneousUtils.isUseShorthandProjection(selectStatementContext)) { - for (Get each : gets) { - appendColumns(each, selectStatementContext); - } - } - String tableName = selectStatementContext.getTablesContext().getTableNames().iterator().next(); - return expr instanceof InExpression ? new HBaseOperation(tableName, new HBaseSelectOperation(gets)) : new HBaseOperation(tableName, gets.get(0)); - } - - private List getRowKeys(final ExpressionSegment expr) { - return expr instanceof InExpression ? HBaseRowKeyExtractor.getRowKeys((InExpression) expr) : Collections.singletonList(HBaseRowKeyExtractor.getRowKey((BinaryOperationExpression) expr)); - } - - private HBaseOperation createScanOperation(final SelectStatementContext selectStatementContext, final WhereSegment whereSegment) { - Scan scan = new Scan(); - if (whereSegment.getExpr() instanceof BetweenExpression) { - appendBetween(scan, whereSegment.getExpr(), false); - } - if (!HBaseHeterogeneousUtils.isUseShorthandProjection(selectStatementContext)) { - appendColumns(scan, selectStatementContext); - } - appendLimit(scan, selectStatementContext); - return new HBaseOperation(selectStatementContext.getTablesContext().getTableNames().iterator().next(), scan); - } - - private void appendColumns(final Query query, final SelectStatementContext selectStatementContext) { - if (query instanceof Get) { - selectStatementContext.getColumnSegments().forEach(each -> ((Get) query).addColumn(Bytes.toBytes("i"), Bytes.toBytes(String.valueOf(each)))); - } else { - selectStatementContext.getColumnSegments().forEach(each -> ((Scan) query).addColumn(Bytes.toBytes("i"), Bytes.toBytes(String.valueOf(each)))); - } - } - - private void appendBetween(final Scan scan, final ExpressionSegment expressionSegment, final boolean reversed) { - BetweenExpression betweenExpr = (BetweenExpression) expressionSegment; - String startRowKey = ((LiteralExpressionSegment) betweenExpr.getBetweenExpr()).getLiterals().toString(); - String stopRowKey = ((LiteralExpressionSegment) betweenExpr.getAndExpr()).getLiterals().toString(); - if (null != startRowKey && null != stopRowKey) { - if (reversed) { - scan.withStopRow(calBytes(startRowKey, 0), true); - // refer: - scan.withStartRow(calBytes(stopRowKey + "~", 0), true); - } else { - scan.withStartRow(calBytes(startRowKey, 0), true); - scan.withStopRow(calBytes(stopRowKey + "~", 0), true); - } - } - } - - private byte[] calBytes(final String row, final int step) { - byte[] rowByte = Bytes.toBytes(row); - byte[] result = Arrays.copyOf(rowByte, rowByte.length); - result[result.length - 1] = (byte) (result[result.length - 1] + step); - return result; - } - - private void appendLimit(final Scan scan, final SelectStatementContext selectStatementContext) { - // TODO consider about other dialect - MySQLSelectStatement selectStatement = (MySQLSelectStatement) selectStatementContext.getSqlStatement(); - if (selectStatement.getLimit().isPresent()) { - selectStatement.getLimit().get().getRowCount().ifPresent(optional -> scan.setLimit((int) ((NumberLiteralLimitValueSegment) optional).getValue())); - } - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseUpdateOperationConverter.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseUpdateOperationConverter.java deleted file mode 100644 index 1a0da8e77dfa5..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseUpdateOperationConverter.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.converter.type; - -import com.google.common.base.Preconditions; -import lombok.RequiredArgsConstructor; -import org.apache.hadoop.hbase.client.Put; -import org.apache.hadoop.hbase.util.Bytes; -import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.binder.context.statement.dml.UpdateStatementContext; -import org.apache.shardingsphere.proxy.backend.hbase.bean.HBaseOperation; -import org.apache.shardingsphere.proxy.backend.hbase.converter.HBaseOperationConverter; -import org.apache.shardingsphere.proxy.backend.hbase.converter.HBaseRowKeyExtractor; -import org.apache.shardingsphere.proxy.backend.hbase.converter.operation.HBaseUpdateOperation; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.ColumnAssignmentSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.InExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; - -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -/** - * HBase update operation converter. - */ -@RequiredArgsConstructor -public final class HBaseUpdateOperationConverter implements HBaseOperationConverter { - - private final SQLStatementContext sqlStatementContext; - - @Override - public HBaseOperation convert() { - UpdateStatementContext updateStatementContext = (UpdateStatementContext) sqlStatementContext; - Optional whereSegment = updateStatementContext.getWhereSegments().stream().findFirst(); - Preconditions.checkArgument(whereSegment.isPresent(), "Where segment is absent."); - return whereSegment.get().getExpr() instanceof InExpression - ? createUpdateMultipleRowKeysOperation(updateStatementContext, whereSegment.get()) - : createUpdateSingleRowKeyOperation(updateStatementContext, whereSegment.get()); - } - - private HBaseOperation createUpdateMultipleRowKeysOperation(final UpdateStatementContext updateStatementContext, final WhereSegment whereSegment) { - String tableName = updateStatementContext.getTablesContext().getTableNames().iterator().next(); - List puts = HBaseRowKeyExtractor.getRowKeys((InExpression) whereSegment.getExpr()).stream().map(each -> new Put(Bytes.toBytes(each))).collect(Collectors.toList()); - for (Put each : puts) { - addPutColumn(updateStatementContext, each); - } - return new HBaseOperation(tableName, new HBaseUpdateOperation(puts)); - } - - private HBaseOperation createUpdateSingleRowKeyOperation(final UpdateStatementContext updateStatementContext, final WhereSegment whereSegment) { - String tableName = updateStatementContext.getTablesContext().getTableNames().iterator().next(); - return new HBaseOperation(tableName, createOperationRequest(updateStatementContext, whereSegment)); - } - - private Put createOperationRequest(final UpdateStatementContext updateStatementContext, final WhereSegment whereSegment) { - Put result = new Put(Bytes.toBytes(HBaseRowKeyExtractor.getRowKey((BinaryOperationExpression) whereSegment.getExpr()))); - addPutColumn(updateStatementContext, result); - return result; - } - - private void addPutColumn(final UpdateStatementContext updateStatementContext, final Put put) { - for (ColumnAssignmentSegment each : updateStatementContext.getSqlStatement().getSetAssignment().getAssignments()) { - String columnName = each.getColumns().iterator().next().getIdentifier().getValue(); - String value = String.valueOf(((LiteralExpressionSegment) each.getValue()).getLiterals()); - put.addColumn(Bytes.toBytes("i"), Bytes.toBytes(columnName), Bytes.toBytes(value)); - } - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/executor/HBaseBackgroundExecutorManager.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/executor/HBaseBackgroundExecutorManager.java deleted file mode 100644 index 045bfbe5c1670..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/executor/HBaseBackgroundExecutorManager.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.executor; - -import org.apache.shardingsphere.infra.executor.kernel.thread.ExecutorThreadFactoryBuilder; - -import java.io.Closeable; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -/** - * HBase background executor manager. - */ -public final class HBaseBackgroundExecutorManager implements Closeable { - - private final ScheduledExecutorService executorService; - - public HBaseBackgroundExecutorManager() { - executorService = Executors.newScheduledThreadPool(1, ExecutorThreadFactoryBuilder.build("background")); - } - - /** - * Submit task. - * - * @param runnable task - * @param interval running interval - */ - public void submit(final Runnable runnable, final int interval) { - executorService.scheduleWithFixedDelay(runnable, interval, interval, TimeUnit.SECONDS); - } - - @Override - public void close() { - executorService.shutdown(); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/executor/HBaseExecutor.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/executor/HBaseExecutor.java deleted file mode 100644 index 33a56f4448bef..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/executor/HBaseExecutor.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.executor; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.client.Admin; -import org.apache.hadoop.hbase.client.Connection; -import org.apache.hadoop.hbase.client.Table; -import org.apache.shardingsphere.proxy.backend.hbase.context.HBaseContext; -import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseAdminCallback; -import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseQueryCallback; -import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseUpdateCallback; - -import java.io.IOException; -import java.sql.SQLException; - -/** - * HBase executor. - * - *

Do not cache table here.

- */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class HBaseExecutor { - - /** - * Execute update. - * - * @param tableName table name - * @param operation operation - * @throws SQLException SQL exception - */ - public static void executeUpdate(final String tableName, final HBaseUpdateCallback operation) throws SQLException { - try (Table table = HBaseContext.getInstance().getConnection(tableName).getTable(TableName.valueOf(tableName))) { - executeUpdate(table, operation); - } catch (final IOException ex) { - throw new SQLException(ex); - } - } - - private static void executeUpdate(final Table table, final HBaseUpdateCallback operation) throws SQLException { - try { - operation.executeInHBase(table); - } catch (final IOException ex) { - throw new SQLException(ex); - } - } - - /** - * Execute query. - * - * @param tableName table name - * @param operation operation - * @param type of result - * @return query result - * @throws SQLException SQL exception - */ - public static T executeQuery(final String tableName, final HBaseQueryCallback operation) throws SQLException { - TableName backendTableName = TableName.valueOf(tableName); - try (Table table = HBaseContext.getInstance().getConnection(tableName).getTable(backendTableName)) { - return executeQuery(table, operation); - } catch (final IOException ex) { - throw new SQLException(ex); - } - } - - private static T executeQuery(final Table table, final HBaseQueryCallback operation) throws SQLException { - try { - return operation.executeInHBase(table); - } catch (final IOException ex) { - throw new SQLException(ex); - } - } - - /** - * Execute admin. - * - * @param connection HBase connection - * @param operation operation - * @param type of result - * @return admin result - * @throws SQLException SQL exception - */ - public static T executeAdmin(final Connection connection, final HBaseAdminCallback operation) throws SQLException { - try (Admin admin = connection.getAdmin()) { - return operation.executeInHBase(admin); - } catch (final IOException ex) { - throw new SQLException(ex); - } - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/executor/HBaseTaskExecutorManager.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/executor/HBaseTaskExecutorManager.java deleted file mode 100644 index bc2fcb239c651..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/executor/HBaseTaskExecutorManager.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.executor; - -import java.io.Closeable; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -/** - * HBase task executor manager. - */ -public final class HBaseTaskExecutorManager implements Closeable { - - private final ThreadPoolExecutor executorService; - - /** - * HBase task executor manager. - * @param poolSize pool size - */ - public HBaseTaskExecutorManager(final int poolSize) { - executorService = new ThreadPoolExecutor(poolSize, poolSize, 10L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(20000), new ThreadPoolExecutor.CallerRunsPolicy()); - } - - /** - * Submit task. - * - * @param runnable task - */ - public void submit(final Runnable runnable) { - executorService.submit(runnable); - } - - @Override - public void close() { - executorService.shutdown(); - } - -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/handler/HBaseBackendQueryHandler.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/handler/HBaseBackendQueryHandler.java deleted file mode 100644 index f7c9fa83b6e10..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/handler/HBaseBackendQueryHandler.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.handler; - -import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.binder.SQLBindEngine; -import org.apache.shardingsphere.infra.hint.HintValueContext; -import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseBackendHandler; -import org.apache.shardingsphere.proxy.backend.hbase.result.query.HBaseQueryResultSet; -import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader; -import org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeader; -import org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; - -import java.sql.SQLException; -import java.sql.Types; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -/** - * Backend handler for HBase. - */ -@RequiredArgsConstructor -public final class HBaseBackendQueryHandler implements HBaseBackendHandler { - - private final SQLStatement sqlStatement; - - private final HBaseQueryResultSet resultSet; - - @Override - public ResponseHeader execute() throws SQLException { - SQLStatementContext sqlStatementContext = new SQLBindEngine(null, "", new HintValueContext()).bind(sqlStatement, Collections.emptyList()); - resultSet.init(sqlStatementContext); - List queryHeaders = resultSet.getColumnNames().stream().map(each -> new QueryHeader("", "", each, each, Types.CHAR, "CHAR", 255, 0, false, false, false, false)) - .collect(Collectors.toList()); - return new QueryResponseHeader(queryHeaders); - } - - @Override - public boolean next() { - return resultSet.next(); - } - - @Override - public Collection getRowDataObjects() { - return resultSet.getRowData(); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/handler/HBaseBackendUpdateHandler.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/handler/HBaseBackendUpdateHandler.java deleted file mode 100644 index 4281e710a5081..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/handler/HBaseBackendUpdateHandler.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.handler; - -import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.binder.SQLBindEngine; -import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.executor.sql.execute.result.update.UpdateResult; -import org.apache.shardingsphere.infra.hint.HintValueContext; -import org.apache.shardingsphere.proxy.backend.handler.data.DatabaseBackendHandler; -import org.apache.shardingsphere.proxy.backend.hbase.converter.HBaseOperationConverter; -import org.apache.shardingsphere.proxy.backend.hbase.converter.HBaseOperationConverterFactory; -import org.apache.shardingsphere.proxy.backend.hbase.result.update.HBaseUpdater; -import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; - -import java.sql.SQLException; -import java.util.Collection; -import java.util.Collections; - -/** - * HBase backend updater handler. - */ -@RequiredArgsConstructor -public final class HBaseBackendUpdateHandler implements DatabaseBackendHandler { - - private final SQLStatement sqlStatement; - - private final HBaseUpdater updater; - - @Override - public UpdateResponseHeader execute() throws SQLException { - SQLStatementContext sqlStatementContext = new SQLBindEngine(null, "", new HintValueContext()).bind(sqlStatement, Collections.emptyList()); - HBaseOperationConverter converter = HBaseOperationConverterFactory.newInstance(sqlStatementContext); - Collection updateResults = updater.executeUpdate(converter.convert()); - return new UpdateResponseHeader(sqlStatement, updateResults); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/handler/HBaseErrorHintCommentQueryHandler.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/handler/HBaseErrorHintCommentQueryHandler.java deleted file mode 100644 index a15b18b2ace59..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/handler/HBaseErrorHintCommentQueryHandler.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.handler; - -import org.apache.commons.lang3.StringUtils; -import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseBackendHandler; -import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader; -import org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeader; -import org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader; - -import java.sql.Types; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -/** - * Backend handler for error hint for HBase. - */ -public final class HBaseErrorHintCommentQueryHandler implements HBaseBackendHandler { - - private static final Collection COLUMN_NAMES = Arrays.asList("ID", "Hint", "Status"); - - private final List rowDataList; - - private int currentIndex; - - public HBaseErrorHintCommentQueryHandler(final String hintComment) { - rowDataList = Arrays.asList(new HBaseErrorHintCommentQueryRowData(1, "HBase", true), new HBaseErrorHintCommentQueryRowData(2, StringUtils.strip(hintComment, "* "), false)); - currentIndex = 0; - } - - @Override - public ResponseHeader execute() { - List queryHeaders = COLUMN_NAMES.stream().map(each -> new QueryHeader("", "", each, each, Types.CHAR, "CHAR", 255, 0, false, false, false, false)).collect(Collectors.toList()); - return new QueryResponseHeader(queryHeaders); - } - - @Override - public boolean next() { - currentIndex++; - return currentIndex <= rowDataList.size(); - } - - @Override - public Collection getRowDataObjects() { - return rowDataList.get(currentIndex - 1).toList(); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/handler/HBaseErrorHintCommentQueryRowData.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/handler/HBaseErrorHintCommentQueryRowData.java deleted file mode 100644 index 1a13f4afd1c17..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/handler/HBaseErrorHintCommentQueryRowData.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.handler; - -import lombok.RequiredArgsConstructor; - -import java.util.Arrays; -import java.util.Collection; - -/** - * Error hint comment query row data for HBase. - */ -@RequiredArgsConstructor -public final class HBaseErrorHintCommentQueryRowData { - - private final int id; - - private final String hint; - - private final boolean supported; - - /** - * List row data. - * - * @return listed row data - */ - public Collection toList() { - return Arrays.asList(String.valueOf(id), hint, supported ? "supported" : "unsupported"); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/props/HBaseProperties.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/props/HBaseProperties.java deleted file mode 100644 index 64b70286086a9..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/props/HBaseProperties.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.props; - -import org.apache.shardingsphere.infra.props.TypedProperties; -import java.util.Properties; - -/** - * Typed properties of HBase. - */ -public final class HBaseProperties extends TypedProperties { - - public HBaseProperties(final Properties props) { - super(HBasePropertyKey.class, props); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/props/HBasePropertyKey.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/props/HBasePropertyKey.java deleted file mode 100644 index 6d73c7f33ab99..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/props/HBasePropertyKey.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.props; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.props.TypedPropertyKey; - -/** - * Typed property key of HBase. - */ -@RequiredArgsConstructor -@Getter -public enum HBasePropertyKey implements TypedPropertyKey { - - /** - * Background threads are periodically executed to update metadata. - */ - META_REFRESHER_INTERVAL_SECONDS("meta-refresher-interval-seconds", String.valueOf(300), int.class), - - /** - * Maximum number of scanned rows. - */ - MAX_SCAN_LIMIT_SIZE("max-scan-limit-size", String.valueOf(5000), long.class), - - /** - * Warm up thread num. - */ - WARM_UP_THREAD_NUM("warm-up-thread-num", String.valueOf(1), int.class), - - /** - * Is sync warm up. - */ - IS_SYNC_WARM_UP("is-sync-warm-up", String.valueOf(true), boolean.class), - - /** - * HBase execute out time. - */ - EXECUTE_TIME_OUT("execute-time-out", String.valueOf(2000), Long.class); - - private final String key; - - private final String defaultValue; - - private final Class type; -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/HBaseAdminCallback.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/HBaseAdminCallback.java deleted file mode 100644 index 44a140783e14f..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/HBaseAdminCallback.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result; - -import org.apache.hadoop.hbase.client.Admin; -import java.io.IOException; - -/** - * Call back for HBase operation. - * - * @param type of result - */ -public interface HBaseAdminCallback { - - /** - * Execute in HBase. - * - * @param admin execute in HBase table - * @return execute result - * @throws IOException IO exception - */ - T executeInHBase(Admin admin) throws IOException; -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/HBaseBackendHandler.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/HBaseBackendHandler.java deleted file mode 100644 index 8ab81f9af4458..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/HBaseBackendHandler.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result; - -import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandler; -import java.util.Collection; -import java.util.Collections; - -/** - * HBase backend handler. - */ -public interface HBaseBackendHandler extends ProxyBackendHandler { - - /** - * Get row data objects. - * - * @return row data - */ - default Collection getRowDataObjects() { - return Collections.emptyList(); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/HBaseQueryCallback.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/HBaseQueryCallback.java deleted file mode 100644 index a64cbfb6305fe..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/HBaseQueryCallback.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result; - -import org.apache.hadoop.hbase.client.Table; -import java.io.IOException; - -/** - * HBase query callback. - * - * @param type of result - */ -public interface HBaseQueryCallback { - - /** - * Execute in HBase. - * - * @param table table - * @return execute result - * @throws IOException IO exception - */ - T executeInHBase(Table table) throws IOException; -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/HBaseUpdateCallback.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/HBaseUpdateCallback.java deleted file mode 100644 index 5bc4e2db1e82a..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/HBaseUpdateCallback.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result; - -import org.apache.hadoop.hbase.client.Table; -import java.io.IOException; - -/** - * HBase update callback. - */ -public interface HBaseUpdateCallback { - - /** - * Execute in HBase. - * - * @param table table - * @throws IOException IO exception - */ - void executeInHBase(Table table) throws IOException; -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseDescribeResultSet.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseDescribeResultSet.java deleted file mode 100644 index 21bbe72be8f17..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseDescribeResultSet.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result.query; - -import com.google.common.base.Preconditions; -import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.TableName; -import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.binder.context.statement.dal.ShowCreateTableStatementContext; -import org.apache.shardingsphere.proxy.backend.hbase.context.HBaseContext; -import org.apache.shardingsphere.proxy.backend.hbase.executor.HBaseExecutor; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLShowCreateTableStatement; - -import java.sql.SQLException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -/** - * Result set for HBase describe. - */ -public final class HBaseDescribeResultSet implements HBaseQueryResultSet { - - private Iterator iterator; - - @Override - public void init(final SQLStatementContext sqlStatementContext) throws SQLException { - ShowCreateTableStatementContext statementContext = (ShowCreateTableStatementContext) sqlStatementContext; - String tableName = statementContext.getTablesContext().getTableNames().iterator().next(); - boolean isExists = HBaseExecutor.executeAdmin(HBaseContext.getInstance().getConnection(tableName), admin -> admin.tableExists(TableName.valueOf(tableName))); - Preconditions.checkArgument(isExists, String.format("Table %s is not exists", tableName)); - HTableDescriptor hTableDescriptor = HBaseExecutor.executeAdmin(HBaseContext.getInstance().getConnection(tableName), admin -> admin.getTableDescriptor(TableName.valueOf(tableName))); - List tables = Collections.singletonList(hTableDescriptor); - iterator = tables.iterator(); - } - - /** - * Get result set column names. - * - * @return result set column names - */ - @Override - public Collection getColumnNames() { - return Arrays.asList("Name", "TableAttributes", "FlushPolicyClassName", "MaxFileSize", "MemStoreFlushSize", "Priority", "RegionReplication", "RegionSplitPolicyClassName", "CustomizedValues"); - } - - /** - * Go to next data. - * - * @return true if next data exist - */ - @Override - public boolean next() { - return iterator.hasNext(); - } - - /** - * Get row data. - * - * @return row data - */ - @Override - public Collection getRowData() { - HTableDescriptor descriptor = iterator.next(); - return Arrays.asList(descriptor.getNameAsString(), descriptor.toStringTableAttributes(), - descriptor.getFlushPolicyClassName(), descriptor.getMaxFileSize(), - descriptor.getMemStoreFlushSize(), descriptor.getPriority(), descriptor.getRegionReplication(), descriptor.getRegionSplitPolicyClassName(), - descriptor.toStringCustomizedValues()); - } - - /** - * Get type. - * - * @return type name - */ - @Override - public Class getType() { - return MySQLShowCreateTableStatement.class; - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseGetResultSet.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseGetResultSet.java deleted file mode 100644 index 3dd3fee3995e3..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseGetResultSet.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result.query; - -import com.cedarsoftware.util.CaseInsensitiveMap; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; -import org.apache.hadoop.hbase.Cell; -import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.client.Get; -import org.apache.hadoop.hbase.client.Result; -import org.apache.hadoop.hbase.client.ResultScanner; -import org.apache.hadoop.hbase.client.Scan; -import org.apache.hadoop.hbase.util.Bytes; -import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; -import org.apache.shardingsphere.proxy.backend.hbase.bean.HBaseOperation; -import org.apache.shardingsphere.proxy.backend.hbase.context.HBaseContext; -import org.apache.shardingsphere.proxy.backend.hbase.converter.HBaseOperationConverterFactory; -import org.apache.shardingsphere.proxy.backend.hbase.converter.operation.HBaseSelectOperation; -import org.apache.shardingsphere.proxy.backend.hbase.executor.HBaseExecutor; -import org.apache.shardingsphere.proxy.backend.hbase.props.HBasePropertyKey; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BetweenExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.pagination.PaginationValueSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.pagination.limit.LimitSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.pagination.limit.NumberLiteralLimitValueSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; -import org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLSelectStatement; - -import java.nio.charset.StandardCharsets; -import java.sql.SQLException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; - -/** - * HBase get result. - */ -@Slf4j -public final class HBaseGetResultSet implements HBaseQueryResultSet { - - private static final String ROW_KEY_COLUMN_NAME = "rowKey"; - - private static final String CONTENT_COLUMN_NAME = "content"; - - private static final String TIMESTAMP_COLUMN_NAME = "timestamp"; - - private SelectStatementContext statementContext; - - private long resultNum; - - private long maxLimitResultSize; - - @Getter - private Collection columnNames = Collections.singleton(ROW_KEY_COLUMN_NAME); - - private Result compensateResult; - - private Iterator rows; - - /** - * Init data. - * - * @param sqlStatementContext SQL statement context - */ - @Override - public void init(final SQLStatementContext sqlStatementContext) throws SQLException { - statementContext = (SelectStatementContext) sqlStatementContext; - initResultNum(sqlStatementContext); - HBaseOperation operation = HBaseOperationConverterFactory.newInstance(sqlStatementContext).convert(); - long startMills = System.currentTimeMillis(); - if (operation.getOperation() instanceof Get) { - executeGetRequest(operation); - } else if (operation.getOperation() instanceof HBaseSelectOperation) { - executeGetsRequest(operation); - } else { - executeScanRequest(operation); - } - logExecuteTime(startMills); - } - - private void initResultNum(final SQLStatementContext sqlStatementContext) { - resultNum = 0L; - maxLimitResultSize = HBaseContext.getInstance().getProps().getValue(HBasePropertyKey.MAX_SCAN_LIMIT_SIZE); - Optional paginationSegment = ((MySQLSelectStatement) sqlStatementContext.getSqlStatement()).getLimit().flatMap(LimitSegment::getRowCount); - paginationSegment.ifPresent(optional -> maxLimitResultSize = Math.min(maxLimitResultSize, ((NumberLiteralLimitValueSegment) optional).getValue())); - } - - private void executeGetRequest(final HBaseOperation operation) throws SQLException { - Result result = HBaseExecutor.executeQuery(operation.getTableName(), table -> table.get((Get) operation.getOperation())); - Collection rows = 0 == result.rawCells().length ? Collections.emptyList() : Collections.singleton(result); - this.rows = rows.iterator(); - setColumnNames(this.rows); - } - - private void executeGetsRequest(final HBaseOperation operation) throws SQLException { - List results = Arrays.asList(HBaseExecutor.executeQuery(operation.getTableName(), table -> table.get(((HBaseSelectOperation) operation.getOperation()).getGets()))); - results = results.stream().filter(result -> result.rawCells().length > 0).collect(Collectors.toList()); - if (statementContext.getOrderByContext().isGenerated()) { - results.sort(this::compareResult); - } - rows = results.iterator(); - setColumnNames(rows); - } - - private int compareResult(final Result result1, final Result result2) { - return Bytes.toString(result1.getRow()).compareTo(Bytes.toString(result2.getRow())); - } - - private void executeScanRequest(final HBaseOperation hbaseOperation) throws SQLException { - Scan scan = (Scan) hbaseOperation.getOperation(); - scan.setLimit((int) maxLimitResultSize); - ResultScanner resultScanner = HBaseExecutor.executeQuery(hbaseOperation.getTableName(), table -> table.getScanner(scan)); - rows = resultScanner.iterator(); - setColumnNames(rows); - } - - private void setColumnNames(final Iterator rows) { - if (rows.hasNext()) { - compensateResult = rows.next(); - } - columnNames = null == compensateResult ? Arrays.asList(ROW_KEY_COLUMN_NAME, CONTENT_COLUMN_NAME) : parseResultColumnNames(compensateResult); - } - - private Collection parseResultColumnNames(final Result result) { - Collection columnNames = new LinkedList<>(); - columnNames.add(ROW_KEY_COLUMN_NAME); - for (Cell each : result.listCells()) { - String column = new String(CellUtil.cloneQualifier(each), StandardCharsets.UTF_8); - columnNames.add(column); - } - columnNames.add(TIMESTAMP_COLUMN_NAME); - return columnNames; - } - - private Map parseResult(final Result result) { - Map row = new CaseInsensitiveMap<>(); - row.put(ROW_KEY_COLUMN_NAME, Bytes.toString(result.getRow())); - Long timestamp = null; - for (Cell each : result.listCells()) { - String column = new String(CellUtil.cloneQualifier(each), StandardCharsets.UTF_8); - String value = new String(CellUtil.cloneValue(each), StandardCharsets.UTF_8); - if (null == timestamp) { - timestamp = each.getTimestamp(); - } - row.put(column, value); - } - row.put(TIMESTAMP_COLUMN_NAME, String.valueOf(timestamp)); - return row; - } - - private void logExecuteTime(final long startMills) { - long endMills = System.currentTimeMillis(); - String tableName = getTableName(); - String whereClause = getWhereClause(); - if (endMills - startMills > HBaseContext.getInstance().getProps().getValue(HBasePropertyKey.EXECUTE_TIME_OUT)) { - log.info(String.format("query hbase table: %s, where case: %s , query %dms time out", tableName, whereClause, endMills - startMills)); - } else { - log.info(String.format("query hbase table: %s, where case: %s , execute time: %dms", tableName, whereClause, endMills - startMills)); - } - } - - private String getTableName() { - if (statementContext.getSqlStatement().getFrom().isPresent()) { - return statementContext.getSqlStatement().getFrom().get() instanceof SimpleTableSegment - ? ((SimpleTableSegment) statementContext.getSqlStatement().getFrom().get()).getTableName().getIdentifier().getValue() - : statementContext.getSqlStatement().getFrom().toString(); - } - return "DUAL"; - } - - private String getWhereClause() { - if (!statementContext.getSqlStatement().getWhere().isPresent()) { - return ""; - } - StringBuilder result = new StringBuilder(); - ExpressionSegment expressionSegment = statementContext.getSqlStatement().getWhere().get().getExpr(); - if (expressionSegment instanceof BetweenExpression) { - result.append(((BetweenExpression) expressionSegment).getBetweenExpr()); - } else if (expressionSegment instanceof BinaryOperationExpression) { - result.append(expressionSegment.getText()); - } - return result.toString(); - } - - @Override - public boolean next() { - return resultNum < maxLimitResultSize && (rows.hasNext() || null != compensateResult); - } - - @Override - public Collection getRowData() { - Map row; - if (null == compensateResult) { - row = parseResult(rows.next()); - } else { - row = parseResult(compensateResult); - compensateResult = null; - } - resultNum++; - return columnNames.stream().map(each -> row.getOrDefault(each, "")).collect(Collectors.toList()); - } - - @Override - public Class getType() { - return MySQLSelectStatement.class; - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseListResultSet.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseListResultSet.java deleted file mode 100644 index 1e3e51c401e63..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseListResultSet.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result.query; - -import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.client.Admin; -import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.binder.context.statement.dal.ShowTablesStatementContext; -import org.apache.shardingsphere.proxy.backend.hbase.bean.HBaseCluster; -import org.apache.shardingsphere.proxy.backend.hbase.context.HBaseContext; -import org.apache.shardingsphere.proxy.backend.hbase.executor.HBaseExecutor; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLShowTablesStatement; - -import java.sql.SQLException; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; - -/** - * Result set for HBase. - */ -public final class HBaseListResultSet implements HBaseQueryResultSet { - - private Iterator> iterator; - - @Override - public void init(final SQLStatementContext sqlStatementContext) throws SQLException { - ShowTablesStatementContext context = (ShowTablesStatementContext) sqlStatementContext; - Map result; - if (context.getSqlStatement().getFromDatabase().isPresent()) { - String clusterName = context.getSqlStatement().getFromDatabase().get().getDatabase().getIdentifier().getValue(); - result = listTablesInHBaseByFromSchema(clusterName); - } else { - result = listTablesInHBase(); - } - iterator = result.entrySet().iterator(); - } - - private Map listTablesInHBaseByFromSchema(final String clusterName) throws SQLException { - HTableDescriptor[] tables = HBaseExecutor.executeAdmin(HBaseContext.getInstance().getConnectionByClusterName(clusterName), Admin::listTables); - Map result = new HashMap<>(tables.length); - for (HTableDescriptor tableDescriptor : tables) { - result.put(tableDescriptor.getNameAsString(), clusterName); - } - return result; - } - - private Map listTablesInHBase() { - Map result = new HashMap<>(HBaseContext.getInstance().getTableConnectionMap().size(), 1F); - for (Entry entry : HBaseContext.getInstance().getTableConnectionMap().entrySet()) { - result.put(entry.getKey(), entry.getValue().getClusterName()); - } - return result; - } - - /** - * Get result set column names. - * - * @return result set column names - */ - @Override - public Collection getColumnNames() { - return Arrays.asList("hbase cluster name", "table name"); - } - - /** - * Go to next data. - * - * @return true if next data exist - */ - @Override - public boolean next() { - return iterator.hasNext(); - } - - /** - * Get row data. - * - * @return row data - */ - @Override - public Collection getRowData() { - Entry entry = iterator.next(); - return Arrays.asList(entry.getValue(), entry.getKey()); - } - - /** - * Get type. - * - * @return type name - */ - @Override - public Class getType() { - return MySQLShowTablesStatement.class; - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseQueryFactory.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseQueryFactory.java deleted file mode 100644 index fad195fe1dd04..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseQueryFactory.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result.query; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandler; -import org.apache.shardingsphere.proxy.backend.hbase.handler.HBaseBackendQueryHandler; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; -import java.util.Properties; - -/** - * Heterogeneous database backend handler factory. - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class HBaseQueryFactory { - - /** - * Create new instance of heterogeneous database backend handler. - * - * @param sqlStatement sql statement - * @return instance of database backend handler - */ - public static ProxyBackendHandler newInstance(final SQLStatement sqlStatement) { - HBaseQueryResultSet resultSet = TypedSPILoader.getService(HBaseQueryResultSet.class, sqlStatement.getClass(), new Properties()); - return new HBaseBackendQueryHandler(sqlStatement, resultSet); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseQueryResultSet.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseQueryResultSet.java deleted file mode 100644 index af922dc0f5b6b..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseQueryResultSet.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result.query; - -import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; - -import java.sql.SQLException; -import java.util.Collection; - -/** - * Query result set for HBase. - */ -public interface HBaseQueryResultSet extends TypedSPI { - - /** - * Initialize data. - * - * @param sqlStatementContext SQL statement context - * @throws SQLException SQL exception - */ - void init(SQLStatementContext sqlStatementContext) throws SQLException; - - /** - * Get result set column names. - * - * @return result set column names - */ - Collection getColumnNames(); - - /** - * Go to next data. - * - * @return true if next data exist - */ - boolean next(); - - /** - * Get row data. - * - * @return row data - */ - Collection getRowData(); - - @Override - Class getType(); -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseDeleteUpdater.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseDeleteUpdater.java deleted file mode 100644 index 0e5a1c16a1efa..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseDeleteUpdater.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result.update; - -import org.apache.hadoop.hbase.client.Delete; -import org.apache.shardingsphere.infra.executor.sql.execute.result.update.UpdateResult; -import org.apache.shardingsphere.proxy.backend.hbase.converter.operation.HBaseDeleteOperation; -import org.apache.shardingsphere.proxy.backend.hbase.bean.HBaseOperation; -import org.apache.shardingsphere.proxy.backend.hbase.executor.HBaseExecutor; -import org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLDeleteStatement; - -import java.sql.SQLException; -import java.util.Collection; -import java.util.Collections; - -/** - * HBase delete updater. - */ -public final class HBaseDeleteUpdater implements HBaseUpdater { - - @Override - public Collection executeUpdate(final HBaseOperation operation) throws SQLException { - if (operation.getOperation() instanceof HBaseDeleteOperation) { - int deleteAffectedSize = ((HBaseDeleteOperation) operation.getOperation()).getDeletes().size(); - HBaseExecutor.executeUpdate(operation.getTableName(), table -> table.delete(((HBaseDeleteOperation) operation.getOperation()).getDeletes())); - return Collections.singleton(new UpdateResult(deleteAffectedSize, 0L)); - } - HBaseExecutor.executeUpdate(operation.getTableName(), table -> table.delete((Delete) operation.getOperation())); - return Collections.singleton(new UpdateResult(1, 0L)); - } - - @Override - public Class getType() { - return MySQLDeleteStatement.class; - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseInsertUpdater.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseInsertUpdater.java deleted file mode 100644 index ff30f75354985..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseInsertUpdater.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result.update; - -import org.apache.hadoop.hbase.client.Put; -import org.apache.shardingsphere.infra.executor.sql.execute.result.update.UpdateResult; -import org.apache.shardingsphere.proxy.backend.hbase.bean.HBaseOperation; -import org.apache.shardingsphere.proxy.backend.hbase.converter.operation.HBaseInsertOperation; -import org.apache.shardingsphere.proxy.backend.hbase.executor.HBaseExecutor; -import org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLInsertStatement; - -import java.sql.SQLException; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -/** - * HBase insert updater. - */ -public final class HBaseInsertUpdater implements HBaseUpdater { - - @Override - public Collection executeUpdate(final HBaseOperation operation) throws SQLException { - List puts = ((HBaseInsertOperation) operation.getOperation()).getPuts(); - HBaseExecutor.executeUpdate(operation.getTableName(), table -> table.put(puts)); - return Collections.singleton(new UpdateResult(puts.size(), 0L)); - } - - @Override - public Class getType() { - return MySQLInsertStatement.class; - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseRegionReloadUpdater.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseRegionReloadUpdater.java deleted file mode 100644 index 2d2251cd9d1bf..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseRegionReloadUpdater.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result.update; - -import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; -import org.apache.shardingsphere.infra.exception.kernel.metadata.TableNotFoundException; -import org.apache.shardingsphere.infra.executor.sql.execute.result.update.UpdateResult; -import org.apache.shardingsphere.proxy.backend.hbase.bean.HBaseOperation; -import org.apache.shardingsphere.proxy.backend.hbase.context.HBaseContext; -import org.apache.shardingsphere.proxy.backend.hbase.context.HBaseRegionWarmUpContext; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLFlushStatement; - -import java.sql.SQLException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * HBase database region reload updater. - */ -public final class HBaseRegionReloadUpdater implements HBaseUpdater { - - @Override - public Collection executeUpdate(final HBaseOperation operation) throws SQLException { - List tables = Arrays.asList(operation.getTableName().split(",")); - AtomicInteger updateCount = new AtomicInteger(); - tables.stream().filter(this::isNotNullTableName).forEach(this::checkTableExists); - for (String each : tables) { - if (isNotNullTableName(each)) { - updateCount.getAndIncrement(); - HBaseRegionWarmUpContext.getInstance().loadRegionInfo(each, HBaseContext.getInstance().getConnection(each)); - } - } - return Collections.singleton(new UpdateResult(updateCount.get(), 0L)); - } - - private void checkTableExists(final String tableName) { - ShardingSpherePreconditions.checkState(HBaseContext.getInstance().isTableExists(tableName), () -> new TableNotFoundException(tableName)); - } - - private boolean isNotNullTableName(final String tableName) { - return !"".equals(tableName) && !"null".equalsIgnoreCase(tableName); - } - - @Override - public Class getType() { - return MySQLFlushStatement.class; - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseUpdateFactory.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseUpdateFactory.java deleted file mode 100644 index 039c2a728144e..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseUpdateFactory.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result.update; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandler; -import org.apache.shardingsphere.proxy.backend.hbase.handler.HBaseBackendUpdateHandler; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; -import java.util.Properties; - -/** - * Heterogeneous backend handler factory. - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class HBaseUpdateFactory { - - /** - * Create new instance of heterogeneous database backend handler. - * - * @param sqlStatement sql statement - * @return instance of database backend handler - */ - public static ProxyBackendHandler newInstance(final SQLStatement sqlStatement) { - HBaseUpdater updater = TypedSPILoader.getService(HBaseUpdater.class, sqlStatement.getClass(), new Properties()); - return new HBaseBackendUpdateHandler(sqlStatement, updater); - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseUpdateUpdater.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseUpdateUpdater.java deleted file mode 100644 index fbd04f1965b23..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseUpdateUpdater.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result.update; - -import org.apache.hadoop.hbase.client.Put; -import org.apache.shardingsphere.infra.executor.sql.execute.result.update.UpdateResult; -import org.apache.shardingsphere.proxy.backend.hbase.bean.HBaseOperation; -import org.apache.shardingsphere.proxy.backend.hbase.converter.operation.HBaseUpdateOperation; -import org.apache.shardingsphere.proxy.backend.hbase.executor.HBaseExecutor; -import org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLUpdateStatement; - -import java.sql.SQLException; -import java.util.Collection; -import java.util.Collections; - -/** - * HBase update updater. - */ -public final class HBaseUpdateUpdater implements HBaseUpdater { - - @Override - public Collection executeUpdate(final HBaseOperation operation) throws SQLException { - if (operation.getOperation() instanceof HBaseUpdateOperation) { - HBaseExecutor.executeUpdate(operation.getTableName(), table -> table.put(((HBaseUpdateOperation) operation.getOperation()).getPuts())); - return Collections.singleton(new UpdateResult(((HBaseUpdateOperation) operation.getOperation()).getPuts().size(), 0L)); - } - HBaseExecutor.executeUpdate(operation.getTableName(), table -> table.put((Put) operation.getOperation())); - return Collections.singleton(new UpdateResult(1, 0L)); - } - - @Override - public Class getType() { - return MySQLUpdateStatement.class; - } -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseUpdater.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseUpdater.java deleted file mode 100644 index a9a79da47cf79..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseUpdater.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result.update; - -import org.apache.shardingsphere.infra.executor.sql.execute.result.update.UpdateResult; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI; -import org.apache.shardingsphere.proxy.backend.hbase.bean.HBaseOperation; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; - -import java.sql.SQLException; -import java.util.Collection; - -/** - * HBase backend updater. - */ -public interface HBaseUpdater extends TypedSPI { - - /** - * Execute HBase operation. - * - * @param operation HBase operation - * @return affected rows - * @throws SQLException SQL exception - */ - Collection executeUpdate(HBaseOperation operation) throws SQLException; - - @Override - Class getType(); -} diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/util/HBaseHeterogeneousUtils.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/util/HBaseHeterogeneousUtils.java deleted file mode 100644 index ad582c0042caa..0000000000000 --- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/util/HBaseHeterogeneousUtils.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.util; - -import com.google.common.base.Preconditions; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.ShorthandProjection; -import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ExpressionProjectionSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionSegment; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * HBase heterogeneous utility class. - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class HBaseHeterogeneousUtils { - - /** - * Whether crc projection segment. - * - * @param projectionSegment projection segment - * @return Is crc projection segment or not - */ - public static boolean isCrcProjectionSegment(final ProjectionSegment projectionSegment) { - - if (projectionSegment instanceof ExpressionProjectionSegment) { - return ((ExpressionProjectionSegment) projectionSegment).getText().contains("crc32"); - } - - return false; - } - - /** - * Convert prepared statement to literal statement. - * - * @param source source - * @param target target - * @param replacements replacements - * @return literal statement - */ - public static String replaceSQLStatementWithParameters(final String source, final CharSequence target, final Object... replacements) { - if (null == source || null == replacements) { - return source; - } - Matcher matcher = Pattern.compile(target.toString(), Pattern.LITERAL).matcher(source); - int found = 0; - StringBuffer sb = new StringBuffer(); - while (matcher.find()) { - found++; - Preconditions.checkState(found <= replacements.length, "Missing replacement for '%s' at [%s].", target, found); - matcher.appendReplacement(sb, Matcher.quoteReplacement(replacements[found - 1].toString())); - } - matcher.appendTail(sb); - return sb.toString(); - } - - /** - * Return true if using * in SELECT statement. - * - * @param statementContext select statement context - * @return is use shorthand projection - */ - public static boolean isUseShorthandProjection(final SelectStatementContext statementContext) { - return statementContext.getProjectionsContext().getProjections().stream().anyMatch(ShorthandProjection.class::isInstance); - } -} diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/CommonHeterogeneousSQLStatementCheckerTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/CommonHeterogeneousSQLStatementCheckerTest.java deleted file mode 100644 index cbfa623a2f151..0000000000000 --- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/CommonHeterogeneousSQLStatementCheckerTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.checker; - -import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseSupportedSQLStatement; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BetweenExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.SelectStatement; -import org.junit.jupiter.api.Test; - -import java.util.Optional; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -class CommonHeterogeneousSQLStatementCheckerTest { - - @Test - void assertIsSinglePoint() { - SelectStatement sqlStatement = (SelectStatement) HBaseSupportedSQLStatement.parseSQLStatement("select /*+ hbase */ * from t_order where rowKey = '1'"); - assertTrue(sqlStatement.getWhere().isPresent()); - new CommonHeterogeneousSQLStatementChecker(sqlStatement).checkIsSinglePointQuery(sqlStatement.getWhere().get()); - } - - @Test - void assertIsSinglePointWithErrorKey() { - SelectStatement sqlStatement = (SelectStatement) HBaseSupportedSQLStatement.parseSQLStatement("select /*+ hbase */ * from t_order where a = '1'"); - assertTrue(sqlStatement.getWhere().isPresent()); - Exception ex = assertThrows(IllegalArgumentException.class, () -> new CommonHeterogeneousSQLStatementChecker(sqlStatement).checkIsSinglePointQuery(sqlStatement.getWhere().get())); - assertThat(ex.getMessage(), is("a is not a allowed key.")); - } - - @Test - void assertIsSinglePointWithErrorOperation() { - SelectStatement sqlStatement = (SelectStatement) HBaseSupportedSQLStatement.parseSQLStatement("select /*+ hbase */ * from t_order where rowKey between '1' and '2' "); - assertTrue(sqlStatement.getWhere().isPresent()); - Exception ex = assertThrows(IllegalArgumentException.class, () -> new CommonHeterogeneousSQLStatementChecker(sqlStatement).checkIsSinglePointQuery(sqlStatement.getWhere().get())); - assertThat(ex.getMessage(), is("Only support binary operation expression.")); - } - - @Test - void assertInExpression() { - SelectStatement sqlStatement = (SelectStatement) HBaseSupportedSQLStatement.parseSQLStatement("select /*+ hbase */ * from t_order where rowKey in ('1', '2') "); - Optional whereSegment = sqlStatement.getWhere(); - assertTrue(whereSegment.isPresent()); - new CommonHeterogeneousSQLStatementChecker(sqlStatement).checkInExpressionIsExpected(whereSegment.get().getExpr()); - } - - @Test - void assertInExpressionWithNotIn() { - SelectStatement sqlStatement = (SelectStatement) HBaseSupportedSQLStatement.parseSQLStatement("select /*+ hbase */ * from t_order where rowKey not in ('1', '2') "); - Optional whereSegment = sqlStatement.getWhere(); - assertTrue(whereSegment.isPresent()); - Exception ex = assertThrows(IllegalArgumentException.class, () -> new CommonHeterogeneousSQLStatementChecker(sqlStatement).checkInExpressionIsExpected(whereSegment.get().getExpr())); - assertThat(ex.getMessage(), is("Do not supported `not in`.")); - } - - @Test - void assertInExpressionWithErrorKey() { - SelectStatement sqlStatement = (SelectStatement) HBaseSupportedSQLStatement.parseSQLStatement("select /*+ hbase */ * from t_order where a in ('1', '2') "); - Optional whereSegment = sqlStatement.getWhere(); - assertTrue(whereSegment.isPresent()); - Exception ex = assertThrows(IllegalArgumentException.class, () -> new CommonHeterogeneousSQLStatementChecker(sqlStatement).checkInExpressionIsExpected(whereSegment.get().getExpr())); - assertThat(ex.getMessage(), is("a is not a allowed key.")); - } - - @Test - void assertIsAllowExpressionSegment() { - SelectStatement sqlStatement = (SelectStatement) HBaseSupportedSQLStatement.parseSQLStatement("select /*+ hbase */ * from t_order where rowKey BETWEEN 'v1' AND 'v2' "); - Optional whereSegment = sqlStatement.getWhere(); - assertTrue(whereSegment.isPresent()); - BetweenExpression betweenExpression = (BetweenExpression) whereSegment.get().getExpr(); - CommonHeterogeneousSQLStatementChecker checker = new CommonHeterogeneousSQLStatementChecker(sqlStatement); - assertTrue(checker.isAllowExpressionSegment(betweenExpression.getBetweenExpr())); - assertTrue(checker.isAllowExpressionSegment(betweenExpression.getAndExpr())); - } - - @Test - void assertIsAllowExpressionSegmentError() { - SelectStatement sqlStatement = (SelectStatement) HBaseSupportedSQLStatement.parseSQLStatement("select /*+ hbase */ * from t_order where rowKey = '1'"); - Optional whereSegment = sqlStatement.getWhere(); - assertTrue(whereSegment.isPresent()); - assertFalse(new CommonHeterogeneousSQLStatementChecker(sqlStatement).isAllowExpressionSegment(whereSegment.get().getExpr())); - } -} diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HBaseCheckerFactoryTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HBaseCheckerFactoryTest.java deleted file mode 100644 index bb9cf747b9152..0000000000000 --- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HBaseCheckerFactoryTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.checker; - -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLShowCreateTableStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLDeleteStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLInsertStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLSelectStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLUpdateStatement; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.mock; - -class HBaseCheckerFactoryTest { - - @Test - void assertExecuteSelectStatement() { - SQLStatement sqlStatement = mock(MySQLSelectStatement.class); - HeterogeneousSQLStatementChecker actual = HBaseCheckerFactory.newInstance(sqlStatement); - assertThat(actual, instanceOf(HeterogeneousSelectStatementChecker.class)); - assertThat(actual.getSqlStatement(), is(sqlStatement)); - } - - @Test - void assertExecuteInsertStatement() { - SQLStatement sqlStatement = mock(MySQLInsertStatement.class); - HeterogeneousSQLStatementChecker actual = HBaseCheckerFactory.newInstance(sqlStatement); - assertThat(actual, instanceOf(HeterogeneousInsertStatementChecker.class)); - assertThat(actual.getSqlStatement(), is(sqlStatement)); - } - - @Test - void assertExecuteUpdateStatement() { - SQLStatement sqlStatement = mock(MySQLUpdateStatement.class); - HeterogeneousSQLStatementChecker actual = HBaseCheckerFactory.newInstance(sqlStatement); - assertThat(actual, instanceOf(HeterogeneousUpdateStatementChecker.class)); - assertThat(actual.getSqlStatement(), is(sqlStatement)); - } - - @Test - void assertExecuteDeleteStatement() { - SQLStatement sqlStatement = mock(MySQLDeleteStatement.class); - HeterogeneousSQLStatementChecker actual = HBaseCheckerFactory.newInstance(sqlStatement); - assertThat(actual, instanceOf(HeterogeneousDeleteStatementChecker.class)); - assertThat(actual.getSqlStatement(), is(sqlStatement)); - } - - @Test - void assertExecuteOtherStatement() { - SQLStatement sqlStatement = mock(MySQLShowCreateTableStatement.class); - HeterogeneousSQLStatementChecker actual = HBaseCheckerFactory.newInstance(sqlStatement); - assertThat(actual, instanceOf(CommonHeterogeneousSQLStatementChecker.class)); - assertThat(actual.getSqlStatement(), is(sqlStatement)); - } -} diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousDeleteStatementCheckerTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousDeleteStatementCheckerTest.java deleted file mode 100644 index 8aef77d7c625d..0000000000000 --- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousDeleteStatementCheckerTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.checker; - -import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseSupportedSQLStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.ArgumentsProvider; -import org.junit.jupiter.params.provider.ArgumentsSource; - -import java.util.stream.Stream; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertThrows; - -class HeterogeneousDeleteStatementCheckerTest { - - @ParameterizedTest(name = "{0}") - @ArgumentsSource(SupportedTestCaseArgumentsProvider.class) - void assertExecuteSuccess(final String name, final String sql) { - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql); - assertDoesNotThrow(() -> HBaseCheckerFactory.newInstance(sqlStatement).execute()); - } - - @ParameterizedTest(name = "{0}") - @ArgumentsSource(UnsupportedTestCaseArgumentsProvider.class) - void assertExecuteFailed(final String name, final String sql, final String expectedErrorMessage) { - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql); - Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute()); - assertThat(ex.getMessage(), is(expectedErrorMessage)); - } - - private static class SupportedTestCaseArgumentsProvider implements ArgumentsProvider { - - @Override - public Stream provideArguments(final ExtensionContext extensionContext) { - return Stream.of(Arguments.of("standard", HBaseSupportedSQLStatement.getDeleteStatement())); - } - } - - private static class UnsupportedTestCaseArgumentsProvider implements ArgumentsProvider { - - @Override - public Stream provideArguments(final ExtensionContext extensionContext) { - return Stream.of( - Arguments.of("operatorIsNotEqual", "delete /*+ hbase */ from t_test_order where rowKey > 1", "Only Supported `=` operator."), - Arguments.of("columnIsNotRowKey", "delete /*+ hbase */ from t_test_order where age = 1", "age is not a allowed key."), - Arguments.of("leftIsNotColumn", "delete /*+ hbase */ from t_test_order where 1 = 1", "Left segment must column segment."), - Arguments.of("MultipleExpressions", "DELETE /*+ hbase */ FROM t_order WHERE order_id = ? AND user_id = ? AND status=?", "Do not supported multiple expressions."), - Arguments.of("between", "DELETE /*+ hbase */ FROM t_order WHERE rowKey between 1 and 5", "Only support binary operation expression."), - Arguments.of("withoutWhere", "DELETE /*+ hbase */ FROM t_order", "Must contain where segment.")); - } - } -} diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousInsertStatementCheckerTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousInsertStatementCheckerTest.java deleted file mode 100644 index f4c472ab7cf74..0000000000000 --- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousInsertStatementCheckerTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.checker; - -import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseSupportedSQLStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.ArgumentsProvider; -import org.junit.jupiter.params.provider.ArgumentsSource; - -import java.util.stream.Stream; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertThrows; - -class HeterogeneousInsertStatementCheckerTest { - - @ParameterizedTest(name = "{0}") - @ArgumentsSource(SupportedTestCaseArgumentsProvider.class) - void assertExecuteSuccess(final String name, final String sql) { - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql); - assertDoesNotThrow(() -> HBaseCheckerFactory.newInstance(sqlStatement).execute()); - } - - @ParameterizedTest(name = "{0}") - @ArgumentsSource(UnsupportedTestCaseArgumentsProvider.class) - void assertExecuteFailed(final String name, final String sql, final String expectedErrorMessage) { - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql); - Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute()); - assertThat(ex.getMessage(), is(expectedErrorMessage)); - } - - private static class SupportedTestCaseArgumentsProvider implements ArgumentsProvider { - - @Override - public Stream provideArguments(final ExtensionContext extensionContext) { - return Stream.of(Arguments.of( - "standard", HBaseSupportedSQLStatement.getInsertStatement(), - "literalAndParameterMarker", "INSERT /*+ HBase */ INTO t_order_item(rowKey, order_id, user_id, status, creation_date) VALUES (?, ?, ?, 'insert', '2017-08-08')")); - } - } - - private static class UnsupportedTestCaseArgumentsProvider implements ArgumentsProvider { - - @Override - public Stream provideArguments(final ExtensionContext extensionContext) { - return Stream.of( - Arguments.of("withoutRowKey", "INSERT /*+ HBase */ INTO t_order (order_id, user_id, status) VALUES (?, ?, ?)", "First column must be rowKey."), - Arguments.of("withoutColumns", "INSERT /*+ HBase */ INTO t_order VALUES (?, ?, ?)", "The inserted column must be explicitly specified."), - Arguments.of("withMultipleRowKey", "INSERT /*+ HBase */ INTO t_order (rowKey, id, status) VALUES (?, ?, ?)", "Cannot contain multiple rowKeys."), - Arguments.of("onDuplicateKey", - "INSERT /*+ HBase */ INTO t_order (rowKey, user_id, status) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE status = ?", "Do not supported ON DUPLICATE KEY UPDATE"), - Arguments.of("function", - "INSERT /*+ HBase */ INTO t_order_item (rowKey, order_id, user_id, status, creation_date) VALUES (?, ?, ?, 'insert', now())", "Value must is literal or parameter marker."), - Arguments.of("subQuery", - "INSERT /*+ HBase */ INTO t_order_item(rowKey, order_id, user_id) select rowKey, order_id, user_id from t_order", "Do not supported `insert into...select...`")); - } - } -} diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousSelectStatementCheckerTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousSelectStatementCheckerTest.java deleted file mode 100644 index 33a580771b58d..0000000000000 --- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousSelectStatementCheckerTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.checker; - -import org.apache.shardingsphere.proxy.backend.hbase.context.HBaseContext; -import org.apache.shardingsphere.proxy.backend.hbase.props.HBaseProperties; -import org.apache.shardingsphere.proxy.backend.hbase.props.HBasePropertyKey; -import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseSupportedSQLStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.ArgumentsProvider; -import org.junit.jupiter.params.provider.ArgumentsSource; - -import java.util.stream.Stream; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -class HeterogeneousSelectStatementCheckerTest { - - @BeforeEach - void setUp() { - HBaseProperties props = mock(HBaseProperties.class); - when(props.getValue(HBasePropertyKey.MAX_SCAN_LIMIT_SIZE)).thenReturn(5000L); - HBaseContext.getInstance().setProps(props); - } - - @ParameterizedTest(name = "{0}") - @ArgumentsSource(SupportedTestCaseArgumentsProvider.class) - void assertExecuteSuccess(final String name, final String sql) { - assertDoesNotThrow(() -> HBaseCheckerFactory.newInstance(HBaseSupportedSQLStatement.parseSQLStatement(sql)).execute()); - } - - @ParameterizedTest(name = "{0}") - @ArgumentsSource(UnsupportedTestCaseArgumentsProvider.class) - void assertExecuteFailed(final String name, final String sql, final String expectedErrorMessage) { - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql); - Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute()); - assertThat(ex.getMessage(), is(expectedErrorMessage)); - } - - private static class SupportedTestCaseArgumentsProvider implements ArgumentsProvider { - - @Override - public Stream provideArguments(final ExtensionContext extensionContext) { - return Stream.of( - Arguments.of("pointSelect", HBaseSupportedSQLStatement.getSelectStatement()), - Arguments.of("parameterMarker", "SELECT /*+ HBase */ * FROM t_order WHERE rowKey IN (?, ?, ?)"), - Arguments.of("selectIn", "SELECT /*+ HBase */ * FROM t_order WHERE rowKey IN (1, 2, 3)"), - Arguments.of("between", "SELECT /*+ HBase */ * FROM t_order WHERE rowKey BETWEEN 1 AND 2"), - Arguments.of("useCrc32", "SELECT /*+ HBase */ crc32(concat_ws('#',rowKey)) FROM t_order WHERE rowKey IN (1, 2, 3)"), - Arguments.of("useCrc32", "SELECT /*+ HBase */ crc32(concat_ws('#',rowKey)) FROM t_order WHERE rowKey IN (1, 2, 3)")); - } - } - - private static class UnsupportedTestCaseArgumentsProvider implements ArgumentsProvider { - - @Override - public Stream provideArguments(final ExtensionContext extensionContext) { - return Stream.of( - Arguments.of("largeRowCount", "SELECT /*+ hbase */ * FROM t_order WHERE id = 1 LIMIT 5001", "Row count must less than 5000."), - Arguments.of("limit", "SELECT /*+ hbase */ * FROM t_order WHERE id = 1 LIMIT 5 OFFSET 3", "Do not supported offset segment."), - Arguments.of("lock", "SELECT /*+ hbase */ * FROM t_order WHERE id = 1 lock in share mode", "Do not supported lock segment."), - Arguments.of("function", "SELECT /*+ HBase */ sum(score) FROM person", "Only supported shorthand, column and crc32 expression projections."), - Arguments.of("join", "SELECT /*+ HBase */ * FROM t_order o JOIN t_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id", "Only supported simple table segment."), - Arguments.of("multipleIn", "SELECT /*+ HBase */ * FROM t_order WHERE rowKey IN (?, ?) AND id IN (?, ?)", "Left segment must column segment."), - Arguments.of("errorKey", "SELECT /*+ HBase */ * FROM t_order WHERE age IN (1, 2, 3)", "age is not a allowed key."), - Arguments.of("notIn", "SELECT /*+ HBase */ * FROM t_order WHERE rowKey NOT IN (1, 2, 3)", "Do not supported `not in`."), - Arguments.of("errorInExpression", "SELECT /*+ HBase */ * FROM t_order WHERE rowKey IN (SELECT rowKey FROM t_order_item)", "Only supported list expression."), - Arguments.of("notBetween", "SELECT /*+ HBase */ * FROM t_order WHERE rowKey not BETWEEN 1 AND 2", "Do not supported `not between...and...`"), - Arguments.of("betweenErrorKey", "SELECT /*+ HBase */ * FROM t_order WHERE age BETWEEN 1 AND 2", "age is not a allowed key."), - Arguments.of("errorBetweenExpr", "SELECT /*+ HBase */ * FROM t_order WHERE rowKey BETWEEN 1 AND now()", "Between expr must literal or parameter marker."), - Arguments.of("groupBy", "SELECT /*+ HBase */ * FROM t_order GROUP BY order_id", "Do not supported group by segment."), - Arguments.of("notAllowedOperator", "SELECT /*+ hbase */ * FROM t_order WHERE rowKey != 1", "Only Supported `=` operator."), - Arguments.of("notAllowedColumn", "SELECT /*+ hbase */ * FROM t_order WHERE age = 1", "age is not a allowed key."), - Arguments.of("multipleExpressions", "SELECT /*+ hbase */ * FROM t_order WHERE rowKey = 1 AND age = 2", "Do not supported multiple expressions."), - Arguments.of("notColumnExpression", "SELECT /*+ hbase */ * FROM t_order WHERE 1 = 1", "Left segment must column segment."), - Arguments.of("parameterMarker", "SELECT /*+ hbase */ rowKey, name, ? FROM t_order WHERE rowKey = 'kid'", "Only supported shorthand, column and crc32 expression projections.")); - } - } -} diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousUpdateStatementCheckerTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousUpdateStatementCheckerTest.java deleted file mode 100644 index 5a5241b996cfb..0000000000000 --- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousUpdateStatementCheckerTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.checker; - -import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseSupportedSQLStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.ArgumentsProvider; -import org.junit.jupiter.params.provider.ArgumentsSource; - -import java.util.stream.Stream; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertThrows; - -class HeterogeneousUpdateStatementCheckerTest { - - @ParameterizedTest(name = "{0}") - @ArgumentsSource(SupportedTestCaseArgumentsProvider.class) - void assertExecuteSuccess(final String name, final String sql) { - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql); - assertDoesNotThrow(() -> HBaseCheckerFactory.newInstance(sqlStatement).execute()); - } - - @ParameterizedTest(name = "{0}") - @ArgumentsSource(UnsupportedTestCaseArgumentsProvider.class) - void assertExecuteFailed(final String name, final String sql, final String expectedErrorMessage) { - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql); - Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute()); - assertThat(ex.getMessage(), is(expectedErrorMessage)); - } - - private static class SupportedTestCaseArgumentsProvider implements ArgumentsProvider { - - @Override - public Stream provideArguments(final ExtensionContext extensionContext) { - return Stream.of(Arguments.of("standard", HBaseSupportedSQLStatement.getUpdateStatement())); - } - } - - private static class UnsupportedTestCaseArgumentsProvider implements ArgumentsProvider { - - @Override - public Stream provideArguments(final ExtensionContext extensionContext) { - return Stream.of( - Arguments.of("function", "update /*+ hbase */ t_test_order set age = 10, name = 'bob', time = now() where rowKey = 1", "Assignment must is literal or parameter marker."), - Arguments.of("operatorIsNotEqual", "update /*+ hbase */ t_test_order set age = 10 where rowKey > 1", "Only Supported `=` operator."), - Arguments.of("columnIsNotRowKey", "update /*+ hbase */ t_test_order set age = 10 where age = 1", "age is not a allowed key."), - Arguments.of("leftIsNotColumn", "update /*+ hbase */ t_test_order set age = 10 where 1 = 1", "Left segment must column segment."), - Arguments.of("multiExpression", "update /*+ hbase */ t_test_order set age = 10 WHERE order_id = ? AND user_id = ? AND status=?", "Do not supported multiple expressions."), - Arguments.of("withoutWhere", "update /*+ hbase */ t_test_order set age = 10 ", "Must contain where segment."), - Arguments.of("updateRowKey", "update /*+ hbase */ t_test_order set rowKey = 10 where rowKey = 'kid'", "Do not allow update rowKey")); - } - } -} diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/HBaseOperationConverterFactoryTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/HBaseOperationConverterFactoryTest.java deleted file mode 100644 index 92aff0c731cb9..0000000000000 --- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/HBaseOperationConverterFactoryTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.converter; - -import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.binder.context.statement.dal.FlushStatementContext; -import org.apache.shardingsphere.infra.binder.context.statement.dml.DeleteStatementContext; -import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; -import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; -import org.apache.shardingsphere.infra.binder.context.statement.dml.UpdateStatementContext; -import org.apache.shardingsphere.proxy.backend.hbase.converter.type.HBaseDeleteOperationConverter; -import org.apache.shardingsphere.proxy.backend.hbase.converter.type.HBaseInsertOperationConverter; -import org.apache.shardingsphere.proxy.backend.hbase.converter.type.HBaseRegionReloadOperationConverter; -import org.apache.shardingsphere.proxy.backend.hbase.converter.type.HBaseSelectOperationConverter; -import org.apache.shardingsphere.proxy.backend.hbase.converter.type.HBaseUpdateOperationConverter; -import org.junit.jupiter.api.Test; - -import java.sql.SQLException; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.mock; - -class HBaseOperationConverterFactoryTest { - - @Test - void assertExecuteSelectStatement() throws SQLException { - SQLStatementContext sqlStatementContext = mock(SelectStatementContext.class); - HBaseOperationConverter converter = HBaseOperationConverterFactory.newInstance(sqlStatementContext); - assertThat(converter, instanceOf(HBaseSelectOperationConverter.class)); - } - - @Test - void assertExecuteInsertStatement() throws SQLException { - SQLStatementContext sqlStatementContext = mock(InsertStatementContext.class); - HBaseOperationConverter converter = HBaseOperationConverterFactory.newInstance(sqlStatementContext); - assertThat(converter, instanceOf(HBaseInsertOperationConverter.class)); - } - - @Test - void assertExecuteUpdateStatement() throws SQLException { - SQLStatementContext sqlStatementContext = mock(UpdateStatementContext.class); - HBaseOperationConverter converter = HBaseOperationConverterFactory.newInstance(sqlStatementContext); - assertThat(converter, instanceOf(HBaseUpdateOperationConverter.class)); - } - - @Test - void assertExecuteDeleteStatement() throws SQLException { - SQLStatementContext sqlStatementContext = mock(DeleteStatementContext.class); - HBaseOperationConverter converter = HBaseOperationConverterFactory.newInstance(sqlStatementContext); - assertThat(converter, instanceOf(HBaseDeleteOperationConverter.class)); - } - - @Test - void assertExecuteFlushStatement() throws SQLException { - SQLStatementContext sqlStatementContext = mock(FlushStatementContext.class); - HBaseOperationConverter converter = HBaseOperationConverterFactory.newInstance(sqlStatementContext); - assertThat(converter, instanceOf(HBaseRegionReloadOperationConverter.class)); - } -} diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/HBaseRowKeyExtractorTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/HBaseRowKeyExtractorTest.java deleted file mode 100644 index fb89ef1264603..0000000000000 --- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/HBaseRowKeyExtractorTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.converter; - -import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseSupportedSQLStatement; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.InExpression; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.SelectStatement; -import org.junit.jupiter.api.Test; - -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.junit.jupiter.api.Assertions.assertTrue; - -class HBaseRowKeyExtractorTest { - - @Test - void assertGetRowKeys() { - SelectStatement sqlStatement = (SelectStatement) HBaseSupportedSQLStatement.parseSQLStatement("select /*+ hbase */ * from t_order where rowKey in ('1', '2') "); - Optional whereSegment = sqlStatement.getWhere(); - assertTrue(whereSegment.isPresent()); - List actual = Arrays.asList("1", "2"); - List expected = HBaseRowKeyExtractor.getRowKeys((InExpression) whereSegment.get().getExpr()); - assertThat(actual, is(expected)); - } -} diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseDeleteOperationConverterTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseDeleteOperationConverterTest.java deleted file mode 100644 index 90c62a2a5e51a..0000000000000 --- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseDeleteOperationConverterTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.converter.type; - -import org.apache.hadoop.hbase.client.Delete; -import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.binder.SQLBindEngine; -import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.database.core.DefaultDatabase; -import org.apache.shardingsphere.infra.hint.HintValueContext; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; -import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; -import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; -import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; -import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; -import org.apache.shardingsphere.proxy.backend.hbase.bean.HBaseOperation; -import org.apache.shardingsphere.proxy.backend.hbase.converter.HBaseOperationConverter; -import org.apache.shardingsphere.proxy.backend.hbase.converter.HBaseOperationConverterFactory; -import org.apache.shardingsphere.proxy.backend.hbase.converter.operation.HBaseDeleteOperation; -import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseSupportedSQLStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; -import org.junit.jupiter.api.Test; - -import java.sql.SQLException; -import java.sql.Types; -import java.util.Collections; -import java.util.Map; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.RETURNS_DEEP_STUBS; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -class HBaseDeleteOperationConverterTest { - - @Test - void assertConvert() throws SQLException { - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(HBaseSupportedSQLStatement.getDeleteStatement()); - SQLStatementContext sqlStatementContext = new SQLBindEngine(mockMetaData(), DefaultDatabase.LOGIC_NAME, new HintValueContext()).bind(sqlStatement, Collections.emptyList()); - HBaseOperationConverter converter = HBaseOperationConverterFactory.newInstance(sqlStatementContext); - HBaseOperation hbaseOperation = converter.convert(); - assertThat(hbaseOperation.getTableName(), is(HBaseSupportedSQLStatement.HBASE_DATABASE_TABLE_NAME)); - assertThat(hbaseOperation.getOperation(), instanceOf(Delete.class)); - } - - @Test - void assertConvertWithIn() throws SQLException { - String sql = " delete /*+ hbase */ from t_test_order where rowKey in ('2', '1')"; - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql); - SQLStatementContext sqlStatementContext = new SQLBindEngine(mockMetaData(), DefaultDatabase.LOGIC_NAME, new HintValueContext()).bind(sqlStatement, Collections.emptyList()); - HBaseOperationConverter converter = HBaseOperationConverterFactory.newInstance(sqlStatementContext); - HBaseOperation hBaseOperation = converter.convert(); - assertThat(hBaseOperation.getTableName(), is(HBaseSupportedSQLStatement.HBASE_DATABASE_TABLE_NAME)); - assertThat(hBaseOperation.getOperation(), instanceOf(HBaseDeleteOperation.class)); - assertThat(((HBaseDeleteOperation) hBaseOperation.getOperation()).getDeletes().size(), is(2)); - } - - private ShardingSphereMetaData mockMetaData() { - ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); - ShardingSphereTable table = new ShardingSphereTable("t_test_order", Collections.singletonList(new ShardingSphereColumn("rowKey", Types.VARCHAR, true, false, false, false, true, false)), - Collections.emptyList(), Collections.emptyList()); - when(database.getSchema(DefaultDatabase.LOGIC_NAME).getTable("t_test_order")).thenReturn(table); - when(database.containsSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(true); - when(database.getSchema(DefaultDatabase.LOGIC_NAME).containsTable("t_test_order")).thenReturn(true); - Map databases = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database); - return new ShardingSphereMetaData(databases, mock(ResourceMetaData.class), mock(RuleMetaData.class), mock(ConfigurationProperties.class)); - - } -} diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseUpdateOperationConverterTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseUpdateOperationConverterTest.java deleted file mode 100644 index e7128a11c9378..0000000000000 --- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseUpdateOperationConverterTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.converter.type; - -import org.apache.hadoop.hbase.client.Put; -import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.binder.SQLBindEngine; -import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.database.core.DefaultDatabase; -import org.apache.shardingsphere.infra.hint.HintValueContext; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; -import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; -import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; -import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; -import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; -import org.apache.shardingsphere.proxy.backend.hbase.bean.HBaseOperation; -import org.apache.shardingsphere.proxy.backend.hbase.converter.HBaseOperationConverter; -import org.apache.shardingsphere.proxy.backend.hbase.converter.HBaseOperationConverterFactory; -import org.apache.shardingsphere.proxy.backend.hbase.converter.operation.HBaseUpdateOperation; -import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseSupportedSQLStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; -import org.junit.jupiter.api.Test; - -import java.sql.SQLException; -import java.sql.Types; -import java.util.Arrays; -import java.util.Collections; -import java.util.Map; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.RETURNS_DEEP_STUBS; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -class HBaseUpdateOperationConverterTest { - - @Test - void assertConvert() throws SQLException { - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(HBaseSupportedSQLStatement.getUpdateStatement()); - SQLStatementContext sqlStatementContext = new SQLBindEngine(mockMetaData(), DefaultDatabase.LOGIC_NAME, new HintValueContext()).bind(sqlStatement, Collections.emptyList()); - HBaseOperationConverter converter = HBaseOperationConverterFactory.newInstance(sqlStatementContext); - HBaseOperation operation = converter.convert(); - assertThat(operation.getTableName(), is(HBaseSupportedSQLStatement.HBASE_DATABASE_TABLE_NAME)); - assertThat(operation.getOperation(), instanceOf(Put.class)); - } - - @Test - void assertConvertWithIn() throws SQLException { - String sql = " update /*+ hbase */ t_test_order set age = 10 where rowKey in (1, '2')"; - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql); - SQLStatementContext sqlStatementContext = new SQLBindEngine(mockMetaData(), DefaultDatabase.LOGIC_NAME, new HintValueContext()).bind(sqlStatement, Collections.emptyList()); - HBaseOperationConverter converter = HBaseOperationConverterFactory.newInstance(sqlStatementContext); - HBaseOperation operation = converter.convert(); - assertThat(operation.getTableName(), is(HBaseSupportedSQLStatement.HBASE_DATABASE_TABLE_NAME)); - assertThat(operation.getOperation(), instanceOf(HBaseUpdateOperation.class)); - assertThat(((HBaseUpdateOperation) operation.getOperation()).getPuts().size(), is(2)); - } - - private ShardingSphereMetaData mockMetaData() { - ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); - ShardingSphereTable table = new ShardingSphereTable("t_test_order", Arrays.asList(new ShardingSphereColumn("rowKey", Types.VARCHAR, true, false, false, false, true, false), - new ShardingSphereColumn("age", Types.INTEGER, false, false, false, false, true, false)), Collections.emptyList(), Collections.emptyList()); - when(database.getSchema(DefaultDatabase.LOGIC_NAME).getTable("t_test_order")).thenReturn(table); - when(database.containsSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(true); - when(database.getSchema(DefaultDatabase.LOGIC_NAME).containsTable("t_test_order")).thenReturn(true); - Map databases = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database); - return new ShardingSphereMetaData(databases, mock(ResourceMetaData.class), mock(RuleMetaData.class), mock(ConfigurationProperties.class)); - - } -} diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/result/HBaseSupportedSQLStatement.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/result/HBaseSupportedSQLStatement.java deleted file mode 100644 index 0bc7fc299c002..0000000000000 --- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/result/HBaseSupportedSQLStatement.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result; - -import org.apache.shardingsphere.sql.parser.api.CacheOption; -import org.apache.shardingsphere.sql.parser.api.SQLParserEngine; -import org.apache.shardingsphere.sql.parser.api.SQLStatementVisitorEngine; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; - -/** - * SQL Statement which supported in HBase. - */ -public final class HBaseSupportedSQLStatement { - - public static final String HBASE_DATABASE_TABLE_NAME = "t_test_order"; - - private static final String INSERT = "insert /*+ hbase */ into t_test_order(rowKey, v1, v2) values(1, 2, 3)"; - - private static final String UPDATE = "update /*+ hbase */ t_test_order set age = 10 where rowKey = 1"; - - private static final String DELETE = "delete /*+ hbase */ from t_test_order where rowKey = 'kid'"; - - private static final String SELECT = "select /*+ hbase */ * from t_order where id = 1"; - - private static final String SHOW_DATABASES = "show /*+ hbase */ databases"; - - private static final String SHOW_TABLES = "show /*+ hbase */ tables"; - - private static final String SHOW_CREATE_TABLE = "show /*+ hbase */ create table t_test_order"; - - private static final String FLUSH_TABLES = "flush /*+ hbase */ tables t_test"; - - /** - * parse SQL statement. - * - * @param sql SQL - * @return SQL statement - */ - public static SQLStatement parseSQLStatement(final String sql) { - return new SQLStatementVisitorEngine("MySQL").visit(new SQLParserEngine("MySQL", new CacheOption(128, 4L)).parse(sql, false)); - } - - /** - * Get insert statement. - * - * @return insert statement - */ - public static String getInsertStatement() { - return INSERT; - } - - /** - * Get update statement. - * - * @return update statement - */ - public static String getUpdateStatement() { - return UPDATE; - } - - /** - * Get delete statement. - * - * @return delete statement - */ - public static String getDeleteStatement() { - return DELETE; - } - - /** - * Get select statement. - * - * @return select statement - */ - public static String getSelectStatement() { - return SELECT; - } - - /** - * Get show databases statement. - * - * @return show databases statement - */ - public static String getShowDatabaseStatement() { - return SHOW_DATABASES; - } - - /** - * Get show tables statement. - * - * @return show tables statement - */ - public static String getShowTablesStatement() { - return SHOW_TABLES; - } - - /** - * Get show create table statement. - * - * @return show create table statement - */ - public static String getShowCreateTableStatement() { - return SHOW_CREATE_TABLE; - } - - /** - * Get flush tables statement. - * - * @return flush tables statement - */ - public static String getFlushTablesStatement() { - return FLUSH_TABLES; - } -} diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/AbstractHBaseQueryResultSetTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/AbstractHBaseQueryResultSetTest.java deleted file mode 100644 index 655c129efc63a..0000000000000 --- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/AbstractHBaseQueryResultSetTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result.query; - -import lombok.Getter; -import org.apache.hadoop.hbase.HColumnDescriptor; -import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.client.Admin; -import org.apache.hadoop.hbase.client.Connection; -import org.apache.hadoop.hbase.client.Table; -import org.apache.shardingsphere.proxy.backend.hbase.context.HBaseContext; -import org.apache.shardingsphere.proxy.backend.hbase.props.HBaseProperties; -import org.apache.shardingsphere.proxy.backend.hbase.props.HBasePropertyKey; -import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseSupportedSQLStatement; -import org.apache.shardingsphere.test.util.PropertiesBuilder; -import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.mockito.junit.jupiter.MockitoSettings; -import org.mockito.quality.Strictness; - -import java.io.IOException; -import java.sql.SQLException; -import java.util.Collections; -import java.util.Properties; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.RETURNS_DEEP_STUBS; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -@ExtendWith(MockitoExtension.class) -@MockitoSettings(strictness = Strictness.LENIENT) -@Getter -abstract class AbstractHBaseQueryResultSetTest { - - @Mock - private Admin admin; - - @BeforeEach - void setUp() throws IOException, SQLException { - Properties props = PropertiesBuilder.build(new Property(HBasePropertyKey.WARM_UP_THREAD_NUM.getKey(), String.valueOf(1))); - HBaseContext.getInstance().setProps(new HBaseProperties(props)); - HTableDescriptor[] tableDescriptors = createHTableDescriptors(); - when(admin.tableExists(any())).thenReturn(true); - when(admin.getTableDescriptor(any())).thenReturn(tableDescriptors[0]); - when(admin.listTables()).thenReturn(tableDescriptors); - Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS); - when(connection.getAdmin()).thenReturn(admin); - when(connection.getTable(any())).thenReturn(mock(Table.class)); - HBaseContext.getInstance().init(Collections.singletonMap("cluster_lj", connection)); - } - - private HTableDescriptor[] createHTableDescriptors() { - HTableDescriptor descriptor = mock(HTableDescriptor.class); - when(descriptor.getNameAsString()).thenReturn(HBaseSupportedSQLStatement.HBASE_DATABASE_TABLE_NAME); - when(descriptor.toStringTableAttributes()).thenReturn("{attributes}"); - when(descriptor.getFlushPolicyClassName()).thenReturn(""); - when(descriptor.getMaxFileSize()).thenReturn(-1L); - when(descriptor.getMemStoreFlushSize()).thenReturn(-1L); - when(descriptor.getPriority()).thenReturn(0); - when(descriptor.getRegionReplication()).thenReturn(1); - when(descriptor.getRegionSplitPolicyClassName()).thenReturn(null); - when(descriptor.toStringCustomizedValues()).thenReturn(""); - when(descriptor.getFamilies()).thenReturn(Collections.singletonList(mock(HColumnDescriptor.class))); - return new HTableDescriptor[]{descriptor}; - } - - @AfterEach - void tearDown() throws SQLException { - HBaseContext.getInstance().close(); - } -} diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseDescribeResultSetTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseDescribeResultSetTest.java deleted file mode 100644 index 49e77f73b7f6f..0000000000000 --- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseDescribeResultSetTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result.query; - -import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext; -import org.apache.shardingsphere.infra.binder.context.statement.dal.ShowCreateTableStatementContext; -import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseSupportedSQLStatement; -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.RETURNS_DEEP_STUBS; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -class HBaseDescribeResultSetTest extends AbstractHBaseQueryResultSetTest { - - @Test - void assertGetRowData() throws SQLException { - HBaseQueryResultSet resultSet = new HBaseDescribeResultSet(); - ShowCreateTableStatementContext context = mock(ShowCreateTableStatementContext.class); - when(context.getTablesContext()).thenReturn(mock(TablesContext.class, RETURNS_DEEP_STUBS)); - when(context.getTablesContext().getTableNames().iterator().next()).thenReturn(HBaseSupportedSQLStatement.HBASE_DATABASE_TABLE_NAME); - resultSet.init(context); - List actual = new ArrayList<>(resultSet.getRowData()); - assertThat(actual.size(), is(9)); - assertThat(actual.get(0), is(HBaseSupportedSQLStatement.HBASE_DATABASE_TABLE_NAME)); - assertThat(actual.get(5), is(0)); - assertThat(actual.get(6), is(1)); - assertThat(actual.get(8), is("")); - } - - @Test - void assertGetRowDataWithTableIsNotExists() throws IOException { - when(getAdmin().tableExists(any())).thenReturn(false); - ShowCreateTableStatementContext context = mock(ShowCreateTableStatementContext.class); - when(context.getTablesContext()).thenReturn(mock(TablesContext.class, RETURNS_DEEP_STUBS)); - when(context.getTablesContext().getTableNames().iterator().next()).thenReturn(HBaseSupportedSQLStatement.HBASE_DATABASE_TABLE_NAME); - assertThrows(IllegalArgumentException.class, () -> new HBaseDescribeResultSet().init(context)); - } - - @Test - void assertGetRowDataWithBackendError() throws IOException { - when(getAdmin().getTableDescriptor(any())).thenThrow(IOException.class); - ShowCreateTableStatementContext context = mock(ShowCreateTableStatementContext.class); - when(context.getTablesContext()).thenReturn(mock(TablesContext.class, RETURNS_DEEP_STUBS)); - when(context.getTablesContext().getTableNames().iterator().next()).thenReturn(HBaseSupportedSQLStatement.HBASE_DATABASE_TABLE_NAME); - assertThrows(SQLException.class, () -> new HBaseDescribeResultSet().init(context)); - } -} diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseListResultSetTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseListResultSetTest.java deleted file mode 100644 index 9a948354f1737..0000000000000 --- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/result/query/HBaseListResultSetTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result.query; - -import org.apache.shardingsphere.infra.binder.context.statement.dal.ShowTablesStatementContext; -import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseSupportedSQLStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; -import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLShowTablesStatement; -import org.junit.jupiter.api.Test; - -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -class HBaseListResultSetTest extends AbstractHBaseQueryResultSetTest { - - @Test - void assertGetRowData() throws SQLException { - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(HBaseSupportedSQLStatement.getShowTablesStatement()); - HBaseQueryResultSet resultSet = new HBaseListResultSet(); - ShowTablesStatementContext context = mock(ShowTablesStatementContext.class); - when(context.getSqlStatement()).thenReturn((MySQLShowTablesStatement) sqlStatement); - resultSet.init(context); - assertTrue(resultSet.next()); - List actual = new ArrayList<>(resultSet.getRowData()); - assertThat(actual.size(), is(2)); - assertThat(actual.get(0), is("cluster_lj")); - assertThat(actual.get(1), is(HBaseSupportedSQLStatement.HBASE_DATABASE_TABLE_NAME)); - } - - @Test - void assertGetRowDataFromRemoteHBaseCluster() throws SQLException { - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement("show /*+ hbase */ tables from cluster_lj"); - HBaseQueryResultSet resultSet = new HBaseListResultSet(); - ShowTablesStatementContext context = mock(ShowTablesStatementContext.class); - when(context.getSqlStatement()).thenReturn((MySQLShowTablesStatement) sqlStatement); - resultSet.init(context); - - assertTrue(resultSet.next()); - List actual = new ArrayList<>(resultSet.getRowData()); - assertThat(actual.size(), is(2)); - assertThat(actual.get(0), is("cluster_lj")); - assertThat(actual.get(1), is(HBaseSupportedSQLStatement.HBASE_DATABASE_TABLE_NAME)); - } - - @Test - void assertGetRowDataByLike() throws SQLException { - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement("show /*+ hbase */ tables like 't_test' "); - HBaseQueryResultSet resultSet = new HBaseListResultSet(); - ShowTablesStatementContext context = mock(ShowTablesStatementContext.class); - when(context.getSqlStatement()).thenReturn((MySQLShowTablesStatement) sqlStatement); - resultSet.init(context); - sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement("show /*+ hbase */ tables like 't_test%' "); - when(context.getSqlStatement()).thenReturn((MySQLShowTablesStatement) sqlStatement); - resultSet.init(context); - assertTrue(resultSet.next()); - List actual = new ArrayList<>(resultSet.getRowData()); - assertThat(actual.size(), is(2)); - assertThat(actual.get(1), is(HBaseSupportedSQLStatement.HBASE_DATABASE_TABLE_NAME)); - } - - @Test - void assertGetRowDataError() { - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement("show /*+ hbase */ tables from cluster_do_not_exists"); - HBaseQueryResultSet resultSet = new HBaseListResultSet(); - ShowTablesStatementContext context = mock(ShowTablesStatementContext.class); - when(context.getSqlStatement()).thenReturn((MySQLShowTablesStatement) sqlStatement); - assertThrows(SQLException.class, () -> resultSet.init(context)); - } -} diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseBackendUpdateHandlerTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseBackendUpdateHandlerTest.java deleted file mode 100644 index 20f748f36ae5e..0000000000000 --- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/result/update/HBaseBackendUpdateHandlerTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.result.update; - -import org.apache.shardingsphere.infra.executor.sql.execute.result.update.UpdateResult; -import org.apache.shardingsphere.proxy.backend.hbase.handler.HBaseBackendUpdateHandler; -import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseSupportedSQLStatement; -import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; -import org.junit.jupiter.api.Test; - -import java.sql.SQLException; -import java.util.Collections; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -class HBaseBackendUpdateHandlerTest { - - @Test - void assertExecuteDeleteStatement() throws SQLException { - HBaseDeleteUpdater updater = mock(HBaseDeleteUpdater.class); - when(updater.executeUpdate(any())).thenReturn(Collections.singletonList(new UpdateResult(1, 0L))); - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(HBaseSupportedSQLStatement.getDeleteStatement()); - HBaseBackendUpdateHandler handler = new HBaseBackendUpdateHandler(sqlStatement, updater); - assertUpdateResponseHeader(sqlStatement, handler.execute()); - } - - @Test - void assertExecuteUpdateStatement() throws SQLException { - HBaseUpdateUpdater updater = mock(HBaseUpdateUpdater.class); - when(updater.executeUpdate(any())).thenReturn(Collections.singletonList(new UpdateResult(1, 0L))); - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(HBaseSupportedSQLStatement.getUpdateStatement()); - HBaseBackendUpdateHandler handler = new HBaseBackendUpdateHandler(sqlStatement, updater); - assertUpdateResponseHeader(sqlStatement, handler.execute()); - } - - @Test - void assertFlushTableStatement() throws SQLException { - HBaseRegionReloadUpdater updater = mock(HBaseRegionReloadUpdater.class); - when(updater.executeUpdate(any())).thenReturn(Collections.singletonList(new UpdateResult(1, 0L))); - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(HBaseSupportedSQLStatement.getFlushTablesStatement()); - HBaseBackendUpdateHandler handler = new HBaseBackendUpdateHandler(sqlStatement, updater); - assertUpdateResponseHeader(sqlStatement, handler.execute()); - } - - private void assertUpdateResponseHeader(final SQLStatement sqlStatement, final UpdateResponseHeader responseHeader) { - assertThat(responseHeader, instanceOf(UpdateResponseHeader.class)); - assertThat(responseHeader.getSqlStatement(), is(sqlStatement)); - assertThat(responseHeader.getUpdateCount(), is(1L)); - } -} diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/util/HBaseHeterogeneousUtilsTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/util/HBaseHeterogeneousUtilsTest.java deleted file mode 100644 index db3cb26f911f7..0000000000000 --- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/util/HBaseHeterogeneousUtilsTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.shardingsphere.proxy.backend.hbase.util; - -import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseSupportedSQLStatement; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionSegment; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.SelectStatement; -import org.junit.jupiter.api.Test; -import java.util.ArrayList; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -class HBaseHeterogeneousUtilsTest { - - @Test - void assertCrc32ProjectionSegment() { - String sql = "SELECT /*+ HBase */ rowKey, crc32(concat_ws('#',rowKey)) from t_order where rowKey in (1, 2, 3)"; - SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql); - List projectionSegments = new ArrayList<>(((SelectStatement) sqlStatement).getProjections().getProjections()); - assertTrue(HBaseHeterogeneousUtils.isCrcProjectionSegment(projectionSegments.get(1))); - } -} diff --git a/proxy/backend/type/pom.xml b/proxy/backend/type/pom.xml index 2b3cbba659b3b..bb7df05514089 100644 --- a/proxy/backend/type/pom.xml +++ b/proxy/backend/type/pom.xml @@ -31,6 +31,5 @@ mysql postgresql opengauss - hbase