Skip to content

Commit 1be1eb7

Browse files
tcyameterstick-copybara
authored andcommitted
Add options to control if a sql dialect supports FULL JOIN.
PiperOrigin-RevId: 785965825
1 parent 9c36151 commit 1be1eb7

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

sql.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
# run_only_once_in_with_clause() returns False.
3333
NEED_TEMP_TABLE = None
3434
CREATE_TEMP_TABLE_FN = None
35+
SUPPORT_FULL_JOIN = None
3536
# ORDER BY is required for ROW_NUMBER() in some dialects.
3637
ROW_NUMBER_REQUIRE_ORDER_BY = None
3738
GROUP_BY_FN = None
@@ -371,6 +372,11 @@ def duplicate_data_n_times_not_implemented(n, alias: Optional[str] = None):
371372
'Oracle': create_temp_table_fn_not_implemented,
372373
'SQL Server': 'SELECT * INTO #{alias} FROM ({query});'.format,
373374
}
375+
SUPPORT_FULL_JOIN_OPTIONS = {
376+
'Default': True,
377+
'MariaDB': False,
378+
'SQLite': False,
379+
}
374380
ROW_NUMBER_REQUIRE_ORDER_BY_OPTIONS = {
375381
'Default': False,
376382
'Oracle': True,
@@ -511,10 +517,11 @@ def set_dialect(dialect: str):
511517
"""Sets the dialect of the SQL query."""
512518
# You can manually override the options below. You can manually test it in
513519
# https://colab.research.google.com/drive/1y3UigzEby1anMM3-vXocBx7V8LVblIAp?usp=sharing.
514-
global DIALECT, NEED_TEMP_TABLE, CREATE_TEMP_TABLE_FN, ROW_NUMBER_REQUIRE_ORDER_BY, GROUP_BY_FN, RAND_FN, CEIL_FN, SAFE_DIVIDE_FN, QUANTILE_FN, ARRAY_AGG_FN, ARRAY_INDEX_FN, NTH_VALUE_FN, COUNTIF_FN, STRING_CAST_FN, FLOAT_CAST_FN, UNIFORM_MAPPING_FN, UNNEST_ARRAY_FN, UNNEST_ARRAY_LITERAL_FN, GENERATE_ARRAY_FN, DUPLICATE_DATA_N_TIMES_FN
520+
global DIALECT, NEED_TEMP_TABLE, CREATE_TEMP_TABLE_FN, SUPPORT_FULL_JOIN, ROW_NUMBER_REQUIRE_ORDER_BY, GROUP_BY_FN, RAND_FN, CEIL_FN, SAFE_DIVIDE_FN, QUANTILE_FN, ARRAY_AGG_FN, ARRAY_INDEX_FN, NTH_VALUE_FN, COUNTIF_FN, STRING_CAST_FN, FLOAT_CAST_FN, UNIFORM_MAPPING_FN, UNNEST_ARRAY_FN, UNNEST_ARRAY_LITERAL_FN, GENERATE_ARRAY_FN, DUPLICATE_DATA_N_TIMES_FN
515521
DIALECT = dialect
516522
NEED_TEMP_TABLE = _get_dialect_option(NEED_TEMP_TABLE_OPTIONS)
517523
CREATE_TEMP_TABLE_FN = _get_dialect_option(CREATE_TEMP_TABLE_OPTIONS)
524+
SUPPORT_FULL_JOIN = _get_dialect_option(SUPPORT_FULL_JOIN_OPTIONS)
518525
ROW_NUMBER_REQUIRE_ORDER_BY = _get_dialect_option(
519526
ROW_NUMBER_REQUIRE_ORDER_BY_OPTIONS
520527
)
@@ -1151,8 +1158,8 @@ def __init__(self,
11511158
if join.upper() not in ('', 'INNER', 'FULL', 'FULL OUTER', 'LEFT',
11521159
'LEFT OUTER', 'RIGHT', 'RIGHT OUTER', 'CROSS'):
11531160
raise ValueError('Unrecognized JOIN type!')
1154-
if 'FULL' in join.upper() and DIALECT == 'MariaDB':
1155-
raise NotImplementedError('FULL JOIN is not supported in MariaDB.')
1161+
if 'FULL' in join.upper() and not SUPPORT_FULL_JOIN:
1162+
raise NotImplementedError(f'FULL JOIN is not supported in {DIALECT}.')
11561163
self.ds1 = Datasource(datasource1)
11571164
self.ds2 = Datasource(datasource2)
11581165
self.join_type = join.upper()

0 commit comments

Comments
 (0)