feat: supports passing user params into coprocessor (#962)

* feat: make args in coprocessor optional

* feat: supports kwargs for coprocessor as params passed by the users

* feat: supports params for /run-script

* fix: we should rewrite the coprocessor by removing kwargs

* fix: remove println

* fix: compile error after rebasing

* fix: improve http_handler_test

* test: http scripts api with user params

* refactor: tweak all to_owned
This commit is contained in:
dennis zhuang
2023-02-16 16:11:26 +08:00
committed by GitHub
parent ddbc97befb
commit 5ec1a7027b
19 changed files with 564 additions and 142 deletions

View File

@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::collections::HashMap;
use async_trait::async_trait;
use common_query::Output;
use common_telemetry::timer;
@@ -34,8 +36,15 @@ impl ScriptHandler for Instance {
.await
}
async fn execute_script(&self, schema: &str, name: &str) -> servers::error::Result<Output> {
async fn execute_script(
&self,
schema: &str,
name: &str,
params: HashMap<String, String>,
) -> servers::error::Result<Output> {
let _timer = timer!(metric::METRIC_RUN_SCRIPT_ELAPSED);
self.script_executor.execute_script(schema, name).await
self.script_executor
.execute_script(schema, name, params)
.await
}
}

View File

@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::collections::HashMap;
use catalog::CatalogManagerRef;
use common_query::Output;
use query::QueryEngineRef;
@@ -34,13 +36,19 @@ mod dummy {
pub async fn insert_script(
&self,
_schema: &str,
_name: &str,
_script: &str,
) -> servers::error::Result<()> {
servers::error::NotSupportedSnafu { feat: "script" }.fail()
}
pub async fn execute_script(&self, _script: &str) -> servers::error::Result<Output> {
pub async fn execute_script(
&self,
_schema: &str,
_name: &str,
_params: HashMap<String, String>,
) -> servers::error::Result<Output> {
servers::error::NotSupportedSnafu { feat: "script" }.fail()
}
}
@@ -94,9 +102,10 @@ mod python {
&self,
schema: &str,
name: &str,
params: HashMap<String, String>,
) -> servers::error::Result<Output> {
self.script_manager
.execute(schema, name)
.execute(schema, name, params)
.await
.map_err(|e| {
error!(e; "Instance failed to execute script");