Sunday, April 22, 2007

Calendar Dimension

While working on a data mart and reporting system for a project I needed a way of pulling data for specific time periods for reports. This was done by using a calendar dimension, which is a table that specifies time frames primarily for reporting purposes. The dimension can be setup for any level of granularity that one needs. Since my smallest reporting period was a single month I setup a table like:
CREATE TABLE calendar_dim(
calendar_id NUMBER,
year NUMBER,
quarter NUMBER,
month_number NUMBER,
month_name VARCHAR2,
month_abbr VARCHAR2 )

The calendar_dim table is then populated with the calendar data that you need like:
1, 2006, 1, 1, 'January', 'JAN'
2, 2006, 1, 2, 'February', 'FEB'

Each table that contains dated information has a calendar_id column like:

calendar_id NUMBER NOT NULL,
bar NUMBER )

The calendar dimension can then be used to control the time frame that queries are run for. As an example the following query sums the value bar over the first quarter of the year 2006.
FROM foo_bar fb, calendar_dim c
fb.calendar_id = c.calendar_id AND
c.year = 2006 AND
c.quarter = 1

Fortune Cookie Says

You have great physical powers and an iron constitution.

Sunday, April 15, 2007

Implementing Non-Recursive Make

I had to take over the web application piece of a project that I worked on after it became abandonware from the software vendor. I needed a build system for this project and decided to implement it using non-recursive make having previously read Peter Miller's paper. I based mine on the non-recursive make system presented by Emile van Bergen, but I ran into several problems with his approach. These are my notes on how I resolved my problems.

Documentation and Suggested Reading

Length Limit of Macros

The original presentation for implementing non-recursive make had individual macros defined to contain all of the source or object files. However, due to the sheer number of files in the webapp project, almost 2,000 after code generation, the upper bound for the length of a macro was exceeded. To resolve this problem my Makefile defines macros to hold the names of directory targets. Where each directory target is dependent upon the contents of per-directory macros, which contain the source or object files for that directory.

For example the Makefile contains:

CALLENTRY := $(DIR_LIBS)/fbCallEntry.jar
dir := com/fb/callentry
include $(dir)/


The files in the callentry sub directories contain something like:

d := $(dir)
$(d)/ \
$(d)/ \


$(d) : $(CALLENTRY_OBJ_$(d))


Clean Targets

One of the goals was to keep the directory level details in the directory's file. However, this makes it difficult to implement directory level clean targets. The difficulty arises in that you no longer know the directory path after the file has been loaded. The solution to this problem was to encode the directory path into the per-directory clean target, and then extract the directory path by using make's substitution rules.

For example the Makefile contains:



clean :$(CLN_TGT)

realclean : clean $(REAL_CLN_TGT)

distclean : realclean $(DIST_CLEAN_TGT)

The files in the callentry subdirectories contain something like:

CLN_TGT += CLN_$(d)

CLN_$(d) :
rm -f $(subst CLN_,,$@)/*.class

Tuesday, April 3, 2007


The VIM (VI iMproved) editor is available for most platforms and is available as a native Window's GUI application as the program gvim. The VIM editor has many customization features which are controlled by the vimrc configuration file.

The vimrc file may exist in several different locations and different names depending on your platform and installation. You can access vim's online help for additional information with the command :h vimrc. The default vimrc file does some nice things like setting up syntax highlighting so it is recommended that you either modify the default file or copy it for a user specific customizations. These are the settings that I use.

  • ai or autoindent This option automatically indents to the level of the previous line.
  • et or expandtab Insert an appropriate number of spaces instead of tabs.
  • sw or shiftwidth The number of spaces to use for each step of auto indent. Set this option to 4.
  • ts or tabstop The number of spaces a tab character counts for. Set this option to 4.
  • sts or softabstop The number of spaces a tab counts for while editing. Set this option to 4.
  • fdm or foldmethod This option enables code folding in the editor. I set this option to indent.

I set the last line of my vimrc file to:
set ai et sw=4 ts=4 sts=4 fdm=indent

Splitting Windows
  • :sp to split the current window into two views.
  • C-w C-w jumps between the windows.
  • C-w+ or C-w- to increase or decrease the view size.
  • C-wc or :q will close the selected view.

Using Tags
To enable tags do :set tag=.
C-] or C-W] follows tag for item under cursor (existing or split window).
C-T returns to your previous spot.
Searching tags :tag / or :tag for completion
:ts will list multiple matches.

Code Folding
The indent fold method works very well for source code if one uses good and consistent indentation. In this case vim will fold the code based upon the level of indentation. For example:

public void preInit(URL url) {
+--- 46 lines: or the default if no config files was specified.------- } // end preInit

public void init()
+--- 60 lines: preInit(getCodeBase());-------------------------------- } // end init

If one wants to use folding but not for source code then the fold method can be set to marker (fdm=marker). A marker will define a folding level for a hierarchy of
folds. A marker is the string { { { # where the # is a numeral defining the fold level. For example:

VIM {{{1
* To insert tabs when in expandtab (et) mode use C-V

windows {{{2 * :[#]sp to split the current window into two views

From command mode the following basic commands can be used to control the folding.
  • zR Open all folds
  • zo Open one fold under the cursor.
  • zO Open all folds under the cursor recursively.
  • zc Close one fold under the cursor.
  • zC Close all folds under the cursor recursively.

Misc Notes
  • To insert tabs when in expandtab (et) mode use {{C-V}}