There are a few places where Malloy 4.0 will require existing code to change. In the transitional period, both the 4.0 and Pre-4.0 syntax is accepted, and a warning will be generated for Pre-4.0 constructs, to give users guidance in changing their code. Once 4.0 fully releases, these will be errors and not warnings.
This is a list of all the 4.0 compatibility messages, with examples code showing how to transform existing code for Malloy 4.0.
Extend a source with extend
Creating a new source by adding new propertied to an existing source is called extension in Malloy. There have been three different ways to express extension of a source, now only the form source extend { extensions }
is accepted.
Pre-4.0 Malloy | 4.0 Malloy |
---|---|
|
|
Refine a query with +
Creating a new query by adding properties to an existing query is called refinement
in Malloy. There have been three different ways to express refinements, now only the form query + { refinements }
is accepted.
Pre-4.0 Malloy | 4.0 Malloy |
---|---|
|
query: flights -> by_carrier refine + { limit: 5 } |
Sources contain views
The object inside a source which can be used to build a query is now called a view:
, it used to be called a query:
Pre-4.0 Malloy | 4.0 Malloy |
---|---|
|
|
select:
instead of project:
The project:
keyword has been renamed to select:
.
Pre-4.0 Malloy | 4.0 Malloy |
---|---|
query: flights -> { project: * } |
run: flights -> { select: * } |
New syntax for count(*)
and count(distinct)
The SQL syntax for distinct counts count(distinct expression)
is deprecated in favor of count(expression)
.
Pre-4.0 Malloy | 4.0 Malloy |
---|---|
|
|
The SQL syntax for counting the records of a table count(*)
is deprecated in favor of count()
.
Pre-4.0 Malloy | 4.0 Malloy |
---|---|
query: flights -> { aggregate: flight_count is count(*) } |
run: flights -> { aggregate: flight_count is count() } |
{? } deprecated
The old filter shortcut syntax {? condition }
is deprecated. Use the more explicit { where: condition }
syntax instead.
Pre-4.0 Malloy | 4.0 Malloy |
---|---|
flight_count {? distance > 2 } |
flight_count { where: distance > 2} |
flights {? distance > 2 } |
flights extend { where: distance > 2} |
by_carrier {? distance > 2 } |
by_carrier + { where: distance > 2} |
Nesting Malloy in SQL with %{}% is now %{}
Query interpolation in SQL strings should use }
to end the interpolation rather than }%
.
Pre-4.0 Malloy | 4.0 Malloy |
---|---|
|
|
-> no longer begins a named query or view
It used to be necessary to use an arrow (->
) to base a new source or query off of an existing query. This is no longer necessary.
Pre-4.0 Malloy | 4.0 Malloy |
---|---|
query: -> flights_by_carrier -> { project: * } |
run: flights_by_carrier -> { select: * } |
A leading ->
operator no longer signifies the beginning of a query pipeline.
Pre-4.0 Malloy | 4.0 Malloy |
---|---|
query: x is -> { group_by: y} nest: z is -> x + { aggregate: c is count() } |
view: x is { group_by: y} nest: z is x + { aggregate: c is count() } |
SQL and tables are accessed through the connection
When referencing a SQL table, the connection name should now be specified connection_name.table('table_path')
instead of table('connection_name:table_path')
.
Pre-4.0 Malloy | 4.0 Malloy |
---|---|
source: flights is table('duckdb:flights.parquet') |
source: flights is duckdb.table('flights.parquet') |
Prior to Malloy 4.0, SQL blocks were declared using sql: sql_block is ...
and used with from_sql(sql_block) ...
. Now, SQL blocks are created with the connection_name.sql(...)
syntax and can be used as sources directly.
Pre-4.0 Malloy | 4.0 Malloy |
---|---|
|
|
Prior to Malloy 4.0, SQL blocks were declared using sql: sql_block is ...
. Now, SQL blocks are created with the connection_name.sql(...)
syntax.
Pre-4.0 Malloy | 4.0 Malloy |
---|---|
|
|
Queries can be used as a source without from()
Prior to Malloy 4.0, the from()
function was required to convert a query into a source. Now a query can be used directly anywhere where a source is needed.
Pre-4.0 Malloy | 4.0 Malloy |
---|---|
|
|
Extensions to view objects move to an extend: {}
section
When the ability to extend the source of a query operation was first introduced, the extensions were written alongside the query. Now those extensions should be written in an extend:
block inside the query.
On the fly joins in queries should now be specified in an extend:
block.
Pre-4.0 Malloy | 4.0 Malloy |
---|---|
|
|
The declare:
keyword has been deprecated, and should be replaced with dimension:
or measure:
. If the declare:
is used inside a query, it also needs to be put into an extend:
block.
Pre-4.0 Malloy | 4.0 Malloy |
---|---|
|
|
|
|
top:
... by
removed
Previously, you could specify an ordering field in the top:
specification. Now you should use order_by:
explicitly.
Pre-4.0 Malloy | 4.0 Malloy |
---|---|
|
|
Write nameless queries with run:
query:
should now only be used to declare a query with a name. To run a query without naming it, use run:
.
Pre-4.0 Malloy | 4.0 Malloy |
---|---|
query: flights -> by_carrier |
run: flights -> by_carrier |
query: flights_by_carrier is flights -> by_carrier |
Unchanged |