@@ -699,7 +699,7 @@ 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
- if _Table . partition_decorator not in table_id :
702
+ if not _Table . is_date_partitioned ( table_id ) :
703
703
table .create (table_id , table_schema )
704
704
sleep (delay )
705
705
@@ -1010,6 +1010,9 @@ class _Table(GbqConnector):
1010
1010
1011
1011
partition_decorator = '$'
1012
1012
1013
+ def is_date_partitioned (self , table_id ):
1014
+ return self .partition_decorator in table_id
1015
+
1013
1016
def __init__ (self , project_id , dataset_id , reauth = False , verbose = False ,
1014
1017
private_key = None ):
1015
1018
self .dataset_id = dataset_id
@@ -1031,8 +1034,12 @@ def exists(self, table_id):
1031
1034
from google .api_core .exceptions import NotFound
1032
1035
1033
1036
table_ref = self .client .dataset (self .dataset_id ).table (table_id )
1037
+
1034
1038
try :
1035
- self .client .get_table (table_ref )
1039
+ table = self .client .get_table (table_ref )
1040
+ if self .is_date_partitioned (table_id ):
1041
+ return table .num_rows > 0
1042
+
1036
1043
return True
1037
1044
except NotFound :
1038
1045
return False
@@ -1067,7 +1074,7 @@ def create(self, table_id, schema, date_partitioned=False):
1067
1074
table_ref = self .client .dataset (self .dataset_id ).table (table_id )
1068
1075
table = Table (table_ref )
1069
1076
1070
- if date_partitioned or '$' in table_id :
1077
+ if date_partitioned or self . is_date_partitioned ( table_id ) :
1071
1078
table .partitioning_type = 'DAY'
1072
1079
1073
1080
# Manually create the schema objects, adding NULLABLE mode
0 commit comments