Skip to content

Commit

Permalink
Merge branch 'apache:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
YaoFly authored Dec 27, 2024
2 parents fea4fa2 + 829099d commit abcda97
Show file tree
Hide file tree
Showing 76 changed files with 1,466 additions and 346 deletions.
3 changes: 3 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
1. SQL Binder: Support rename table statement sql bind and split segment bind to ddl and dml package - [#34158](https://github.com/apache/shardingsphere/pull/34158)
1. SQL Binder: Support copy statement sql bind and add bind test case - [#34159](https://github.com/apache/shardingsphere/pull/34159)
1. SQL Binder: Support truncate table sql bind and add test case - [#34162](https://github.com/apache/shardingsphere/pull/34162)
1. SQL Binder: Support create view, alter view, drop view sql bind logic - [#34167](https://github.com/apache/shardingsphere/pull/34167)
1. Transaction: Support savepoint/release savepoint TCL statements in jdbc adapter -[#34173](https://github.com/apache/shardingsphere/pull/34173)
1. Kernel: Add WithAvailable interface and encrypt with, combine, insert select support checker - [#34175](https://github.com/apache/shardingsphere/pull/34175)

### Bug Fixes

Expand Down
2 changes: 2 additions & 0 deletions docs/document/content/features/encrypt/appendix.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ weight = 3
- 加密字段无法支持比较操作,如:大于、小于、ORDER BY、BETWEEN 等;
- 加密字段无法支持计算操作,如:AVG、SUM 以及计算表达式;
- 不支持子查询中包含加密字段,并且外层投影使用星号的 SQL;
- 不支持 WITH 语句中包含加密列;
- 不支持 INSERT SELECT 语句中包含加密列;
- 不支持 UNION、INTERSECT、EXCEPT 等集合运算语句中包含加密列。

其他:
Expand Down
2 changes: 2 additions & 0 deletions docs/document/content/features/encrypt/appendix.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Unsupported SQL:
- Comparison operations are not supported for encrypted fields, such as GREATER THAN, LESS THAN, ORDER BY, BETWEEN.
- Calculation operations are not supported for encrypted fields, such as AVG, SUM, and computation expressions.
- SQL that contains encrypt column in subquery and uses asterisks for outer projection is not supported.
- SQL that contains encrypt column in WITH is not supported.
- SQL that contains encrypt column in INSERT SELECT is not supported.
- SQL that contains encrypt column in UNION, INTERSECT, and EXCEPT statements is not supported.

Other:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
+++
title = "LOCK CLUSTER WITH"
weight = 16
+++

### 描述

`LOCK CLUSTER WITH` 语法用于向 `CLUSTER` 施加特定算法的锁。

### 语法

{{< tabs >}}
{{% tab name="语法" %}}

```sql
LockClusterWith ::=
'LOCK' 'CLUSTER' 'WITH' lockStrategy ('TIMEOUT' timeoutMillis)?

timeoutmillis ::=
long
```

{{% /tab %}}
{{% tab name="铁路图" %}}
<iframe frameborder="0" name="diagram" id="diagram" width="100%" height="100%"></iframe>
{{% /tab %}}
{{< /tabs >}}

### 补充说明

-`CLUSTER` 已经处于被锁状态时,无法重复加锁,否则会抛出异常。
- `lockStrategy` 当前支持两种锁策略,分别是排他锁 `WRITE` 与读写锁 `READ_WRITE`
- `timeoutMillis` 用于表明尝试加锁的超时时间,其单位为毫秒,未指定时,默认为 3000 毫秒。

### 示例

- 采用排他锁锁定 `CLUSTER` ,不设置超时时间

```sql
LOCK CLUSTER WITH WRITE;
```

- 采用读写锁锁定 `CLUSTER` ,并设置超时时间为 2000 毫秒

```sql
LOCK CLUSTER WITH READ_WRITE TIMEOUT 2000;
```

### 保留字

`LOCK``CLUSTER``WITH`

### 相关链接

- [保留字](/cn/user-manual/shardingsphere-proxy/distsql/syntax/reserved-word/)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
+++
title = "LOCK CLUSTER WITH"
weight = 16
+++

### Description

The `LOCK CLUSTER WITH` syntax is utilized to apply a lock with a specific algorithm to the `CLUSTER`.

### Syntax

{{< tabs >}}
{{% tab name="Grammar" %}}

```sql
LockClusterWith ::=
'LOCK' 'CLUSTER' 'WITH' lockStrategy ('TIMEOUT' timeoutMillis)?

timeoutmillis ::=
long
```

{{% /tab %}}
{{% tab name="Railroad diagram" %}}

<iframe frameborder="0" name="diagram" id="diagram" width="100%" height="100%"></iframe>{{% /tab %}}{{< /tabs >}}

### Supplement

- When the `CLUSTER` is already locked, it is impossible to re-lock it, otherwise an exception will be thrown.
- Currently, the `lockStrategy` supports two lock strategies, namely the exclusive lock `WRITE` and the read-write lock `READ_WRITE` .
- The `timeoutMillis` is used to indicate the timeout period for attempting to acquire the lock, with the unit being milliseconds. When not specified, the default value is 3,000 milliseconds.

### Example

- Lock the `CLUSTER` with an exclusive lock without setting the timeout.
-
```sql
LOCK CLUSTER WITH WRITE;
```

- Lock the CLUSTER with a read-write lock and set the timeout to 2000 milliseconds.
-
```sql
LOCK CLUSTER WITH READ_WRITE TIMEOUT 2000;
```

### Reserved words

`LOCK`,`CLUSTER`,`WITH`

### Related links

- [Reserved word](/en/user-manual/shardingsphere-proxy/distsql/syntax/reserved-word/)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
+++
title = "UNLOCK CLUSTER"
weight = 17
+++

### 描述

`UNLOCK CLUSTER` 语法用于解除通过 `LOCK CLUSTER WITH` 语句施加在 `CLUSTER` 上的锁。

### 语法

{{< tabs >}}
{{% tab name="语法" %}}

```sql
UnlockCluster ::=
'UNLOCK' 'CLUSTER' ('TIMEOUT' timeoutMillis)?

timeoutmillis ::=
long
```

{{% /tab %}}
{{% tab name="铁路图" %}}
<iframe frameborder="0" name="diagram" id="diagram" width="100%" height="100%"></iframe>
{{% /tab %}}
{{< /tabs >}}

### 补充说明

-`CLUSTER` 不处于被锁状态时,无法解除锁,否则会抛出异常。
- `timeoutMillis` 表明尝试解锁的超时时间,其单位为毫秒,未指定时,默认为 3000 毫秒。

### 示例

- 解锁 `CLUSTER` ,不设置超时时间。

```sql
UNLOCK CLUSTER;
```

- 解锁 `CLUSTER` ,并设置超时时间为 2000 毫秒。

```sql
UNLOCK CLUSTER TIMEOUT 2000;
```

### 保留字

`UNLOCK``CLUSTER`

### 相关链接

- [保留字](/cn/user-manual/shardingsphere-proxy/distsql/syntax/reserved-word/)
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
+++
title = "UNLOCK CLUSTER"
weight = 17
+++

### Description

The `UNLOCK CLUSTER` syntax is used to release the lock applied to the `CLUSTER` by the `LOCK CLUSTER WITH` statement.

### Syntax

{{< tabs >}}
{{% tab name="Grammar" %}}

```sql
UnlockCluster ::=
'UNLOCK' 'CLUSTER' ('TIMEOUT' timeoutMillis)?

timeoutmillis ::=
long
```

{{% /tab %}}
{{% tab name="Railroad diagram" %}}

<iframe frameborder="0" name="diagram" id="diagram" width="100%" height="100%"></iframe>{{% /tab %}}{{< /tabs >}}

### Supplement

- When the `CLUSTER` is not in a locked state, it is impossible to release the lock; otherwise, an exception will be thrown.
- `timeoutMillis` is used to indicate the timeout duration for attempting to unlock, with the unit being milliseconds. When not specified, the default value is 3,000 milliseconds.

### Example

- Unlock the `CLUSTER` without setting a timeout.
-
```sql
UNLOCK CLUSTER;
```

- Unlock the `CLUSTER` and set the timeout to 2000 milliseconds.

```sql
UNLOCK CLUSTER TIMEOUT 2000;
```

### Reserved words

`UNLOCK`,`CLUSTER`

### Related links

- [Reserved word](/en/user-manual/shardingsphere-proxy/distsql/syntax/reserved-word/)
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

package org.apache.shardingsphere.encrypt.checker.sql;

import org.apache.shardingsphere.encrypt.checker.sql.combine.EncryptCombineClauseSupportedChecker;
import org.apache.shardingsphere.encrypt.checker.sql.insert.EncryptInsertSelectSupportedChecker;
import org.apache.shardingsphere.encrypt.checker.sql.orderby.EncryptOrderByItemSupportedChecker;
import org.apache.shardingsphere.encrypt.checker.sql.predicate.EncryptPredicateColumnSupportedChecker;
import org.apache.shardingsphere.encrypt.checker.sql.projection.EncryptInsertSelectProjectionSupportedChecker;
import org.apache.shardingsphere.encrypt.checker.sql.projection.EncryptSelectProjectionSupportedChecker;
import org.apache.shardingsphere.encrypt.checker.sql.with.EncryptWithClauseSupportedChecker;
import org.apache.shardingsphere.encrypt.constant.EncryptOrder;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.infra.checker.SupportedSQLChecker;
Expand All @@ -40,7 +43,10 @@ public Collection<SupportedSQLChecker<?, EncryptRule>> getSupportedSQLCheckers()
new EncryptSelectProjectionSupportedChecker(),
new EncryptInsertSelectProjectionSupportedChecker(),
new EncryptPredicateColumnSupportedChecker(),
new EncryptOrderByItemSupportedChecker());
new EncryptOrderByItemSupportedChecker(),
new EncryptWithClauseSupportedChecker(),
new EncryptCombineClauseSupportedChecker(),
new EncryptInsertSelectSupportedChecker());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.encrypt.checker.sql.combine;

import org.apache.shardingsphere.encrypt.exception.syntax.UnsupportedEncryptSQLException;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.infra.binder.context.extractor.SQLStatementContextExtractor;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.checker.SupportedSQLChecker;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;

import java.util.Collection;

/**
* Combine clause supported checker for encrypt.
*/
@HighFrequencyInvocation
public final class EncryptCombineClauseSupportedChecker implements SupportedSQLChecker<SQLStatementContext, EncryptRule> {

@Override
public boolean isCheck(final SQLStatementContext sqlStatementContext) {
if (isContainsCombine(sqlStatementContext)) {
return true;
}
for (SelectStatementContext each : SQLStatementContextExtractor.getAllSubqueryContexts(sqlStatementContext)) {
if (isContainsCombine(each)) {
return true;
}
}
return false;
}

private static boolean isContainsCombine(final SQLStatementContext sqlStatementContext) {
return sqlStatementContext instanceof SelectStatementContext && ((SelectStatementContext) sqlStatementContext).isContainsCombine();
}

@Override
public void check(final EncryptRule rule, final ShardingSphereDatabase database, final ShardingSphereSchema currentSchema, final SQLStatementContext sqlStatementContext) {
Collection<String> tableNames = SQLStatementContextExtractor.getTableNames(database, sqlStatementContext);
for (String each : tableNames) {
ShardingSpherePreconditions.checkState(!rule.findEncryptTable(each).isPresent(), () -> new UnsupportedEncryptSQLException("COMBINE"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.encrypt.checker.sql.insert;

import org.apache.shardingsphere.encrypt.exception.syntax.UnsupportedEncryptSQLException;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.infra.binder.context.extractor.SQLStatementContextExtractor;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.checker.SupportedSQLChecker;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;

import java.util.Collection;

/**
* Insert select supported checker for encrypt.
*/
@HighFrequencyInvocation
public final class EncryptInsertSelectSupportedChecker implements SupportedSQLChecker<InsertStatementContext, EncryptRule> {

@Override
public boolean isCheck(final SQLStatementContext sqlStatementContext) {
return sqlStatementContext instanceof InsertStatementContext && ((InsertStatementContext) sqlStatementContext).getSqlStatement().getInsertSelect().isPresent();
}

@Override
public void check(final EncryptRule rule, final ShardingSphereDatabase database, final ShardingSphereSchema currentSchema, final InsertStatementContext sqlStatementContext) {
Collection<String> tableNames = SQLStatementContextExtractor.getTableNames(database, sqlStatementContext);
for (String each : tableNames) {
ShardingSpherePreconditions.checkState(!rule.findEncryptTable(each).isPresent(), () -> new UnsupportedEncryptSQLException("INSERT ... SELECT ..."));
}
}
}
Loading

0 comments on commit abcda97

Please sign in to comment.