@@ -840,17 +840,27 @@ def to_gbq(dataframe, destination_table, project_id, chunksize=10000,
840
840
"already exists. "
841
841
"Change the if_exists parameter to "
842
842
"append or replace data." )
843
- elif if_exists == 'replace' :
844
- connector .delete_and_recreate_table (
845
- dataset_id , table_id , table_schema )
846
- elif if_exists == 'append' :
843
+ else :
844
+ delay = 0
847
845
if not connector .verify_schema (dataset_id , table_id , table_schema ):
848
- raise InvalidSchema ("Please verify that the structure and "
849
- "data types in the DataFrame match the "
850
- "schema of the destination table." )
846
+ if if_exists == 'append' or table .partition_decorator in table_id :
847
+ raise InvalidSchema ("Please verify that the structure and "
848
+ "data types in the DataFrame match the "
849
+ "schema of the destination table." )
850
+ elif if_exists == 'replace' :
851
+ table ._print ('The existing table has a different schema. Please '
852
+ 'wait 2 minutes. See Google BigQuery issue #191' )
853
+ delay = 120
854
+ if if_exists == 'replace' :
855
+ table .delete (table_id )
856
+ if table .partition_decorator not in table_id :
857
+ table .create (table_id , table_schema )
858
+ sleep (delay )
859
+
851
860
else :
861
+ if table .partition_decorator in table_id :
862
+ raise TableCreationError ("Cannot create a partition without the main table." )
852
863
table .create (table_id , table_schema )
853
-
854
864
connector .load_data (dataframe , dataset_id , table_id , chunksize )
855
865
856
866
@@ -893,6 +903,8 @@ def _generate_bq_schema(df, default_type='STRING'):
893
903
894
904
class _Table (GbqConnector ):
895
905
906
+ partition_decorator = '$'
907
+
896
908
def __init__ (self , project_id , dataset_id , reauth = False , verbose = False ,
897
909
private_key = None ):
898
910
try :
0 commit comments