Because Malloy writes SQL expressions, when queries are actually executed, all data will be in types understood by the SQL engine which is running the query.
Malloy does have a set of data types and there is a mapping between the types of the SQL engine and the Malloy datatypes, mostly this mapping is invisible.
An engine will have a large variety of storage formats for numeric data. Malloy doesn't distinguish between these, and simply folds them all into one type,
Although Malloy can use columns of any numberic type, there is no way to write a pure Malloy query to generate columns in a specific engine type.
Malloy has a fairly basic syntax for numeric literals
Strings in Malloy are wrapped in either single quotes (
'), double quotes (
") or what we call the triple quote (
A triple quote
string can extend over more than one line, as in
dimension: my_poem is """ I wrote some new code in Malloy and experienced boundless joy. It worked right away, so I just have to say 'This language is more than a toy.' """
Single and double quoted strings must be written on one line. They can contain a number of special
characters through the
\'- Single quote
\"- Double quote
Malloy has one interesting difference from most SQL engines in how it handles null values.
For expressions which return a
might_be_null > 0:
In SQL, the result is a boolean column where the value could be
In Malloy, the result will only be
This is true for all the comparison operators (
=, etc.) as well as functions which return a boolean (e.g.
timestamp represents an instant in time.
Malloy's approach to timezone related computations relating to timestamp data is explained in the Timezones section.
Timestamp literals are specified in Malloy with the
@ character. Seconds, subsecond resolution, and locale are optional.
In addition, in any of the above, a
T can be used instead of a space between the date and time portion of the timestamp string, as in
date literal, when used in an expression with a timestamp, also functions as a timestamp literal. That is
my_timestamp > @2003is equivalent to
my_timestamp > @2003-01-01 00:00
date represents combination of year, month, and day into a single data item.
Date literals are specified in Malloy with the
@ character. A literal can specify a date, a week, a month, a quarter or a year.
@2001-02-04-WK( the sunday week containing 2001-02-04 )
@2001-02-03-WKwill generate an error because that day does not start a week. The week containing 2001-02-03 that would be
Columns in sources which Malloy does not have a datatype for are considered "unsupported." The following operations are legal on unsupported types
Two expressions of the same unsupported type can be compared
An unsupported type can be compared to
An expression of unsupported type can be cast to a supported type
The following types are not assignable to fields, and are
therefore considered intermediate types, in that they are
primarily used to represent part of a computation that
yields a regular scalar type, often
Literal regular expressions are enclosed in single quotation
' and preceded by either
r'.*'. Both syntaxes are semantically equivalent.
In the future, the literal regular expressions will likely
be simply slash-enclosed, e.g
Values of type
string may be compared against regular
expressions using either the apply operator,
name ? r'c.*' or the like operator,
name ~ r'c.*'.
There are three types of ranges today:
date ranges, and
timestamp ranges. The most basic ranges
are of the form
start to end and represent the inclusive range between
10 to 20 or
@2004-01 to @2005-05.
Ranges may be used in conjunction with the apply operator to test whether a value falls within a given range.
Partials represent a "part of" a comparison.
Specifically, a partial is a comparison missing its
left-hand side, and represents the condition of the
true if a given value were to be
filled in for that missing left-hand side. For example,
> 10 is a partial that represents the condition "is greater
than ten." Likewise,
!= 'CA' is a partial that represents the condition of not being equal to
Alternations are combinations of partials representing
either the logical union ("or") or conjunction ("and") of
their conditions. Alternations are represented using the
union alternation operator
| and the conjunction
= 'CA' | = 'NY' represents the condition of being equal to 'CA' or alternatively being equal to 'NY'. On the other hand,
!= 'CA' & != 'NY' represents the condition of being not equal to 'CA' as well as being not equal to 'NY'.
Scalar values, regular expressions, and ranges may also be used in alternations, in which case the condition is assumed to be that of equality, matching, and inclusion respectively.
'CA' | r'N.*' represents the condition of being equal to 'CA' or starting with 'N', and
10 to 20 | 20 to 30 represents the condition of being either between 10 and 20 or 20 and 30.
Alternations and partials may be used in conjunction with the apply operator to test whether a value meets the given condition.
Today, all Malloy types include the value