File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -154,7 +154,7 @@ def ordering_clause(
154154 # Probably shouldn't have constants in ordering definition, but best to ignore if somehow they end up here.
155155 continue
156156 assert isinstance (ordering_expr , bigframes .core .expression .DerefOp )
157- part = f"`{ ordering_expr .id .sql } ` { asc_desc } { null_clause } "
157+ part = f"`{ escape_chars ( ordering_expr .id .sql ) } ` { asc_desc } { null_clause } "
158158 parts .append (part )
159159 return f"ORDER BY { ' ,' .join (parts )} "
160160
Original file line number Diff line number Diff line change 1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ import bigframes .core .expression as ex
16+ import bigframes .core .identifiers as ids
17+ import bigframes .core .ordering as order
1518from bigframes .core import sql
1619
1720
21+ def test_ordering_clause_escapes_backtick_in_column_name ():
22+ ordering = order .OrderingExpression (ex .DerefOp (ids .ColumnId ("col`,(SELECT 1))--" )))
23+ result = sql .ordering_clause ([ordering ])
24+ assert result == "ORDER BY `col\\ `,(SELECT 1))--` ASC NULLS LAST"
25+
26+
27+ def test_ordering_clause_leaves_plain_column_name_unchanged ():
28+ ordering = order .OrderingExpression (ex .DerefOp (ids .ColumnId ("my_col" )))
29+ result = sql .ordering_clause ([ordering ])
30+ assert result == "ORDER BY `my_col` ASC NULLS LAST"
31+
32+
1833def test_create_vector_search_sql_simple ():
1934 result_query = sql .create_vector_search_sql (
2035 sql_string = "SELECT embedding FROM my_embeddings_table WHERE id = 1" ,
You can’t perform that action at this time.
0 commit comments