Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/bigframes/bigframes/core/sql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def ordering_clause(
# Probably shouldn't have constants in ordering definition, but best to ignore if somehow they end up here.
continue
assert isinstance(ordering_expr, bigframes.core.expression.DerefOp)
part = f"`{ordering_expr.id.sql}` {asc_desc} {null_clause}"
part = f"`{escape_chars(ordering_expr.id.sql)}` {asc_desc} {null_clause}"
parts.append(part)
return f"ORDER BY {' ,'.join(parts)}"

Expand Down
15 changes: 15 additions & 0 deletions packages/bigframes/tests/unit/core/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import bigframes.core.expression as ex
import bigframes.core.identifiers as ids
import bigframes.core.ordering as order
from bigframes.core import sql


def test_ordering_clause_escapes_backtick_in_column_name():
ordering = order.OrderingExpression(ex.DerefOp(ids.ColumnId("col`,(SELECT 1))--")))
result = sql.ordering_clause([ordering])
assert result == "ORDER BY `col\\`,(SELECT 1))--` ASC NULLS LAST"


def test_ordering_clause_leaves_plain_column_name_unchanged():
ordering = order.OrderingExpression(ex.DerefOp(ids.ColumnId("my_col")))
result = sql.ordering_clause([ordering])
assert result == "ORDER BY `my_col` ASC NULLS LAST"


def test_create_vector_search_sql_simple():
result_query = sql.create_vector_search_sql(
sql_string="SELECT embedding FROM my_embeddings_table WHERE id = 1",
Expand Down
Loading