| 1092 | signature = (data, src, dst, metadata = None, shared_metadata = None, layer = None, layer_col = None, schema = None, csv_options = None) |
| 1093 | )] |
| 1094 | fn load_edge_metadata( |
| 1095 | &self, |
| 1096 | data: &Bound<PyAny>, |
| 1097 | src: &str, |
| 1098 | dst: &str, |
| 1099 | metadata: Option<Vec<PyBackedStr>>, |
| 1100 | shared_metadata: Option<HashMap<String, Prop>>, |
| 1101 | layer: Option<&str>, |
| 1102 | layer_col: Option<&str>, |
| 1103 | schema: Option<Bound<PyAny>>, |
| 1104 | csv_options: Option<CsvReadOptions>, |
| 1105 | ) -> Result<(), GraphError> { |
| 1106 | let metadata = convert_py_prop_args(metadata.as_deref()).unwrap_or_default(); |
| 1107 | let column_schema = convert_py_schema(schema)?; |
| 1108 | if data.hasattr("__arrow_c_stream__")? { |
| 1109 | load_edge_metadata_from_arrow_c_stream( |
| 1110 | &self.graph, |
| 1111 | data, |
| 1112 | src, |
| 1113 | dst, |
| 1114 | &metadata, |
| 1115 | shared_metadata.as_ref(), |
| 1116 | layer, |
| 1117 | layer_col, |
| 1118 | column_schema, |
| 1119 | ) |
| 1120 | } else if let Ok(path) = data.extract::<PathBuf>() { |
| 1121 | // extracting PathBuf handles Strings too |
| 1122 | let is_parquet = is_parquet_path(&path)?; |
| 1123 | let is_csv = is_csv_path(&path)?; |
| 1124 | |
| 1125 | // fail before loading anything at all to avoid loading partial data |
| 1126 | if !is_csv && csv_options.is_some() { |
| 1127 | return Err(GraphError::from(PyValueError::new_err(format!( |
| 1128 | "CSV options were passed but no CSV files were detected at {}.", |
| 1129 | path.display() |
| 1130 | )))); |
| 1131 | } |
| 1132 | |
| 1133 | // wrap in Arc to avoid cloning the entire schema for Parquet, CSV, and inner loops in CSV path |
| 1134 | let arced_schema = column_schema.map(Arc::new); |
| 1135 | |
| 1136 | // if-if instead of if-else to support directories with mixed parquet and CSV files |
| 1137 | if is_parquet { |
| 1138 | load_edge_metadata_from_parquet( |
| 1139 | &self.graph, |
| 1140 | path.as_path(), |
| 1141 | src, |
| 1142 | dst, |
| 1143 | &metadata, |
| 1144 | shared_metadata.as_ref(), |
| 1145 | layer, |
| 1146 | layer_col, |
| 1147 | None, |
| 1148 | arced_schema.clone(), |
| 1149 | true, |
| 1150 | )?; |
| 1151 | } |