Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions influxdb3_processing_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ object_store.workspace = true
parquet_file.workspace = true
tempfile.workspace = true
test-log.workspace = true
influxdb3_id = { path = "../influxdb3_id" }

[lints]
workspace = true
41 changes: 40 additions & 1 deletion influxdb3_processing_engine/src/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,8 +1077,10 @@ pub(crate) fn run_test_schedule_plugin(
mod tests {
use super::*;
use crate::virtualenv::init_pyo3;
use chrono::{TimeZone, Utc};
use hashbrown::HashMap;
use influxdb3_catalog::catalog::Catalog;
use influxdb3_catalog::catalog::{Catalog, DatabaseSchema};
use influxdb3_id::DbId;
use influxdb3_internal_api::query_executor::UnimplementedQueryExecutor;
use influxdb3_write::Precision;
use influxdb3_write::write_buffer::validator::WriteValidator;
Expand Down Expand Up @@ -1208,6 +1210,7 @@ def process_writes(influxdb3_local, table_batches, args=None):
.await
.unwrap(),
);
catalog.create_database("foo").await.unwrap();
let namespace = NamespaceName::new("foodb").unwrap();
let validator =
WriteValidator::initialize(namespace.clone(), Arc::clone(&catalog)).unwrap();
Expand Down Expand Up @@ -1288,4 +1291,40 @@ def process_writes(influxdb3_local, table_batches, args=None):
let expected_error = "line protocol parse error on write to db foodb: WriteLineError { original_line: \"cpu,host=A f1=not_an_int\", line_number: 2, error_message: \"invalid column type for column 'f1', expected iox::column_type::field::integer, got iox::column_type::field::string\" }";
assert_eq!(response.errors[0], expected_error);
}

#[tokio::test]
async fn test_schedule_plugin_py_api_surface_area() {
init_pyo3();

let code = r#"
def process_scheduled_call(influxdb3_local, call_time, args=None):
allowed = {"info", "warn", "error", "query", "write", "cache", "write_to_db"}
attrs = {name for name in dir(influxdb3_local) if not name.startswith("__")}
extras = attrs - allowed
missing = allowed - attrs
if extras or missing:
raise RuntimeError(f"unexpected attributes: extras={sorted(extras)}, missing={sorted(missing)}")
"#;

let cache = Arc::new(Mutex::new(CacheStore::new(
Arc::new(MockProvider::new(Time::from_timestamp_nanos(0))),
Duration::from_secs(10),
)));

let result = influxdb3_py_api::system_py::execute_schedule_trigger(
code,
Utc.timestamp_opt(0, 0).unwrap(),
Arc::new(DatabaseSchema::new(DbId::from(0), Arc::from("test_db"))),
Arc::new(UnimplementedQueryExecutor),
None,
&None::<HashMap<String, String>>,
PyCache::new_test_cache(cache, "_shared_test".to_string()),
None,
);

assert!(
result.is_ok(),
"PyPluginCallApi exposes unexpected Python methods: {result:?}"
);
}
}
18 changes: 9 additions & 9 deletions influxdb3_py_api/src/system_py.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,6 @@ impl PyPluginCallApi {
Ok(())
}

fn log_args_to_string(&self, args: &Bound<'_, PyTuple>) -> PyResult<String> {
let line = args
.try_iter()?
.map(|arg| arg?.str()?.extract::<String>())
.collect::<Result<Vec<String>, _>>()?
.join(" ");
Ok(line)
}

fn write(&self, line_builder: &Bound<'_, PyAny>) -> PyResult<()> {
// Get the built line from the LineBuilder object
let line = line_builder.getattr("build")?.call0()?;
Expand Down Expand Up @@ -322,6 +313,15 @@ impl PyPluginCallApi {
logger.log(level, log_line);
}
}

fn log_args_to_string(&self, args: &Bound<'_, PyTuple>) -> PyResult<String> {
let line = args
.try_iter()?
.map(|arg| arg?.str()?.extract::<String>())
.collect::<Result<Vec<String>, _>>()?
.join(" ");
Ok(line)
}
}

// constant for the process writes call site string
Expand Down