Question

I am trying to apply some business rules (inclusion and exclusion rules) on an Oracle table and update a status column based on the rules. A file will be later extracted from this table based on the value of the status column. Now the business wants to configure the rules using a UI. So the rules will be dynamic.

I am planning to store all possible columns on which users might want to use Business Rules in a staging table. In the rule UI all columns from this staging table will be displayed. Then I am planning to create a stored procedure to fetch rules from Rule table and use with dynamic update statement to update the status column. Would Dynamic SQL be good for this?

Rule Table :

Id, RuleName, RuleDesc, ColumnName, Operator, Value, Connector, ConnectOperator, RulePrecedence

Connector- To connect to rules say

#1 Code=1001
#2 state='FL' 

In the first rule user can put #2 as Connector and ConnectOperator can be "and/or"

Or I can go for C# code, fetching all rows from table into objects and then use LINQ queries to filter rows based on rules and update the table. Maybe use NHibernate as ORM since Oracle is the underlying database. But not sure if the performance would be good with Oracle. The number of rows to be processed can be around 500K

I am also confused, if database will be the best place to store the rules or there are some other means but for sure users want to configure and create the rules and a rule can refer columns which may belong to different tables (that's why i want to store all possible columns in the staging table though I understand it has limitations, if business wants to create rules on a column which is not there in this staging then this architecture will not work)

Any suggestions how I should approach this design?

Was it helpful?

Solution

I went ahead with storing the rules in database table and executing them on run time using stored procedure and dynamic sql. I needed to do some performance tuning on sql queries and now it is working fine. I was able to process 64 MN records within 45 mins which is not bad. I used set based operation (update statement) for rule processing.

OTHER TIPS

There's many ways to tackle this problem, no standard solution. If you google around for 'Rule Engine' and 'ETL' you find many people presenting their solution.

The most flexible solution I found integrates a graphical ETL tool with an existing rules engine. This leverages existing products, it keeps both sides of the process well separated and flexible. And they report good enough performance, even though they feed single rows to the rules engine.

The main advantage of evaluating the rules in C# or Java would be that you can use a standard rules engine. So you get all the syntactic sugar and graphical editing that comes with the rules engine for free. Your business can go wild on the rules side of things and you won't even notice.

I'd advise against using an ORM tool to fetch and update to the data. The information needed to update the status column ought to be present in one and the same row, so there is no need for an ORM tool. A simple dataset ought to do just fine.

As a wild afterthought: Oracle has experimented with Java-in-the-database, so perhaps you can even get a Java rules engine to run in your database?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top