-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add alter/show streaming rule SQL parse IT
- Loading branch information
Showing
15 changed files
with
434 additions
and
8 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
...n/java/org/apache/shardingsphere/cdc/distsql/handler/query/ShowStreamingRuleExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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.cdc.distsql.handler.query; | ||
|
||
import org.apache.shardingsphere.cdc.distsql.statement.ShowStreamingRuleStatement; | ||
import org.apache.shardingsphere.data.pipeline.common.config.process.PipelineProcessConfiguration; | ||
import org.apache.shardingsphere.data.pipeline.common.context.PipelineContextKey; | ||
import org.apache.shardingsphere.data.pipeline.core.job.service.InventoryIncrementalJobAPI; | ||
import org.apache.shardingsphere.data.pipeline.core.job.service.PipelineJobAPI; | ||
import org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor; | ||
import org.apache.shardingsphere.infra.instance.metadata.InstanceType; | ||
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; | ||
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; | ||
import org.apache.shardingsphere.infra.util.json.JsonUtils; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.LinkedList; | ||
|
||
/** | ||
* Show streaming rule executor. | ||
*/ | ||
public final class ShowStreamingRuleExecutor implements QueryableRALExecutor<ShowStreamingRuleStatement> { | ||
|
||
@Override | ||
public Collection<LocalDataQueryResultRow> getRows(final ShowStreamingRuleStatement sqlStatement) { | ||
PipelineProcessConfiguration processConfig = ((InventoryIncrementalJobAPI) TypedSPILoader.getService(PipelineJobAPI.class, "STREAMING")) | ||
.showProcessConfiguration(new PipelineContextKey(InstanceType.PROXY)); | ||
Collection<LocalDataQueryResultRow> result = new LinkedList<>(); | ||
result.add(new LocalDataQueryResultRow(getString(processConfig.getRead()), getString(processConfig.getWrite()), getString(processConfig.getStreamChannel()))); | ||
return result; | ||
} | ||
|
||
private String getString(final Object obj) { | ||
return null == obj ? "" : JsonUtils.toJsonString(obj); | ||
} | ||
|
||
@Override | ||
public Collection<String> getColumnNames() { | ||
return Arrays.asList("read", "write", "stream_channel"); | ||
} | ||
|
||
@Override | ||
public Class<ShowStreamingRuleStatement> getType() { | ||
return ShowStreamingRuleStatement.class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...main/java/org/apache/shardingsphere/cdc/distsql/statement/ShowStreamingRuleStatement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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.cdc.distsql.statement; | ||
|
||
import org.apache.shardingsphere.distsql.statement.ral.pipeline.cdc.QueryableCDCRALStatement; | ||
|
||
/** | ||
* Show streaming rule statement. | ||
*/ | ||
public final class ShowStreamingRuleStatement extends QueryableCDCRALStatement { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...nal/asserts/statement/ral/impl/pipeline/AlterInventoryIncrementalRuleStatementAssert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* 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.test.it.sql.parser.internal.asserts.statement.ral.impl.pipeline; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import org.apache.shardingsphere.distsql.segment.AlgorithmSegment; | ||
import org.apache.shardingsphere.distsql.segment.ReadOrWriteSegment; | ||
import org.apache.shardingsphere.distsql.statement.ral.updatable.AlterInventoryIncrementalRuleStatement; | ||
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext; | ||
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.domain.statement.ral.AlterInventoryIncrementalRuleStatementTestCase; | ||
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.distsql.ExpectedAlgorithm; | ||
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.distsql.ral.ExpectedRead; | ||
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.distsql.ral.ExpectedWrite; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
/** | ||
* Alter inventory incremental rule statement assert. | ||
*/ | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class AlterInventoryIncrementalRuleStatementAssert { | ||
|
||
/** | ||
* Assert statement is correct with expected parser result. | ||
* | ||
* @param assertContext assert context | ||
* @param actual actual statement | ||
* @param expected expected statement test case | ||
*/ | ||
public static void assertIs(final SQLCaseAssertContext assertContext, final AlterInventoryIncrementalRuleStatement actual, final AlterInventoryIncrementalRuleStatementTestCase expected) { | ||
if (null == expected) { | ||
assertNull(actual, assertContext.getText("Actual statement should not exist.")); | ||
} else { | ||
assertThat(actual.getJobTypeName(), is(expected.getJobTypeName())); | ||
assertRead(assertContext, actual.getProcessConfigSegment().getReadSegment(), expected.getRule().getRead()); | ||
assertWrite(assertContext, actual.getProcessConfigSegment().getWriteSegment(), expected.getRule().getWrite()); | ||
assertTypeStrategy(assertContext, actual.getProcessConfigSegment().getStreamChannel(), expected.getRule().getStreamChannel()); | ||
} | ||
} | ||
|
||
private static void assertRead(final SQLCaseAssertContext assertContext, final ReadOrWriteSegment actual, final ExpectedRead expected) { | ||
if (null == expected) { | ||
assertNull(actual, assertContext.getText("Actual read or write should not exist.")); | ||
return; | ||
} | ||
assertThat(actual.getWorkerThread(), is(expected.getWorkerThread())); | ||
assertThat(actual.getBatchSize(), is(expected.getBatchSize())); | ||
assertThat(actual.getShardingSize(), is(expected.getShardingSize())); | ||
assertThat(actual.getRateLimiter().getName(), is(expected.getRateLimiter().getName())); | ||
} | ||
|
||
private static void assertWrite(final SQLCaseAssertContext assertContext, final ReadOrWriteSegment actual, final ExpectedWrite expected) { | ||
if (null == expected) { | ||
assertNull(actual, assertContext.getText("Actual read or write should not exist.")); | ||
return; | ||
} | ||
assertThat(actual.getWorkerThread(), is(expected.getWorkerThread())); | ||
assertThat(actual.getBatchSize(), is(expected.getBatchSize())); | ||
assertThat(actual.getRateLimiter().getName(), is(expected.getRateLimiter().getName())); | ||
} | ||
|
||
private static void assertTypeStrategy(final SQLCaseAssertContext assertContext, final AlgorithmSegment actual, final ExpectedAlgorithm expected) { | ||
if (null == expected) { | ||
assertNull(actual, assertContext.getText("Actual strategy should not exist.")); | ||
} else { | ||
assertNotNull(actual, assertContext.getText("Actual strategy should exist.")); | ||
assertThat(assertContext.getText("Type assertion error"), actual.getName(), is(expected.getName())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...nal/cases/parser/domain/statement/ral/AlterInventoryIncrementalRuleStatementTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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.test.it.sql.parser.internal.cases.parser.domain.statement.ral; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase; | ||
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.distsql.ral.ExpectedInventoryIncrementalRule; | ||
|
||
import javax.xml.bind.annotation.XmlAccessType; | ||
import javax.xml.bind.annotation.XmlAccessorType; | ||
import javax.xml.bind.annotation.XmlElement; | ||
|
||
/** | ||
* Alter inventory incremental rule statement test case. | ||
*/ | ||
@Getter | ||
@Setter | ||
@XmlAccessorType(XmlAccessType.FIELD) | ||
public final class AlterInventoryIncrementalRuleStatementTestCase extends SQLParserTestCase { | ||
|
||
@XmlElement(name = "job-type-name") | ||
private String jobTypeName; | ||
|
||
@XmlElement(name = "rule") | ||
private ExpectedInventoryIncrementalRule rule; | ||
} |
Oops, something went wrong.