forked from apache/paimon
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flink] Introduce Query Service (apache#2709)
- Loading branch information
1 parent
996eda6
commit 37683e6
Showing
15 changed files
with
698 additions
and
26 deletions.
There are no files selected for viewing
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
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
70 changes: 70 additions & 0 deletions
70
...-flink-common/src/main/java/org/apache/paimon/flink/action/QueryServiceActionFactory.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,70 @@ | ||
/* | ||
* 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.paimon.flink.action; | ||
|
||
import org.apache.paimon.flink.service.QueryService; | ||
|
||
import org.apache.flink.api.java.tuple.Tuple3; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
/** Factory to create QueryService Action. */ | ||
public class QueryServiceActionFactory implements ActionFactory { | ||
|
||
public static final String IDENTIFIER = "query_service"; | ||
|
||
public static final String PARALLELISM = "parallelism"; | ||
|
||
@Override | ||
public String identifier() { | ||
return IDENTIFIER; | ||
} | ||
|
||
@Override | ||
public Optional<Action> create(MultipleParameterToolAdapter params) { | ||
Tuple3<String, String, String> tablePath = getTablePath(params); | ||
Map<String, String> catalogConfig = optionalConfigMap(params, CATALOG_CONF); | ||
Map<String, String> tableConfig = optionalConfigMap(params, TABLE_CONF); | ||
String parallStr = params.get(PARALLELISM); | ||
int parallelism = parallStr == null ? 1 : Integer.parseInt(parallStr); | ||
Action action = | ||
new TableActionBase(tablePath.f0, tablePath.f1, tablePath.f2, catalogConfig) { | ||
@Override | ||
public void run() throws Exception { | ||
QueryService.build(env, table.copy(tableConfig), parallelism); | ||
execute("Query Service job"); | ||
} | ||
}; | ||
return Optional.of(action); | ||
} | ||
|
||
@Override | ||
public void printHelp() { | ||
System.out.println( | ||
"Action \"query-service\" runs a dedicated job starting query service for a table."); | ||
System.out.println(); | ||
|
||
System.out.println("Syntax:"); | ||
System.out.println( | ||
" query-service --warehouse <warehouse-path> --database <database-name> --table <table-name> --parallelism <parallelism>" | ||
+ "[--catalog_conf <key>=<value> [--catalog_conf <key>=<value> ...]] " | ||
+ "[--table_conf <key>=<value> [--table_conf <key>=<value> ...]] "); | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
...n-flink-common/src/main/java/org/apache/paimon/flink/procedure/QueryServiceProcedure.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,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.paimon.flink.procedure; | ||
|
||
import org.apache.paimon.catalog.Identifier; | ||
import org.apache.paimon.flink.service.QueryService; | ||
import org.apache.paimon.table.Table; | ||
|
||
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; | ||
import org.apache.flink.table.procedure.ProcedureContext; | ||
|
||
/** | ||
* Query Service procedure. Usage: | ||
* | ||
* <pre><code> | ||
* CALL sys.query_service('tableId', 'parallelism') | ||
* </code></pre> | ||
*/ | ||
public class QueryServiceProcedure extends ProcedureBase { | ||
|
||
public static final String IDENTIFIER = "query_service"; | ||
|
||
@Override | ||
public String identifier() { | ||
return IDENTIFIER; | ||
} | ||
|
||
public String[] call(ProcedureContext procedureContext, String tableId, int parallelism) | ||
throws Exception { | ||
Table table = catalog.getTable(Identifier.fromString(tableId)); | ||
StreamExecutionEnvironment env = procedureContext.getExecutionEnvironment(); | ||
QueryService.build(env, table, parallelism); | ||
return execute(env, IDENTIFIER); | ||
} | ||
} |
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
76 changes: 76 additions & 0 deletions
76
...imon-flink-common/src/main/java/org/apache/paimon/flink/service/QueryAddressRegister.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,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.paimon.flink.service; | ||
|
||
import org.apache.paimon.data.InternalRow; | ||
import org.apache.paimon.service.ServiceManager; | ||
import org.apache.paimon.table.FileStoreTable; | ||
import org.apache.paimon.table.Table; | ||
|
||
import org.apache.flink.configuration.Configuration; | ||
import org.apache.flink.streaming.api.functions.sink.RichSinkFunction; | ||
import org.apache.flink.streaming.api.functions.sink.SinkFunction; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.util.TreeMap; | ||
|
||
import static org.apache.paimon.service.ServiceManager.PRIMARY_KEY_LOOKUP; | ||
|
||
/** Operator for address server to register addresses to {@link ServiceManager}. */ | ||
public class QueryAddressRegister extends RichSinkFunction<InternalRow> { | ||
|
||
private final Table table; | ||
|
||
private transient int numberExecutors; | ||
private transient TreeMap<Integer, InetSocketAddress> executors; | ||
|
||
public QueryAddressRegister(Table table) { | ||
this.table = table; | ||
} | ||
|
||
@Override | ||
public void open(Configuration parameters) throws Exception { | ||
this.executors = new TreeMap<>(); | ||
} | ||
|
||
@Override | ||
public void invoke(InternalRow row, SinkFunction.Context context) { | ||
int numberExecutors = row.getInt(0); | ||
if (this.numberExecutors != 0 && this.numberExecutors != numberExecutors) { | ||
throw new IllegalArgumentException( | ||
String.format( | ||
"Number Executors can not be changed! Old %s , New %s .", | ||
this.numberExecutors, numberExecutors)); | ||
} | ||
this.numberExecutors = numberExecutors; | ||
|
||
int executorId = row.getInt(1); | ||
String hostname = row.getString(2).toString(); | ||
int port = row.getInt(3); | ||
|
||
executors.put(executorId, new InetSocketAddress(hostname, port)); | ||
|
||
if (executors.size() == numberExecutors) { | ||
FileStoreTable storeTable = (FileStoreTable) table; | ||
ServiceManager manager = storeTable.store().newServiceManager(); | ||
manager.resetService( | ||
PRIMARY_KEY_LOOKUP, executors.values().toArray(new InetSocketAddress[0])); | ||
} | ||
} | ||
} |
Oops, something went wrong.