| 988 | signature = (data, id, node_type = None, node_type_col = None, metadata = None, shared_metadata = None, schema = None, csv_options = None) |
| 989 | )] |
| 990 | fn load_node_metadata( |
| 991 | &self, |
| 992 | data: &Bound<PyAny>, |
| 993 | id: &str, |
| 994 | node_type: Option<&str>, |
| 995 | node_type_col: Option<&str>, |
| 996 | metadata: Option<Vec<PyBackedStr>>, |
| 997 | shared_metadata: Option<HashMap<String, Prop>>, |
| 998 | schema: Option<Bound<PyAny>>, |
| 999 | csv_options: Option<CsvReadOptions>, |
| 1000 | ) -> Result<(), GraphError> { |
| 1001 | let metadata = convert_py_prop_args(metadata.as_deref()).unwrap_or_default(); |
| 1002 | let column_schema = convert_py_schema(schema)?; |
| 1003 | if data.hasattr("__arrow_c_stream__")? { |
| 1004 | load_node_metadata_from_arrow_c_stream( |
| 1005 | &self.graph, |
| 1006 | data, |
| 1007 | id, |
| 1008 | node_type, |
| 1009 | node_type_col, |
| 1010 | &metadata, |
| 1011 | shared_metadata.as_ref(), |
| 1012 | column_schema, |
| 1013 | ) |
| 1014 | } else if let Ok(path) = data.extract::<PathBuf>() { |
| 1015 | // extracting PathBuf handles Strings too |
| 1016 | let is_parquet = is_parquet_path(&path)?; |
| 1017 | let is_csv = is_csv_path(&path)?; |
| 1018 | |
| 1019 | // fail before loading anything at all to avoid loading partial data |
| 1020 | if !is_csv && csv_options.is_some() { |
| 1021 | return Err(GraphError::from(PyValueError::new_err(format!( |
| 1022 | "CSV options were passed but no CSV files were detected at {}.", |
| 1023 | path.display() |
| 1024 | )))); |
| 1025 | } |
| 1026 | |
| 1027 | // wrap in Arc to avoid cloning the entire schema for Parquet, CSV, and inner loops in CSV path |
| 1028 | let arced_schema = column_schema.map(Arc::new); |
| 1029 | |
| 1030 | // if-if instead of if-else to support directories with mixed parquet and CSV files |
| 1031 | if is_parquet { |
| 1032 | load_node_metadata_from_parquet( |
| 1033 | &self.graph, |
| 1034 | path.as_path(), |
| 1035 | id, |
| 1036 | node_type, |
| 1037 | node_type_col, |
| 1038 | None, |
| 1039 | None, |
| 1040 | &metadata, |
| 1041 | shared_metadata.as_ref(), |
| 1042 | None, |
| 1043 | None, |
| 1044 | None, |
| 1045 | arced_schema.clone(), |
| 1046 | )?; |
| 1047 | } |