Execute DISTINCT operation to remove duplicate rows
(&self, input_rows: Vec<Row>)
| 6786 | |
| 6787 | /// Execute DISTINCT operation to remove duplicate rows |
| 6788 | fn execute_distinct(&self, input_rows: Vec<Row>) -> Result<Vec<Row>, ExecutionError> { |
| 6789 | use std::collections::HashSet; |
| 6790 | |
| 6791 | let mut seen_rows = HashSet::new(); |
| 6792 | let mut unique_rows = Vec::new(); |
| 6793 | |
| 6794 | for row in input_rows { |
| 6795 | // Create a unique key from all column values in the row |
| 6796 | let mut row_key = String::new(); |
| 6797 | |
| 6798 | // Sort the keys to ensure consistent ordering for comparison |
| 6799 | let mut sorted_keys: Vec<_> = row.values.keys().collect(); |
| 6800 | sorted_keys.sort(); |
| 6801 | |
| 6802 | for key in sorted_keys { |
| 6803 | if let Some(value) = row.values.get(key) { |
| 6804 | // Append key and value to create unique row signature |
| 6805 | row_key.push_str(key); |
| 6806 | row_key.push(':'); |
| 6807 | row_key.push_str(&format!("{:?}", value)); |
| 6808 | row_key.push('|'); |
| 6809 | } |
| 6810 | } |
| 6811 | |
| 6812 | // Only include row if we haven't seen this exact combination before |
| 6813 | if seen_rows.insert(row_key) { |
| 6814 | unique_rows.push(row); |
| 6815 | } |
| 6816 | } |
| 6817 | |
| 6818 | Ok(unique_rows) |
| 6819 | } |
| 6820 | |
| 6821 | /// Execute a session statement - validates resources and returns session change request |
| 6822 | /// Following PostgreSQL/Oracle pattern: executor validates, pipeline handles session updates |
no test coverage detected