Repository navigation
Is a custom SemanticLayer extension the right way to query an Apache Ossie model stored in Apache Polaris? #45891
mfournioux
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
What we are trying to do
We want to describe our metrics once, in Apache Ossie format, store that definition in Apache Polaris, and then build charts and dashboards on it in Superset. The data itself lives in Iceberg tables, queried through a database connection Superset already has.
Our stack:
7.0.0rc1, withSEMANTIC_LAYERSandENABLE_EXTENSIONSon1.8.00.2.0.dev0The extension mechanism itself already works for us: we deployed
betodealmeida/pandas-semantic-layeras a local extension, the connection form renders, and charts against it work. What we are unsure about is the design of an Ossie provider, which is why we are asking before writing code.What we found
Our starting assumption was that something, somewhere, already knew how to turn an Ossie model into a SQL query. We looked, and could not find it. Here is what we checked:
query,sql,compile,resolve,metricsandplanall return404, whilesemantic-modelsreturns401.expression_language.mdstates: "It does not define a query interface… Query interfaces will be defined in separate documents." A reference Ossie → SQL compiler is listed as future work.ossie-converters/polaris/semantic-modelsAPI.SemanticLayerandSemanticViewship as abstract base classes, andget_table()is abstract.So our reading is that generating the SQL is the consuming client's job, which also matches the intent described in apache/polaris#4522: each client reads the same definition, picks its dialect from
expression.dialects[], and produces the query itself.We would like that confirmed, because everything else we plan follows from it.
One distinction we want to state clearly
It is easy to blur two different things, so to be explicit about what we are and are not reusing:
Generating SQL. Superset has
get_sqla_queryinsuperset/models/helpers.py, which builds SQL for Superset's own datasets. It is not used for semantic views.SemanticView.get_query_str()returns the literal string"Not implemented for semantic layers", andsuperset/semantic_layers/mapper.pyhands the request tosemantic_view.get_table(). So Superset generates no SQL on this path, and we are not trying to reuse that code.Executing SQL. Separately,
Database.execute(sql, options)takes a SQL string that the caller already produced and runs it against an existing connection. That is the only piece we want to reuse, so that the extension does not need to ship its own driver or handle authentication.In short: we write the SQL, an existing Superset connection runs it.
What we plan to build
A backend-only Superset extension acting as that consuming client. Nothing in it is specific to a particular engine: the dialect comes from the model, and execution goes through whichever Superset connection is configured.
Step by step:
from_configuration()fetches the model from the Polaris semantic-models API and parses it with theossiePython library, caching it against theentity-versionPolaris returns.get_dimensions()andget_metrics()map Ossie fields and metrics onto Superset's types.get_table()receives aSemanticQuery(metrics, dimensions, filters, order, limit) and builds aSELECTfrom it using SQLGlot, in the dialect the model declares throughexpression.dialects[]. Because Ossie expressions are already SQL fragments, this is mostly assembly: project the dimensions, add the aggregates, and derive the joins by walkingrelationships[].Database.execute()on an existing Superset connection, and the DataFrame is converted to apa.Table.SemanticResult.requests, so it can be inspected when a chart looks wrong.Questions
master,from_configurationtakescache_token,contextandcredentials, and there is aSemanticExecutionContext. None of these exist in7.0.0rc1, where the signature is simplyfrom_configuration(cls, configuration). The guide atdocs/developer_docs/extensions/extension-points/semantic-layers.mddocuments themastersignature and is not present in the7.0.0rc1tag, so following it on 7.0 produces an extension that fails to load. Is there guidance for extension authors on 7.0?Database.execute()the intended way for a provider to run the SQL it generated, or is a provider expected to open its own connection to the engine?pandas-semantic-layeris the only working example we found for rc1;example_provider.pyandtests/e2e_extensions/semantic_stub/exist only onmaster.Contribution
If the approach is confirmed, we will open a PR.
One thing we noticed while scoping the work: the Ossie → SQL part is not specific to Polaris or to us. Any Superset deployment consuming an Ossie model would need the same logic. If that seems useful to others, we are happy to shape it as something reusable rather than keeping it inside our own extension, and to contribute it wherever maintainers think it belongs. If that is out of scope, we will simply keep it internal and ship the provider on its own.
Related: SIP-182, apache/polaris#4522
All reactions