|
70 | 70 |
|
71 | 71 | TABLE_VALUED_ALIAS_ALIASES = "bigquery_table_valued_alias_aliases" |
72 | 72 |
|
| 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 | + |
73 | 100 |
|
74 | 101 | def assert_(cond, message="Assertion failed"): # pragma: NO COVER |
75 | 102 | if not cond: |
@@ -844,48 +871,21 @@ def _process_time_partitioning( |
844 | 871 | * DATE column |
845 | 872 | """ |
846 | 873 |
|
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 | | - |
874 | 874 | def parse_sqltypes(coltype, partitioning_period): |
875 | 875 | """Returns the default value OR the truncation function to be used |
876 | 876 | and the allowed partitioning periods. |
877 | 877 | """ |
878 | 878 |
|
879 | 879 | if coltype in {"_PARTITIONDATE", "_PARTITIONTIME"}: |
880 | | - return sqltypes[coltype] |
| 880 | + return SQLTYPES[coltype] |
881 | 881 |
|
882 | 882 | # by this point, value must be a nested dict |
883 | 883 | if partitioning_period is None: |
884 | 884 | # use "no_period" key |
885 | | - return sqltypes[coltype]["no_period"] |
| 885 | + return SQLTYPES[coltype]["no_period"] |
886 | 886 | else: |
887 | 887 | # use "period" key |
888 | | - return sqltypes[coltype]["period"] |
| 888 | + return SQLTYPES[coltype]["period"] |
889 | 889 |
|
890 | 890 | # Extract field (i.e <column_name> or _PARTITIONDATE) |
891 | 891 | # AND extract the name of the column_type (i.e. "TIMESTAMP", "DATE", |
|
0 commit comments