'BCP python library load function not working
I need to load a huge pandas dataset into a ms sql server. Unfortunately the to_sql() method works very slowly even with 'multi' method . This is why I opted for a bulk copy method using the bcp library . Here is what I tried :
import bcp
conn = bcp.Connection(host='HOST', driver='mssql')
my_bcp = bcp.BCP(conn)
table_name = 'test17'
csv_filename= r'c:\temp\%s.csv' % table_name
df.to_csv(csv_filename, index=False, header=False, sep=';')
file = bcp.DataFile(file_path=csv_filename, delimiter=';')
my_bcp.load(input_file=file, table='QUANT_work..test17')
Here is the error :
AttributeError Traceback (most recent call last)
C:\Users\ABENHA~1\AppData\Local\Temp/ipykernel_5112/883077605.py in <module>
----> 1 my_bcp.load(input_file=file, table='QUANT_work..test17')
C:\Apps\Anaconda3\lib\site-packages\bcp\core.py in load(self, input_file, table)
58 else:
59 raise DriverNotSupportedException
---> 60 load.execute()
61
62 def dump(self, query: str, output_file: 'DataFile'):
C:\Apps\Anaconda3\lib\site-packages\bcp\dialects\mssql.py in execute(self)
80 This will run the instance's command via the BCP utility
81 """
---> 82 subprocess.run(f'bcp {self.command}', check=True)
83
84 @property
C:\Apps\Anaconda3\lib\site-packages\bcp\dialects\mssql.py in command(self)
90 the command that will be passed into the BCP command line utility
91 """
---> 92 return f'{self.table} in "{self.file.path}" {self.connection} {self.config} {self.logging} {self.error}'
93
94 @property
C:\Apps\Anaconda3\lib\site-packages\bcp\files.py in path(self)
54 @property
55 def path(self) -> Path:
---> 56 return self.file.absolute()
57
58
AttributeError: 'str' object has no attribute 'absolute'
Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
