I would like to write a custom mining function, which takes a string, queries the database, and returns an answer based upon those queries. So the basic function is then:
[MiningFunction("Performs Foo")]
public string Foo(string param)
{
// process parameters
// query database
// calculate answer from query results
// return query results
}
And is executed from the client using:
SELECT Foo("X Y Z") FROM FooModel
This arrangement is so that resource-intensive calculations are performed server-side.
My question is: what is the preferrable method for executing the database query from within the custom mining function?
Custom mining functions are not actually designed for this kind of operations. They are intended for predictive features that are related to the mining model and typically this kind of operations do not need external access (such as a database query). I assume that your function's calculation part will use some information from the mining model and apply it to the database query results.
I think you should use a stored procedure. Inside the stored procedure, you should use the server side object model (add a reference to Microsoft.AnalysisServices.AdomdServer). With the server side object model, you can perform the following operations:
- use AdomdCommand to execute calls such as CALL SystemOpenQuery(DataSource, Query), which is the recommended way of querying a relational database from analysis services
- also use AdomdCommand to execute calls such as SELECT .... FROM YourModel PREDICTION JOIN OPENQUERY(DataSource, Query)
This would allow you to get the information from the data base together with scoring for each, scoring computed as a prediction from your model ). Your code could use the results and perform aggregations or more complex computations on the result.
If, in the code of your stored procedure, you need to get extra information from your model, you can traverse the content of the mining model using the object model.
The article at http://www.sqlserverdatamining.com/DMCommunity/TipsNTricks/4264.aspx contains such a stored procedure, which requires both data and model content information, so I think it may be a good example. The data is coming directly from the model, with a drillthrough query. You can replace that query with a CALL SystemOpenQuery or prediction against an OPENQUERY statement.
Hope this helps
|||Yes, this is helpful. I'm looking at the material you referenced to see if it completely answers my question. Unfortunately, I don't seem able to progress pass the logon screen at sqlserverdatamining at the moment, so I can't get the .cs example...|||Do you have an account on sqlserverdatamining.com? Do you have problems logging in with your account? Or creating a new account
No comments:
Post a Comment