Skip to content

Commit

Permalink
Merge branch 'master' into comment-switch-remove
Browse files Browse the repository at this point in the history
  • Loading branch information
TherChenYang committed Dec 28, 2023
2 parents c439b81 + c6fe882 commit 68f29b0
Show file tree
Hide file tree
Showing 62 changed files with 518 additions and 431 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/graalvm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#
# 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.
#

name: NativeTest CI - GraalVM Native Image

# Only execute CI when changes involving GraalVM Reachability Metadata and nativeTest are involved. Because most Contributors don't use GraalVM CE.
on:
pull_request:
branches: [ master ]
paths:
- '.github/workflows/graalvm.yml'
- 'infra/reachability-metadata/src/**'
- 'test/native/native-image-filter/**'
- 'test/native/src/**'

concurrency:
group: graalvm-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
MAVEN_OPTS: -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.http.retryHandler.class=standard -Dmaven.wagon.http.retryHandler.count=3 -Dspotless.apply.skip=true

jobs:
nativetest:
if: github.repository == 'apache/shardingsphere'
name: GraalVM - GraalVM CE for JDK ${{ matrix.java-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 60
strategy:
max-parallel: 20
fail-fast: false
matrix:
os: [ 'ubuntu-latest' ]
java-version: [ '17.0.9' ]
steps:
- uses: actions/checkout@v3
- uses: graalvm/setup-graalvm@v1
with:
java-version: ${{ matrix.java-version }}
distribution: 'graalvm-community'
github-token: ${{ secrets.GITHUB_TOKEN }}
cache: 'maven'
- name: Run nativeTest with GraalVM CE for ${{ matrix.java-version }}
run: ./mvnw -PnativeTestInShardingSphere -T1C -e clean test
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ WS
: [ \t\r\n] + ->skip
;

TRUE
: T R U E
;

FALSE
: F A L S E
;

CREATE
: C R E A T E
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private void dropUnusedEncryptor(final EncryptRuleConfiguration currentRuleConfi
findUnusedEncryptors(currentRuleConfig).forEach(each -> currentRuleConfig.getEncryptors().remove(each));
}

private static Collection<String> findUnusedEncryptors(final EncryptRuleConfiguration currentRuleConfig) {
private Collection<String> findUnusedEncryptors(final EncryptRuleConfiguration currentRuleConfig) {
Collection<String> inUsedEncryptors = currentRuleConfig.getTables().stream().flatMap(each -> each.getColumns().stream()).map(optional -> optional.getCipher().getEncryptorName())
.collect(Collectors.toSet());
inUsedEncryptors.addAll(currentRuleConfig.getTables().stream().flatMap(each -> each.getColumns().stream())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private void dropUnusedAlgorithm(final MaskRuleConfiguration currentRuleConfig)
findUnusedAlgorithms(currentRuleConfig).forEach(each -> currentRuleConfig.getMaskAlgorithms().remove(each));
}

private static Collection<String> findUnusedAlgorithms(final MaskRuleConfiguration currentRuleConfig) {
private Collection<String> findUnusedAlgorithms(final MaskRuleConfiguration currentRuleConfig) {
Collection<String> inUsedAlgorithms = currentRuleConfig.getTables().stream().flatMap(each -> each.getColumns().stream()).map(MaskColumnRuleConfiguration::getMaskAlgorithm)
.collect(Collectors.toSet());
return currentRuleConfig.getMaskAlgorithms().keySet().stream().filter(each -> !inUsedAlgorithms.contains(each)).collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void dropUnusedLoadBalancer(final ReadwriteSplittingRuleConfiguration cu
findUnusedLoadBalancers(currentRuleConfig).forEach(each -> currentRuleConfig.getLoadBalancers().remove(each));
}

private static Collection<String> findUnusedLoadBalancers(final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
private Collection<String> findUnusedLoadBalancers(final ReadwriteSplittingRuleConfiguration currentRuleConfig) {
Collection<String> inUsedAlgorithms = currentRuleConfig.getDataSources().stream().map(ReadwriteSplittingDataSourceRuleConfiguration::getLoadBalancerName).collect(Collectors.toSet());
return currentRuleConfig.getLoadBalancers().keySet().stream().filter(each -> !inUsedAlgorithms.contains(each)).collect(Collectors.toSet());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private void dropUnusedAlgorithm(final ShadowRuleConfiguration currentRuleConfig
findUnusedAlgorithms(currentRuleConfig).forEach(each -> currentRuleConfig.getShadowAlgorithms().remove(each));
}

private static Collection<String> findUnusedAlgorithms(final ShadowRuleConfiguration currentRuleConfig) {
private Collection<String> findUnusedAlgorithms(final ShadowRuleConfiguration currentRuleConfig) {
Collection<String> inUsedAlgorithms = currentRuleConfig.getTables().entrySet().stream().flatMap(entry -> entry.getValue().getShadowAlgorithmNames().stream()).collect(Collectors.toSet());
if (null != currentRuleConfig.getDefaultShadowAlgorithmName()) {
inUsedAlgorithms.add(currentRuleConfig.getDefaultShadowAlgorithmName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private void dropUnusedKeyGenerator(final ShardingRuleConfiguration currentRuleC
findUnusedKeyGenerator(currentRuleConfig).forEach(each -> currentRuleConfig.getKeyGenerators().remove(each));
}

private static Collection<String> findUnusedKeyGenerator(final ShardingRuleConfiguration currentRuleConfig) {
private Collection<String> findUnusedKeyGenerator(final ShardingRuleConfiguration currentRuleConfig) {
Collection<String> inUsedKeyGenerators = currentRuleConfig.getTables().stream().map(ShardingTableRuleConfiguration::getKeyGenerateStrategy).filter(Objects::nonNull)
.map(KeyGenerateStrategyConfiguration::getKeyGeneratorName).collect(Collectors.toSet());
inUsedKeyGenerators.addAll(currentRuleConfig.getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getKeyGenerateStrategy).filter(Objects::nonNull)
Expand All @@ -154,7 +154,7 @@ private void dropUnusedAuditor(final ShardingRuleConfiguration currentRuleConfig
findUnusedAuditors(currentRuleConfig).forEach(each -> currentRuleConfig.getAuditors().remove(each));
}

private static Collection<String> findUnusedAuditors(final ShardingRuleConfiguration currentRuleConfig) {
private Collection<String> findUnusedAuditors(final ShardingRuleConfiguration currentRuleConfig) {
Collection<String> inUsedAuditors = currentRuleConfig.getTables().stream().map(ShardingTableRuleConfiguration::getAuditStrategy).filter(Objects::nonNull)
.flatMap(each -> each.getAuditorNames().stream()).collect(Collectors.toSet());
inUsedAuditors.addAll(currentRuleConfig.getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getAuditStrategy).filter(Objects::nonNull)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,18 @@
package org.apache.shardingsphere.sharding.distsql.segment.strategy;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.distsql.segment.AlgorithmSegment;
import org.apache.shardingsphere.sql.parser.api.ASTNode;

/**
* Key generate strategy segment.
*/
@RequiredArgsConstructor
@Getter
public final class KeyGenerateStrategySegment implements ASTNode {

private final String keyGenerateColumn;

private final AlgorithmSegment keyGenerateAlgorithmSegment;

public KeyGenerateStrategySegment(final String keyGenerateColumn, final AlgorithmSegment keyGenerateAlgorithmSegment) {
this.keyGenerateColumn = keyGenerateColumn;
this.keyGenerateAlgorithmSegment = keyGenerateAlgorithmSegment;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.infra.binder.segment.parameter;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.binder.segment.parameter.impl.ParameterMarkerExpressionSegmentBinder;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.ParameterMarkerSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.bounded.ColumnSegmentBoundedInfo;

import java.util.Collection;
import java.util.LinkedList;
import java.util.Map;

/**
* Parameter marker segment binder.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ParameterMarkerSegmentBinder {

/**
* Bind parameter marker segment with metadata.
*
* @param parameterMarkerSegments parameter marker segments
* @param parameterMarkerSegmentBoundedInfos parameter marker segment bounded infos
* @return bounded parameter marker segment
*/
public static Collection<ParameterMarkerSegment> bind(final Collection<ParameterMarkerSegment> parameterMarkerSegments,
final Map<ParameterMarkerSegment, ColumnSegmentBoundedInfo> parameterMarkerSegmentBoundedInfos) {
Collection<ParameterMarkerSegment> result = new LinkedList<>();
parameterMarkerSegments.forEach(each -> result.add(bind(each, parameterMarkerSegmentBoundedInfos)));
return result;
}

private static ParameterMarkerSegment bind(final ParameterMarkerSegment parameterMarkerSegment,
final Map<ParameterMarkerSegment, ColumnSegmentBoundedInfo> parameterMarkerSegmentBoundedInfos) {
if (parameterMarkerSegment instanceof ParameterMarkerExpressionSegment) {
return ParameterMarkerExpressionSegmentBinder.bind((ParameterMarkerExpressionSegment) parameterMarkerSegment, parameterMarkerSegmentBoundedInfos);
}
// TODO support more ParameterMarkerSegment bind
return parameterMarkerSegment;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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.infra.binder.segment.parameter.impl;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.binder.enums.SegmentType;
import org.apache.shardingsphere.infra.binder.segment.expression.ExpressionSegmentBinder;
import org.apache.shardingsphere.infra.binder.segment.from.TableSegmentBinderContext;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementBinderContext;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.ParameterMarkerSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.bounded.ColumnSegmentBoundedInfo;

import java.util.Map;

/**
* Binary operation expression binder.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ParameterMarkerExpressionSegmentBinder {

/**
* Bind binary operation expression with metadata.
*
* @param segment binary operation expression segment
* @param parentSegmentType parent segment type
* @param statementBinderContext statement binder context
* @param tableBinderContexts table binder contexts
* @param outerTableBinderContexts outer table binder contexts
* @return bounded binary operation expression segment
*/
public static BinaryOperationExpression bind(final BinaryOperationExpression segment, final SegmentType parentSegmentType, final SQLStatementBinderContext statementBinderContext,
final Map<String, TableSegmentBinderContext> tableBinderContexts, final Map<String, TableSegmentBinderContext> outerTableBinderContexts) {
ExpressionSegment boundedLeft = ExpressionSegmentBinder.bind(segment.getLeft(), parentSegmentType, statementBinderContext, tableBinderContexts, outerTableBinderContexts);
ExpressionSegment boundedRight = ExpressionSegmentBinder.bind(segment.getRight(), parentSegmentType, statementBinderContext, tableBinderContexts, outerTableBinderContexts);
return new BinaryOperationExpression(segment.getStartIndex(), segment.getStopIndex(), boundedLeft, boundedRight, segment.getOperator(), segment.getText());
}

/**
* Bind parameter marker expression segment with metadata.
*
* @param segment parameter marker expression segment
* @param boundedInfos parameter marker expression segment bounded info map
* @return bounded parameter marker expression segment
*/
public static ParameterMarkerExpressionSegment bind(final ParameterMarkerExpressionSegment segment,
final Map<ParameterMarkerSegment, ColumnSegmentBoundedInfo> boundedInfos) {
ColumnSegmentBoundedInfo boundedInfo = boundedInfos.get(segment);
if (null != boundedInfo) {
ParameterMarkerExpressionSegment result =
new ParameterMarkerExpressionSegment(segment.getStartIndex(), segment.getStopIndex(), segment.getParameterMarkerIndex(), segment.getParameterMarkerType());
segment.getAliasSegment().ifPresent(result::setAlias);
result.setBoundedInfo(boundedInfo);
return result;
}
return segment;
}
}
Loading

0 comments on commit 68f29b0

Please sign in to comment.