Skip to content

fix(dynamodb): map NUMBER columns and order charts by metric expressions - #44711

Merged
rusackas merged 1 commit into
apache:masterfrom
aminghadersohi:fix-dynamodb-number-orderby
Sep 29, 2026
Merged

rusackas merged 1 commit into
apache:masterfrom
aminghadersohi:fix-dynamodb-number-orderby

Conversation

@aminghadersohi

Copy link
Copy Markdown
Contributor

SUMMARY

Fixes two defects in DynamoDBEngineSpec. Both block charts on a DynamoDB virtual dataset.

  1. NUMBER has no generic type. PyDynamoDB describes DynamoDB numbers with the type code NUMBER (pydynamodb.sql.common.DataTypes.NUMBER). No default column type mapping matches it, so get_column_spec("NUMBER") returns None. A numeric column in a dataset therefore gets no type_generic. This now maps to Numeric / GenericDataType.NUMERIC.
  2. Sorted charts fail. The PyDynamoDB dialect omits top-level column aliases, because PartiQL has none. A chart query therefore compiles as SELECT label, SUM(amount), COUNT(*) FROM (...) AS virtual_table GROUP BY label ORDER BY total DESC: the AS total label is dropped, but the ORDER BY still references it. This fails with no such column: total (the superset connector evaluates it in SQLite). With allows_alias_in_orderby = False, Superset orders by the expression instead: ORDER BY SUM(amount) DESC.

Related: passren/PyDynamoDB#86 types cursor.description from the returned values. With it, a virtual dataset over SELECT id, amount, ts, label gets NUMBER and DATETIME columns. With the mapping in this PR, those columns become NUMERIC and TEMPORAL.

TESTING INSTRUCTIONS

  • pytest tests/unit_tests/db_engine_specs/test_dynamodb.py: 10 passed. On master, 3 of the new tests fail.
  • End to end against DynamoDB Local 3.3.1 with PyDynamoDB 0.8.0 (connector=superset). The type fix from Type cursor.description columns from the returned values passren/PyDynamoDB#86 was applied, and the requests went through the REST API. The flow was: SQL Lab SELECT, then a virtual dataset (id/amount NUMERIC, ts TEMPORAL with is_dttm), then a saved table chart with SUM(amount) and COUNT(*) by label, ordered by the SUM metric, then a P1D time-grain query.
    • Before this change, the chart step failed with no such column: total.
    • After it, every step passed.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

PyDynamoDB describes DynamoDB numbers as NUMBER, which no column type
mapping matched, so numeric columns had no generic type. Its dialect also
omits top-level column aliases (PartiQL has none), so an ORDER BY on a
metric label (e.g. ORDER BY total) referenced a column that did not exist
and sorted charts failed. Map NUMBER to Numeric and order by the
expression (allows_alias_in_orderby = False).
@bito-code-review

bito-code-review Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #449f26

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 99a8794..99a8794
    • superset/db_engine_specs/dynamodb.py
    • tests/unit_tests/db_engine_specs/test_dynamodb.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@codecov

codecov Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.12%. Comparing base (1a65f0e) to head (99a8794).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #44711      +/-   ##
==========================================
- Coverage   81.12%   81.12%   -0.01%     
==========================================
  Files        2956     2956              
  Lines      178436   178440       +4     
  Branches    41341    41341              
==========================================
+ Hits       144764   144766       +2     
- Misses      30967    30969       +2     
  Partials     2705     2705              
Flag Coverage Δ
hive 36.78% <100.00%> (+<0.01%) ⬆️
mysql 55.97% <100.00%> (+<0.01%) ⬆️
postgres 55.97% <100.00%> (+<0.01%) ⬆️
presto 38.68% <100.00%> (+<0.01%) ⬆️
python 85.41% <100.00%> (-0.01%) ⬇️
sqlite 55.69% <100.00%> (+<0.01%) ⬆️
unit 77.70% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Both changes are narrowly targeted and use real, existing hooks correctly, allows_alias_in_orderby is an established flag and column_type_mappings is empty on the base class so nothing's lost by not extending it. Good test coverage on the type mapping. Approving.

@rusackas
rusackas merged commit 3e9bd8b into apache:master Sep 29, 2026
99 checks passed

@EnxDev EnxDev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Late to this one since it's merged, but I read it through and both fixes hold up. Dropped SELECT aliases are fine too, because query() renames the df columns positionally from labels_expected.

Left two follow-up notes inline: the series-limit join still depends on inner aliases, and the ORDER BY test only checks the flag.

# The PyDynamoDB dialect omits top-level column aliases (PartiQL has none),
# so an ORDER BY on a SELECT alias (e.g. a metric label) names a column that
# does not exist. Order by the expression instead.
allows_alias_in_orderby = False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the main ORDER BY, but the series-limit subquery in helpers.py (around line 5596) still selects label__ / mme_inner__ aliases and joins on label = label__. The dialect strips those aliases too, so a timeseries chart with a dimension and a series limit should still fail with no such column.

Might be misreading the connector, but would allows_joins = False help here? It would route that case through the prequery path, which goes through query() and gets the positional column rename.

DynamoDBEngineSpec as spec, # noqa: N813
)

assert spec.allows_alias_in_orderby is False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, take it or leave it. This asserts the flag we just set, so it can't catch a regression in how the ORDER BY actually gets compiled.

A test that builds a query on a DynamoDB-backed table with a labeled metric and checks the SQL has ORDER BY SUM(amount) DESC would guard the actual bug from the description.

villebro pushed a commit that referenced this pull request Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants