Skip to content

Commit

Permalink
Replace ShowMigrationListResultSet with ShowMigrationListExecutor (
Browse files Browse the repository at this point in the history
  • Loading branch information
Qianyi951015 authored Feb 3, 2023
1 parent d972f30 commit 312c6e1
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

package org.apache.shardingsphere.distsql.parser.statement.ral.scaling;

import org.apache.shardingsphere.distsql.parser.statement.ral.ScalingRALStatement;
import org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatement;

/**
* Queryable RAL statement.
*/
public abstract class QueryableScalingRALStatement extends ScalingRALStatement {
public abstract class QueryableScalingRALStatement extends QueryableRALStatement {
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,36 @@

package org.apache.shardingsphere.migration.distsql.handler.query;

import org.apache.shardingsphere.data.pipeline.api.pojo.PipelineJobMetaData;
import org.apache.shardingsphere.data.pipeline.api.pojo.TableBasedPipelineJobInfo;
import org.apache.shardingsphere.data.pipeline.scenario.migration.api.impl.MigrationJobAPI;
import org.apache.shardingsphere.distsql.handler.resultset.DatabaseDistSQLResultSet;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.migration.distsql.statement.ShowMigrationListStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;

import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.stream.Collectors;

/**
* Result set for show migration list.
* Show migration list executor.
*/
public final class ShowMigrationListResultSet implements DatabaseDistSQLResultSet {
public final class ShowMigrationListExecutor implements QueryableRALExecutor<ShowMigrationListStatement> {

private final MigrationJobAPI jobAPI = new MigrationJobAPI();

private Iterator<Collection<Object>> data;

@Override
public void init(final ShardingSphereDatabase database, final SQLStatement sqlStatement) {
data = jobAPI.list().stream()
.map(each -> {
Collection<Object> result = new LinkedList<>();
PipelineJobMetaData jobMetaData = each.getJobMetaData();
result.add(jobMetaData.getJobId());
result.add(((TableBasedPipelineJobInfo) each).getTable());
result.add(jobMetaData.getJobItemCount());
result.add(jobMetaData.isActive() ? Boolean.TRUE.toString() : Boolean.FALSE.toString());
result.add(jobMetaData.getCreateTime());
result.add(jobMetaData.getStopTime());
return result;
}).collect(Collectors.toList()).iterator();
public Collection<LocalDataQueryResultRow> getRows(final ShowMigrationListStatement sqlStatement) {
return jobAPI.list().stream().map(each -> new LocalDataQueryResultRow(each.getJobMetaData().getJobId(),
((TableBasedPipelineJobInfo) each).getTable(), each.getJobMetaData().getJobItemCount(),
each.getJobMetaData().isActive() ? Boolean.TRUE.toString() : Boolean.FALSE.toString(),
each.getJobMetaData().getCreateTime(), each.getJobMetaData().getStopTime())).collect(Collectors.toList());
}

@Override
public Collection<String> getColumnNames() {
return Arrays.asList("id", "tables", "job_item_count", "active", "create_time", "stop_time");
}

@Override
public boolean next() {
return data.hasNext();
}

@Override
public Collection<Object> getRowData() {
return data.next();
}

@Override
public String getType() {
return ShowMigrationListStatement.class.getName();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# 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.
#

org.apache.shardingsphere.migration.distsql.handler.query.ShowMigrationListExecutor
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#

org.apache.shardingsphere.migration.distsql.handler.query.ShowMigrationCheckStatusResultSet
org.apache.shardingsphere.migration.distsql.handler.query.ShowMigrationListResultSet
org.apache.shardingsphere.migration.distsql.handler.query.ShowMigrationJobStatusResultSet
org.apache.shardingsphere.migration.distsql.handler.query.ShowMigrationCheckAlgorithmsResultSet
org.apache.shardingsphere.migration.distsql.handler.query.ShowMigrationSourceStorageUnitsResultSet
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.migration.distsql.handler.query;

import org.junit.Test;

import java.util.Collection;
import java.util.Iterator;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public final class ShowMigrationListExecutorTest {

@Test
public void assertGetColumnNames() {
ShowMigrationListExecutor executor = new ShowMigrationListExecutor();
Collection<String> columns = executor.getColumnNames();
assertThat(columns.size(), is(6));
Iterator<String> iterator = columns.iterator();
assertThat(iterator.next(), is("id"));
assertThat(iterator.next(), is("tables"));
assertThat(iterator.next(), is("job_item_count"));
assertThat(iterator.next(), is("active"));
assertThat(iterator.next(), is("create_time"));
assertThat(iterator.next(), is("stop_time"));
}
}

0 comments on commit 312c6e1

Please sign in to comment.