Skip to content

Commit 3b7239a

Browse files
committed
Moves SQLTYPES dict out of the function
1 parent 494b797 commit 3b7239a

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

sqlalchemy_bigquery/base.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,33 @@
7070

7171
TABLE_VALUED_ALIAS_ALIASES = "bigquery_table_valued_alias_aliases"
7272

73+
SQLTYPES = {
74+
# column_type | truncation func OR default value | partitioning_period(s)
75+
"_PARTITIONDATE": ("_PARTITIONDATE", None), # default value, no period
76+
"_PARTITIONTIME": ("DATE", None), # trunc_fn, no period
77+
"DATE": {
78+
"no_period": (None, None), # date_column, no trunc_fn, no period
79+
"period": (
80+
"DATE_TRUNC",
81+
{"MONTH", "YEAR"},
82+
), # date_column, trunc_fn, period(s)
83+
},
84+
"DATETIME": {
85+
"no_period": ("DATE", None), # datetime_column, trunc_fn, no period
86+
"period": (
87+
"DATETIME_TRUNC",
88+
{"DAY", "HOUR", "MONTH", "YEAR"},
89+
), # datetime_column, trunc_fn, period(s)
90+
},
91+
"TIMESTAMP": {
92+
"no_period": ("DATE", None), # timestamp_column, trunc_fn, no period
93+
"period": (
94+
"TIMESTAMP_TRUNC",
95+
{"DAY", "HOUR", "MONTH", "YEAR"},
96+
), # timestamp_column, trunc_fn, period(s)
97+
},
98+
}
99+
73100

74101
def assert_(cond, message="Assertion failed"): # pragma: NO COVER
75102
if not cond:
@@ -844,48 +871,21 @@ def _process_time_partitioning(
844871
* DATE column
845872
"""
846873

847-
sqltypes = {
848-
# column_type | truncation func OR default value | partitioning_period(s)
849-
"_PARTITIONDATE": ("_PARTITIONDATE", None), # default value, no period
850-
"_PARTITIONTIME": ("DATE", None), # trunc_fn, no period
851-
"DATE": {
852-
"no_period": (None, None), # date_column, no trunc_fn, no period
853-
"period": (
854-
"DATE_TRUNC",
855-
{"MONTH", "YEAR"},
856-
), # date_column, trunc_fn, period(s)
857-
},
858-
"DATETIME": {
859-
"no_period": ("DATE", None), # datetime_column, trunc_fn, no period
860-
"period": (
861-
"DATETIME_TRUNC",
862-
{"DAY", "HOUR", "MONTH", "YEAR"},
863-
), # datetime_column, trunc_fn, period(s)
864-
},
865-
"TIMESTAMP": {
866-
"no_period": ("DATE", None), # timestamp_column, trunc_fn, no period
867-
"period": (
868-
"TIMESTAMP_TRUNC",
869-
{"DAY", "HOUR", "MONTH", "YEAR"},
870-
), # timestamp_column, trunc_fn, period(s)
871-
},
872-
}
873-
874874
def parse_sqltypes(coltype, partitioning_period):
875875
"""Returns the default value OR the truncation function to be used
876876
and the allowed partitioning periods.
877877
"""
878878

879879
if coltype in {"_PARTITIONDATE", "_PARTITIONTIME"}:
880-
return sqltypes[coltype]
880+
return SQLTYPES[coltype]
881881

882882
# by this point, value must be a nested dict
883883
if partitioning_period is None:
884884
# use "no_period" key
885-
return sqltypes[coltype]["no_period"]
885+
return SQLTYPES[coltype]["no_period"]
886886
else:
887887
# use "period" key
888-
return sqltypes[coltype]["period"]
888+
return SQLTYPES[coltype]["period"]
889889

890890
# Extract field (i.e <column_name> or _PARTITIONDATE)
891891
# AND extract the name of the column_type (i.e. "TIMESTAMP", "DATE",

0 commit comments

Comments
 (0)