@@ -699,8 +699,9 @@ def delete_and_recreate_table(self, dataset_id, table_id, table_schema):
699
699
table = _Table (self .project_id , dataset_id ,
700
700
private_key = self .private_key )
701
701
table .delete (table_id )
702
- table .create (table_id , table_schema )
703
- sleep (delay )
702
+ if _Table .partition_decorator not in table_id :
703
+ table .create (table_id , table_schema )
704
+ sleep (delay )
704
705
705
706
706
707
def _get_credentials_file ():
@@ -1007,6 +1008,8 @@ def _generate_bq_schema(df, default_type='STRING'):
1007
1008
1008
1009
class _Table (GbqConnector ):
1009
1010
1011
+ partition_decorator = '$'
1012
+
1010
1013
def __init__ (self , project_id , dataset_id , reauth = False , verbose = False ,
1011
1014
private_key = None ):
1012
1015
self .dataset_id = dataset_id
@@ -1036,7 +1039,7 @@ def exists(self, table_id):
1036
1039
except self .http_error as ex :
1037
1040
self .process_http_error (ex )
1038
1041
1039
- def create (self , table_id , schema ):
1042
+ def create (self , table_id , schema , date_partitioned = False ):
1040
1043
""" Create a table in Google BigQuery given a table and schema
1041
1044
1042
1045
Parameters
@@ -1046,6 +1049,8 @@ def create(self, table_id, schema):
1046
1049
schema : str
1047
1050
Use the generate_bq_schema to generate your table schema from a
1048
1051
dataframe.
1052
+ date_partitioned: boolean
1053
+ Whether table is to be created as a date partitioned table.
1049
1054
"""
1050
1055
from google .cloud .bigquery import SchemaField
1051
1056
from google .cloud .bigquery import Table
@@ -1062,6 +1067,9 @@ def create(self, table_id, schema):
1062
1067
table_ref = self .client .dataset (self .dataset_id ).table (table_id )
1063
1068
table = Table (table_ref )
1064
1069
1070
+ if date_partitioned or '$' in table_id :
1071
+ table .partitioning_type = 'DAY'
1072
+
1065
1073
# Manually create the schema objects, adding NULLABLE mode
1066
1074
# as a workaround for
1067
1075
# https://github.com/GoogleCloudPlatform/google-cloud-python/issues/4456
0 commit comments