Datasource Statements
Datasource Statements
Datasource statements are used to both define sources of data - the roots of a model - and to define targets for writing data back out.
Syntax
"datasource" IDENTIFIER "(" column_assignment_list ")" grain_clause? (address | query)
Identifier
The named alias of the datasource is used if the datasource is referenced in a persist, validate, or publish statement.
Column Assignment List
The column assignment list contains the binding of physical columns on the datasource to concepts.
A binding can take one of 3 forms:
customers(
# a bare binding represents a mapping from "id" on the table to "id" as a concept
id,
# a colon binding maps "name" on the table to "user_name" as a concept
name: user_name,
# a function binding can reference a prior filed
UPPER(name): upper_name,
# a rawsql binding can reference a sql expression
)
Grain Clause
The grain clause defines unique identifiers for rows in the table. (A primary key, or composite primary key)
Address/Query
A datasource can either come from a table
address database.my_fun_table
or from a query
query '''
select fun_data
'''
Tips
Query sources are very useful for experimentation, injecting in values, and bespoke database SQL syntax
Example
import std.money;
import nation as nation;
key id int;
property id.name string;
property id.address string;
property id.phone string;
property id.account_balance float::usd;
property id.market_segment string; # Capitalized; one of BUILDING | FURNITURE | MACHINERY | AUTOMOBILE | HOUSEHOLD
property id.comment string;
datasource customers (
c_custkey:id,
c_name:name,
c_address:address,
c_nationkey:nation.id,
c_phone:phone,
c_acctbal:account_balance,
c_mktsegment:market_segment,
c_comment:comment
)
grain (id)
address memory.customer;
