Skip to content

Commit 771337e

Browse files
committed
add implementation of streaming into a partition of a date-partitioned table
1 parent cec8c86 commit 771337e

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

pandas_gbq/gbq.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -840,17 +840,27 @@ def to_gbq(dataframe, destination_table, project_id, chunksize=10000,
840840
"already exists. "
841841
"Change the if_exists parameter to "
842842
"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
847845
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+
851860
else:
861+
if table.partition_decorator in table_id:
862+
raise TableCreationError("Cannot create a partition without the main table.")
852863
table.create(table_id, table_schema)
853-
854864
connector.load_data(dataframe, dataset_id, table_id, chunksize)
855865

856866

@@ -893,6 +903,8 @@ def _generate_bq_schema(df, default_type='STRING'):
893903

894904
class _Table(GbqConnector):
895905

906+
partition_decorator = '$'
907+
896908
def __init__(self, project_id, dataset_id, reauth=False, verbose=False,
897909
private_key=None):
898910
try:

0 commit comments

Comments
 (0)