Wednesday, November 18, 2009
Hanging out at PDC 09
Saturday, May 16, 2009
"Reflection" in M
The M catalog is simply a structured representation of an M program, or what we call the M semantic graph. The schema for the catalog is written in M, and the compiler can generate instances of your M program into that schema. Then it just shows up in the database using mx.exe.
Right now, the way to create an image with the M catalog schema is to run m.exe with the 'catalog definition' parameter, or 'catdef' for short.
m.exe -catdef -out:catalog.mx
This creates an image that contains extent declarations for things like Modules, Types, Extents, and Computed Values. The catalog also has various helper computed values for querying the catalog. For example, you can ask if a particular computed value is installed (IsComputedValueInstalled). Or, you can ask if a type is an intrinsic, collection or entity type (IsIntrinsicType, IsCollectionType, IsEntityType). Or, one of my favorite, you can ask for all of the references to an extent ('ReferencesToExtent').
For now, we don't automatically generate instances for a given M program. You have to explicitly ask for it, and you have to reference the catalog definition generated above. We hope to fix all of that in the next milestone and turn it on by default. Here's a simple example for how to create catalog instances for your M:
m.exe myM.m -catalog /r:catalog.mx
When you run mx with myM.mx and catalog.mx, the M catalog will show up in the database. After you load, take a look at the database. In particular, one super cool thing is that the catalog also maintains the relationship between the SQL created from the M and their corresponding M declarations. For example, take a look at Tables, Functions, and Views in the Language.Catalog.SQL namespace.
That's a brief intro to the M catalog. There will be lots of scenarios coming where we use the catalog to query, analyze and understand M.
What if you want to access the catalog from your M program? That's easy enough because the catalog is written in M. So, you can reference and query the extents directly, or call one of the computed values.
The coolest reason to do this is to add additional data to your M program. This is what some people call metadata - although I'm not very fond of that term (it's all just data). Let's start with an example.
Let's start with one of our classic Oslo scenario models, the WIX model. Let's suppose that I am building a super-duper add-in to WIX that will deploy M to a database. The problem is that the WIX model does not include database deployment information. I could update the WIX model to include this, but that's not a great extensibility story for our developers. Instead, I will build my own little model for my specialization, I will reference M content in the catalog, and I will use about to write instances that reference specific values in the catalog.
Here's a simple version of my model. It describes additional information that I want to associate with a module in M:
module MDeployer
{
import Language.Catalog;
DatabaseConfigurations : ({
Id : Integer32 => AutoNumber;
DatabaseName : Text;
ServerName : Text;
Module : Modules;
} where identity Id, value.Module in Modules)*;
}
Now, I want to write a deployment package the says that a particular M module is deployed to a particular server and database. Here's an example, except what do I write to specify the module name?
module DeploymentPackage
{
import MDeployer;
import MyModel;
MDeployer::DatabaseConfigurations
{
{ DatabaseName => "Testdatabase", ServerName => "TestServer", Module => ... }
}
}
You could write a query, for example, 'Module => (Modules where value.Name == "MyModel")'. That's not always easy to remember. What's worse is that it is not strongly typed - what if I misspell "MyModel". I wouldn't find out about that until loading into the database. What I really want is a compile-time check that I have referenced the right M declaration.
'about' is the magic to make this easy. 'about' is a function that does what the query does, but it's strongly typed and uses the actual identifiers of the M declaration that you want to reference. Here it is:
module DeploymentPackage
{
import MDeployer;
import MyModel;
MDeployer::Databases
{
{
DatabaseName => "Testdatabase",
ServerName => "TestServer",
Module => about(MyModel)
}
}
}
In summary, about allows you to add additional data to your M that is about your M. It references that content, and when loaded to the database, references your M program that is represented in the M catalog.
Thursday, May 14, 2009
New stuff coming
Sunday, May 3, 2009
DSLCon was awesome
Sunday, January 18, 2009
M Data Transformation Part 1
Sunday, January 11, 2009
Metadata or data
Friday, January 2, 2009
M == Semantic Model + DSL + values
Sunday, December 28, 2008
Foundational work on DSLs
Wednesday, November 12, 2008
DSL for Banking - interactive DSLs
Saturday, November 8, 2008
Oslo - is that all it is?
In the comments, there were lots of follow-up questions about the realness and substance of Oslo, and the target customers of the language. Here's some reflections from one Oslo guy...
What we shipped in our first CTP is very much an early alpha of our bits. And, it represents the lowest level of the platform without many of the services, libraries, and bells-whistles that you'd want as a developer. It's as if we shipped the .Net runtime and C# but without any libraries or tools. So, that may be some cause of confusion.
Why did we do this? We wanted to get out the core of the platform as soon as possible so we could start having real discussions with customers and partners. We also want the developer community to embrace modeling as a key principle in the future for how we build applications.
Ultimately, our goal is to enable declarative, model-driven programming. If I look around, I see people doing this today in the form of XML schemas and dialects, various textual reps, and frameworks that encode a domain. We went down that path as well, using visual designers and XML. But at some point the pain was too much :) We evolved our approach into Oslo by trying a more holistic solution. We wanted an easy-to-use language to write down declarations. We wanted a place to store those declarations, and then query, and even compose that data (i.e., join) into "instructions" that runtimes could execute to produce interesting behavior. And then, the idea of making it very easy to create a textual DSL over the model/declarations seemed like a natural step forward to enable app development in an elegant way. It just all fit together for us - and we wanted to share as soon as we could.
Let me also comment about our target customers. We are all developers on our team, and we care deeply about developer tools and productivity. We do not really talk much about making business users programmers. I have to say that personally, I think having a DSL may make it easier to have interesting conversations with business users about the solutions that we build for them. But I don't think that makes them programmers. It just makes it easy to write things down and share/design it with them.
...end of reflecting for now.
Thursday, November 6, 2008
API for MGraph
In M we talk about 3 pieces of technology: MGraph is the data model, MSchema is the type system, and MGrammar is the transformation engine.
MGraph is at the core of all of these. MGraph is a labeled directed graph as defined in the System.Dataflow assembly. Interesting enough, rather than force you to implement a class or interface, we designed MGraph to follow a visitor pattern, like a simplified XML navigator. So, you keep or build whatever data structures you have, and then implement IGraphBuilder to expose those values as an MGraph.
Here is IGraphBuilder:
public interface IGraphBuilder
{
IEqualityComparer<object> NodeComparer { get; }
object DefineNode(object label);
void DefineSuccessors(object protoNode, IEnumerable<object> successors);
object GetLabel(object node);
IEnumerable<object> GetSuccessors(object node);
bool IsNode(object value);
}
I'm only going to talk about the navigation part of IGraphBuilder, not the construction protocol.
A node in the graph is identified by your implementation of GraphBuilder by calling IsNode. If this returns true, then the GetLabel and GetSuccessors methods must accept the same object and produce the label and successors, respectively. The Label is optional.
I recently experimented with building an MGraph over an existing SQL database. I defined a SQLGraphBuilder to take a connection and the name of a SQL object, i.e., table or view.
The SQLGraphBuilder queries the database using that name. I constructs a node for the SQL object with the label being the name of the sql object, and each successor being a row in that object. In turn, each row has a label of the primary key (concatenated if there are multiple) followed by each successor, which is itself a node that has the field name as the label and 1 successor being the value.
Here's the base definition for a node in the graph:
abstract class Node : IEquatable<Node>
{
protected string label;
protected SqlDataReader reader;
public Node(string label, SqlDataReader reader)
{
this.label = label;
this.reader = reader;
}
public string Label { get { return label; } }
public SqlDataReader Reader { get { return reader; } }
public abstract IEnumerable<object> GetSuccessors();
public abstract bool Equals(Node other);
}
So then I have a subtype of this for each kind (SqlObject, Row, and Cell). Here's an example:
class SqlObjectNode : Node
{
public SqlObjectNode(string sqlObjectName, SqlDataReader reader) : base(sqlObjectName, reader)
{
}
public override IEnumerable
{
return new Enumerable(new SqlObjectEnumerator(label, reader));
}
public override bool Equals(Node other)
{
var sqlNode = other as SqlObjectNode;
return sqlNode != null
&& sqlNode.label == this.label;
}
}
This is all quite easy except for the definition of identity via the node comparer. You need to make sure that you think through the identity story so that you can easily identity equivalent graph nodes. In my prototype, I use a concatenation of sqlobject + row id + column name. See the Equals method above as an example.
Now here's the tricky part. Some columns are actually foreign keys. So, I maintain a general foreign key lookup table, and when I hit a column name that is actually a foreign key, in stead of returning a value for that cell, I return a new row representing the values from the related table.
Here's the query to find foreign keys:
const string ForeignKeyQuery =
@"select ssource.name as SourceSchemaName,
tsource.name as SourceTableName,
csource.name as SourceColumnName,
fk.name as ForeignKeyName,
starget.name as TargetSchemaName,
ttarget.name as TargetTableName,
ctarget.name as TargetColumnName
from sys.foreign_keys fk
inner join sys.foreign_key_columns fkc on fk.object_id = fkc.constraint_object_id
inner join sys.tables tsource on fkc.parent_object_id = tsource.object_id
inner join sys.tables ttarget on fkc.referenced_object_id = ttarget.object_id
inner join sys.columns csource on (fkc.parent_column_id = csource.column_id and csource.object_id = tsource.object_id)
inner join sys.columns ctarget on (fkc.referenced_column_id = ctarget.column_id and ctarget.object_id = ttarget.object_id)
inner join sys.schemas ssource on ssource.schema_id = tsource.schema_id
inner join sys.schemas starget on starget.schema_id = ttarget.schema_id
and fk.type = 'F'
order by SourceSchemaName, SourceTableName, ForeignKeyName";
And here's the code to construct the row in the reference table. Notice I'm still working on it :)
StringBuilder query = new StringBuilder(@"select * from " + fk.TargetSqlObjectName + " where ");
int i = 0;
foreach (var targetCol in fk.TargetColumnNames)
{
if (i > 0) { query.Append(" and "); }
query.Append(targetCol + " = @var" + i);
i++;
}
i = 0;
//TODO: fix this hack to support non MARs connections; need to dispose connection + reader
var newConnection = new SqlConnection(connection.ConnectionString);
newConnection.Open();
using (var command = new SqlCommand(query.ToString(), newConnection))
{
foreach (var sourceCol in fk.SourceColumnNames)
{
object foo = reader[sourceCol];
command.Parameters.AddWithValue("@var" + i, foo);
i++;
}
var newReader = command.ExecuteReader();
return new ForeignKeyCellNode(fk.TargetSqlObjectName, rowName, fieldName, newReader);
}
GraphBuilder is fairly straightforward to use. It and Mgraphs are at the base of the modeling platform, so learning it now will only help as we introduce more tools and APIs to consume them.
Sunday, November 2, 2008
Louis
I'm at PDC with a great team, in a nice place, at a great hotel (I love the beds at Westin).
I was watching Louis CK last night (shh - don't tell me wife. She wouldn't like him).
It dawned on me that I have "Louis". My "Louis" is just like the CK version. He is super bright, magnanimous, and serious yet funny in the same way.
He says what he thinks, which I love. If there's one thing that kills a team culture, it is ulterior motives or backdoor communications. If "Louis" has them, you either would not know, or agree that he's right.
That's one reason I love my team. We say what we think. No one is offended. Everyone wants to do the right thing. And we all just get along.
And that's "Louis". He's also able to inspire millions, mentor our team, and make a huge impact/influence on our technologies. Yet he (and us with him) have so much fun doing it.
Saturday, November 1, 2008
Self-funded eval of Oslo's M language
Simple Banking Transaction Model in M
Thursday, October 30, 2008
wonder twin powers activate
I'm a superhero fan. Not really into reading the comics, but definitely watching the Saturday morning cartoons :)
I keep gloating over my team. They are awesome. Well we have a couple of folks that I'll call the Wonder Twins, aka, Zan and Jayna (btw - I did not knew their name before today). Individually, each is an awesome person with great talents. Put them together, and BAM, watch out. They have an amazing multiplier greater than 1+1. I enjoy watching them work. I am often jealous.
Having wonder twins is wonder-ful. We have a hard problem, wonder twin powers activate. We need some new bits as soon as possible, wonder twin powers activate.
In all seriousness, Zan and Jayna are good friends, and great team members. Yet another reason I love my team!
Tuesday, October 28, 2008
DSL Hell
Everyone remembers DLL hell. You know -- run my app but there's 15 versions/copies of a DLL. So which one do I choose. That was hell.
Guess what? I hate to tell you, but we are in DSL hell. There's XML dialects all over the place. Those are DSLs (for Mrs. Pinky, that's domain specific languages). And so we have lots of developers having to learn different XML dialects just to work with different runtimes.
And, APIs themselves are really just DSLs. You have to know which objects to instantiate, which methods to call, and in what order.
So - we're in DSL hell. And it's an ugly hell. Who likes writing code in XML? (besides Don Box)
Oslo, and M, are about to change the game. We want developers to build and use natural, textual languages. Imagine users configuring and running applications by writing simple text in a simple language targeted at their domain. Imagine writing a WCF service in 10s lines of code instead of 100s lines of C# + 20 lines of config + ... Imagine a standard language for business processes, such as Purchase Order Processing. Imagine imagine imagine...
One more thing. As a developer, I am pretty sure you will have more fun writing a DSL with Oslo than most programming you do today. I haven't had this much fun in years!
So this is Oslo. Check it out: http://msdn.microsoft.com/oslo