new-spider-HM / spider.py
HusnaManakkot's picture
Update spider.py
a56e568 verified
import pandas as pd
from datasets import Dataset
# Step 1: Read the Parquet files
train_df = pd.read_parquet('train-00000-of-00001.parquet')
validation_df = pd.read_parquet('validation-00000-of-00001.parquet')
# Step 2: Add the new row to the training DataFrame
new_example = {
'db_id': 'hr_1', # Replace with the actual database ID
'query': "SELECT COUNT(*) FROM employees WHERE department = 'Sales' AND salary > 50000;",
'question': 'How many employees in the Sales department have a salary greater than $50,000?',
'query_toks': ['SELECT', 'COUNT', '(', '*', ')', 'FROM', 'employees', 'WHERE', 'department', '=', "'Sales'", 'AND', 'salary', '>', '50000', ';'],
'query_toks_no_value': ['SELECT', 'COUNT', '(', '*', ')', 'FROM', 'employees', 'WHERE', 'department', '=', 'VALUE', 'AND', 'salary', '>', 'VALUE', ';'],
'question_toks': ['How', 'many', 'employees', 'in', 'the', 'Sales', 'department', 'have', 'a', 'salary', 'greater', 'than', '$50,000', '?'],
'sql': {
'select': [(0, [(3, (0, '*'))])], # (agg_id, val_unit), agg_id for COUNT is 0, val_unit is (column_id, column_name)
'from': {'table_units': [('table_unit', 0)], 'conds': []}, # ('table_unit', table_id), assuming 'employees' is the first table
'where': [(0, False, [(2, (0, 'department')), '=', (1, "'Sales'")]), 'AND', (0, False, [(2, (0, 'salary')), '>', (1, '50000')])],
'groupBy': [],
'having': [],
'orderBy': [],
'limit': None,
'intersect': None,
'union': None,
'except': None
}
}
train_df = train_df.append(new_example, ignore_index=True)
# Step 3: Write the modified DataFrame back to Parquet
train_df.to_parquet('train-00000-of-00001.parquet')