MCPcopy
hub / github.com/tanelpoder/0xtools / get_available_values

Method get_available_values

xtop/core/data_source.py:210–250  ·  view source on GitHub ↗

Get distinct values for a column with optional filters. Useful for drill-down suggestions.

(self, column: str, csv_type: str = 'samples', 
                           where_clause: str = "1=1", limit: int = 100)

Source from the content-addressed store, hash-verified

208 return validated
209
210 def get_available_values(self, column: str, csv_type: str = 'samples',
211 where_clause: str = "1=1", limit: int = 100) -> List[Any]:
212 """
213 Get distinct values for a column with optional filters.
214 Useful for drill-down suggestions.
215 """
216 conn = self.connect()
217
218 # Get the CSV pattern
219 patterns = {
220 'samples': 'xcapture_samples_*.csv',
221 'syscend': 'xcapture_syscend_*.csv',
222 'iorqend': 'xcapture_iorqend_*.csv',
223 'kstacks': 'xcapture_kstacks_*.csv',
224 'ustacks': 'xcapture_ustacks_*.csv'
225 }
226
227 pattern = patterns.get(csv_type, 'xcapture_samples_*.csv')
228 csv_path = str(self.datadir / pattern)
229
230 # Validate column name
231 validated_cols = self.validate_columns([column], csv_type)
232 if validated_cols:
233 column = validated_cols[0]
234
235 try:
236 query = f"""
237 SELECT DISTINCT {column} as value, COUNT(*) as count
238 FROM read_csv_auto('{csv_path}')
239 WHERE ({where_clause})
240 AND {column} IS NOT NULL
241 GROUP BY {column}
242 ORDER BY count DESC
243 LIMIT {limit}
244 """
245
246 result = conn.execute(query).fetchall()
247 return [row[0] for row in result]
248 except Exception as e:
249 print(f"Error getting values for {column}: {e}", file=sys.stderr)
250 return []
251
252 def get_partitions_info(self) -> Dict[str, str]:
253 """

Callers

nothing calls this directly

Calls 4

connectMethod · 0.95
validate_columnsMethod · 0.95
fetchallMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected